change tests for phpunit 9 support, breaking support with phpunit 5.6

This commit is contained in:
El RIDO 2020-10-11 10:31:24 +02:00
parent 37a620df95
commit 17c3cb35c0
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
13 changed files with 128 additions and 186 deletions

View file

@ -29,7 +29,7 @@
"yzalis/identicon" : "^2.0.0" "yzalis/identicon" : "^2.0.0"
}, },
"require-dev" : { "require-dev" : {
"phpunit/phpunit" : "^5 || ^9" "phpunit/phpunit" : "^9"
}, },
"autoload" : { "autoload" : {
"psr-4" : { "psr-4" : {

44
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "c5e5c4d3d99ae93c94cc75e225aa50f5", "content-hash": "f8f346748370d0efd672270571c4aa74",
"packages": [ "packages": [
{ {
"name": "paragonie/random_compat", "name": "paragonie/random_compat",
@ -897,16 +897,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "9.4.0", "version": "9.4.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "ef533467a7974c4b6c354f3eff42a115910bd4e5" "reference": "1f09a12726593737e8a228ebb1c8647305d07c41"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ef533467a7974c4b6c354f3eff42a115910bd4e5", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1f09a12726593737e8a228ebb1c8647305d07c41",
"reference": "ef533467a7974c4b6c354f3eff42a115910bd4e5", "reference": "1f09a12726593737e8a228ebb1c8647305d07c41",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -921,23 +921,23 @@
"phar-io/manifest": "^2.0.1", "phar-io/manifest": "^2.0.1",
"phar-io/version": "^3.0.2", "phar-io/version": "^3.0.2",
"php": ">=7.3", "php": ">=7.3",
"phpspec/prophecy": "^1.11.1", "phpspec/prophecy": "^1.12.1",
"phpunit/php-code-coverage": "^9.2", "phpunit/php-code-coverage": "^9.2",
"phpunit/php-file-iterator": "^3.0.4", "phpunit/php-file-iterator": "^3.0.5",
"phpunit/php-invoker": "^3.1", "phpunit/php-invoker": "^3.1.1",
"phpunit/php-text-template": "^2.0.2", "phpunit/php-text-template": "^2.0.3",
"phpunit/php-timer": "^5.0.1", "phpunit/php-timer": "^5.0.2",
"sebastian/cli-parser": "^1.0", "sebastian/cli-parser": "^1.0.1",
"sebastian/code-unit": "^1.0.5", "sebastian/code-unit": "^1.0.6",
"sebastian/comparator": "^4.0.3", "sebastian/comparator": "^4.0.5",
"sebastian/diff": "^4.0.2", "sebastian/diff": "^4.0.3",
"sebastian/environment": "^5.1.2", "sebastian/environment": "^5.1.3",
"sebastian/exporter": "^4.0.2", "sebastian/exporter": "^4.0.3",
"sebastian/global-state": "^5.0", "sebastian/global-state": "^5.0.1",
"sebastian/object-enumerator": "^4.0.2", "sebastian/object-enumerator": "^4.0.3",
"sebastian/resource-operations": "^3.0.2", "sebastian/resource-operations": "^3.0.3",
"sebastian/type": "^2.2.1", "sebastian/type": "^2.3",
"sebastian/version": "^3.0.1" "sebastian/version": "^3.0.2"
}, },
"require-dev": { "require-dev": {
"ext-pdo": "*", "ext-pdo": "*",
@ -992,7 +992,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2020-10-02T03:54:37+00:00" "time": "2020-10-11T07:41:19+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",

View file

@ -58,13 +58,11 @@ class ConfigurationTest extends TestCase
$this->assertEquals($this->_options, $conf->get(), 'returns correct defaults on missing file'); $this->assertEquals($this->_options, $conf->get(), 'returns correct defaults on missing file');
} }
/**
* @expectedException Exception
* @expectedExceptionCode 2
*/
public function testHandleBlankConfigFile() public function testHandleBlankConfigFile()
{ {
file_put_contents(CONF, ''); file_put_contents(CONF, '');
$this->expectException(Exception::class);
$this->expectExceptionCode(2);
new Configuration; new Configuration;
} }
@ -75,25 +73,21 @@ class ConfigurationTest extends TestCase
$this->assertEquals($this->_options, $conf->get(), 'returns correct defaults on empty file'); $this->assertEquals($this->_options, $conf->get(), 'returns correct defaults on empty file');
} }
/**
* @expectedException Exception
* @expectedExceptionCode 3
*/
public function testHandleInvalidSection() public function testHandleInvalidSection()
{ {
file_put_contents(CONF, $this->_minimalConfig); file_put_contents(CONF, $this->_minimalConfig);
$conf = new Configuration; $conf = new Configuration;
$this->expectException(Exception::class);
$this->expectExceptionCode(3);
$conf->getKey('foo', 'bar'); $conf->getKey('foo', 'bar');
} }
/**
* @expectedException Exception
* @expectedExceptionCode 4
*/
public function testHandleInvalidKey() public function testHandleInvalidKey()
{ {
file_put_contents(CONF, $this->_minimalConfig); file_put_contents(CONF, $this->_minimalConfig);
$conf = new Configuration; $conf = new Configuration;
$this->expectException(Exception::class);
$this->expectExceptionCode(4);
$conf->getKey('foo'); $conf->getKey('foo');
} }
@ -160,8 +154,8 @@ class ConfigurationTest extends TestCase
$conf = new Configuration; $conf = new Configuration;
$this->assertFileExists(CONF, 'old configuration file gets converted'); $this->assertFileExists(CONF, 'old configuration file gets converted');
$this->assertFileNotExists(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', 'old configuration file gets removed'); $this->assertFileDoesNotExist(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', 'old configuration file gets removed');
$this->assertFileNotExists(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini.sample', 'old configuration sample file gets removed'); $this->assertFileDoesNotExist(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini.sample', 'old configuration sample file gets removed');
$this->assertTrue( $this->assertTrue(
$conf->getKey('opendiscussion') && $conf->getKey('opendiscussion') &&
$conf->getKey('fileupload') && $conf->getKey('fileupload') &&
@ -180,10 +174,10 @@ class ConfigurationTest extends TestCase
} }
rename(CONF_SAMPLE, $iniSample); rename(CONF_SAMPLE, $iniSample);
new Configuration; new Configuration;
$this->assertFileNotExists($iniSample, 'old sample file gets removed'); $this->assertFileDoesNotExist($iniSample, 'old sample file gets removed');
$this->assertFileExists(CONF_SAMPLE, 'new sample file gets created'); $this->assertFileExists(CONF_SAMPLE, 'new sample file gets created');
$this->assertFileExists(CONF, 'old configuration file gets converted'); $this->assertFileExists(CONF, 'old configuration file gets converted');
$this->assertFileNotExists(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', 'old configuration file gets removed'); $this->assertFileDoesNotExist(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', 'old configuration file gets removed');
} }
public function testConfigPath() public function testConfigPath()
@ -214,15 +208,15 @@ class ConfigurationTest extends TestCase
$options = $this->_options; $options = $this->_options;
$options['main']['name'] = 'OtherBin'; $options['main']['name'] = 'OtherBin';
Helper::createIniFile($configFile, $options); Helper::createIniFile($configFile, $options);
$this->assertFileNotExists(CONF, 'configuration in the default location is non existing'); $this->assertFileDoesNotExist(CONF, 'configuration in the default location is non existing');
// test // test
putenv('CONFIG_PATH=' . $this->_path); putenv('CONFIG_PATH=' . $this->_path);
$conf = new Configuration; $conf = new Configuration;
$this->assertEquals('OtherBin', $conf->getKey('name'), 'changing config path is supported for ini files as well'); $this->assertEquals('OtherBin', $conf->getKey('name'), 'changing config path is supported for ini files as well');
$this->assertFileExists($configMigrated, 'old configuration file gets converted'); $this->assertFileExists($configMigrated, 'old configuration file gets converted');
$this->assertFileNotExists($configFile, 'old configuration file gets removed'); $this->assertFileDoesNotExist($configFile, 'old configuration file gets removed');
$this->assertFileNotExists(CONF, 'configuration is not created in the default location'); $this->assertFileDoesNotExist(CONF, 'configuration is not created in the default location');
// cleanup environment // cleanup environment
if (is_file($configFile)) { if (is_file($configFile)) {

View file

@ -565,7 +565,7 @@ EOT;
case 'Delete': case 'Delete':
$code .= <<<'EOT' $code .= <<<'EOT'
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted[^<]*</div>#s', '#<div[^>]*id="status"[^>]*>.*Paste was properly deleted[^<]*</div>#s',
$content, $content,
'outputs deleted status correctly' 'outputs deleted status correctly'

View file

@ -54,12 +54,12 @@ class ControllerTest extends TestCase
new Controller; new Controller;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertContains( $this->assertStringContainsString(
'<title>PrivateBin</title>', '<title>PrivateBin</title>',
$content, $content,
'outputs title correctly' 'outputs title correctly'
); );
$this->assertNotContains( $this->assertStringNotContainsString(
'id="shortenbutton"', 'id="shortenbutton"',
$content, $content,
'doesn\'t output shortener button' 'doesn\'t output shortener button'
@ -79,7 +79,7 @@ class ControllerTest extends TestCase
new Controller; new Controller;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertContains( $this->assertStringContainsString(
'<title>PrivateBin</title>', '<title>PrivateBin</title>',
$content, $content,
'outputs title correctly' 'outputs title correctly'
@ -100,7 +100,7 @@ class ControllerTest extends TestCase
new Controller; new Controller;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertContains( $this->assertStringContainsString(
'<title>PrivateBin</title>', '<title>PrivateBin</title>',
$content, $content,
'outputs title correctly' 'outputs title correctly'
@ -121,7 +121,7 @@ class ControllerTest extends TestCase
new Controller; new Controller;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#id="shortenbutton"[^>]*data-shortener="' . preg_quote($shortener) . '"#', '#id="shortenbutton"[^>]*data-shortener="' . preg_quote($shortener) . '"#',
$content, $content,
'outputs configured shortener URL correctly' 'outputs configured shortener URL correctly'
@ -150,13 +150,11 @@ class ControllerTest extends TestCase
$this->assertFileExists($htaccess, 'htaccess recreated'); $this->assertFileExists($htaccess, 'htaccess recreated');
} }
/**
* @expectedException Exception
* @expectedExceptionCode 2
*/
public function testConf() public function testConf()
{ {
file_put_contents(CONF, ''); file_put_contents(CONF, '');
$this->expectException(Exception::class);
$this->expectExceptionCode(2);
new Controller; new Controller;
} }
@ -452,8 +450,6 @@ class ControllerTest extends TestCase
* silently removed, check that this case is handled * silently removed, check that this case is handled
* *
* @runInSeparateProcess * @runInSeparateProcess
* @expectedException Exception
* @expectedExceptionCode 90
*/ */
public function testCreateBrokenUpload() public function testCreateBrokenUpload()
{ {
@ -465,6 +461,8 @@ class ControllerTest extends TestCase
$_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1'; $_SERVER['REMOTE_ADDR'] = '::1';
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste does not exists before posting data'); $this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste does not exists before posting data');
$this->expectException(Exception::class);
$this->expectExceptionCode(90);
new Controller; new Controller;
$this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste exists after posting data'); $this->assertFalse($this->_data->exists(Helper::getPasteId()), 'paste exists after posting data');
} }
@ -799,7 +797,7 @@ class ControllerTest extends TestCase
new Controller; new Controller;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted\.#s', '#<div[^>]*id="status"[^>]*>.*Paste was properly deleted\.#s',
$content, $content,
'outputs deleted status correctly' 'outputs deleted status correctly'
@ -819,7 +817,7 @@ class ControllerTest extends TestCase
new Controller; new Controller;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<div[^>]*id="errormessage"[^>]*>.*Invalid paste ID\.#s', '#<div[^>]*id="errormessage"[^>]*>.*Invalid paste ID\.#s',
$content, $content,
'outputs delete error correctly' 'outputs delete error correctly'
@ -838,7 +836,7 @@ class ControllerTest extends TestCase
new Controller; new Controller;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist, has expired or has been deleted\.#s', '#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist, has expired or has been deleted\.#s',
$content, $content,
'outputs delete error correctly' 'outputs delete error correctly'
@ -857,7 +855,7 @@ class ControllerTest extends TestCase
new Controller; new Controller;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<div[^>]*id="errormessage"[^>]*>.*Wrong deletion token\. Paste was not deleted\.#s', '#<div[^>]*id="errormessage"[^>]*>.*Wrong deletion token\. Paste was not deleted\.#s',
$content, $content,
'outputs delete error correctly' 'outputs delete error correctly'
@ -905,7 +903,7 @@ class ControllerTest extends TestCase
new Controller; new Controller;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist, has expired or has been deleted\.#s', '#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist, has expired or has been deleted\.#s',
$content, $content,
'outputs error correctly' 'outputs error correctly'
@ -928,7 +926,7 @@ class ControllerTest extends TestCase
new Controller; new Controller;
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<div[^>]*id="status"[^>]*>.*Paste was properly deleted\.#s', '#<div[^>]*id="status"[^>]*>.*Paste was properly deleted\.#s',
$content, $content,
'outputs deleted status correctly' 'outputs deleted status correctly'

View file

@ -122,124 +122,102 @@ class DatabaseTest extends TestCase
} }
} }
/**
* @expectedException PDOException
*/
public function testGetIbmInstance() public function testGetIbmInstance()
{ {
$this->expectException(PDOException::class);
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'ibm:', 'usr' => null, 'pwd' => null, 'dsn' => 'ibm:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
/**
* @expectedException PDOException
*/
public function testGetInformixInstance() public function testGetInformixInstance()
{ {
$this->expectException(PDOException::class);
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'informix:', 'usr' => null, 'pwd' => null, 'dsn' => 'informix:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
/**
* @expectedException PDOException
*/
public function testGetMssqlInstance() public function testGetMssqlInstance()
{ {
$this->expectException(PDOException::class);
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'mssql:', 'usr' => null, 'pwd' => null, 'dsn' => 'mssql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
/**
* @expectedException PDOException
*/
public function testGetMysqlInstance() public function testGetMysqlInstance()
{ {
$this->expectException(PDOException::class);
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'mysql:', 'usr' => null, 'pwd' => null, 'dsn' => 'mysql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
/**
* @expectedException PDOException
*/
public function testGetOciInstance() public function testGetOciInstance()
{ {
$this->expectException(PDOException::class);
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'oci:', 'usr' => null, 'pwd' => null, 'dsn' => 'oci:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
/**
* @expectedException PDOException
*/
public function testGetPgsqlInstance() public function testGetPgsqlInstance()
{ {
$this->expectException(PDOException::class);
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'pgsql:', 'usr' => null, 'pwd' => null, 'dsn' => 'pgsql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION),
)); ));
} }
/**
* @expectedException Exception
* @expectedExceptionCode 5
*/
public function testGetFooInstance() public function testGetFooInstance()
{ {
$this->expectException(Exception::class);
$this->expectExceptionCode(5);
Database::getInstance(array( Database::getInstance(array(
'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null, 'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null,
)); ));
} }
/**
* @expectedException Exception
* @expectedExceptionCode 6
*/
public function testMissingDsn() public function testMissingDsn()
{ {
$options = $this->_options; $options = $this->_options;
unset($options['dsn']); unset($options['dsn']);
$this->expectException(Exception::class);
$this->expectExceptionCode(6);
Database::getInstance($options); Database::getInstance($options);
} }
/**
* @expectedException Exception
* @expectedExceptionCode 6
*/
public function testMissingUsr() public function testMissingUsr()
{ {
$options = $this->_options; $options = $this->_options;
unset($options['usr']); unset($options['usr']);
$this->expectException(Exception::class);
$this->expectExceptionCode(6);
Database::getInstance($options); Database::getInstance($options);
} }
/**
* @expectedException Exception
* @expectedExceptionCode 6
*/
public function testMissingPwd() public function testMissingPwd()
{ {
$options = $this->_options; $options = $this->_options;
unset($options['pwd']); unset($options['pwd']);
$this->expectException(Exception::class);
$this->expectExceptionCode(6);
Database::getInstance($options); Database::getInstance($options);
} }
/**
* @expectedException Exception
* @expectedExceptionCode 6
*/
public function testMissingOpt() public function testMissingOpt()
{ {
$options = $this->_options; $options = $this->_options;
unset($options['opt']); unset($options['opt']);
$this->expectException(Exception::class);
$this->expectExceptionCode(6);
Database::getInstance($options); Database::getInstance($options);
} }

View file

@ -162,13 +162,13 @@ class FilesystemTest extends TestCase
$this->_model->purge(10); $this->_model->purge(10);
foreach ($ids as $dataid => $storagedir) { foreach ($ids as $dataid => $storagedir) {
$this->assertFileExists($storagedir . $dataid . '.php', "paste $dataid exists in new format"); $this->assertFileExists($storagedir . $dataid . '.php', "paste $dataid exists in new format");
$this->assertFileNotExists($storagedir . $dataid, "old format paste $dataid got removed"); $this->assertFileDoesNotExist($storagedir . $dataid, "old format paste $dataid got removed");
$this->assertTrue($this->_model->exists($dataid), "paste $dataid exists"); $this->assertTrue($this->_model->exists($dataid), "paste $dataid exists");
$this->assertEquals($this->_model->read($dataid), $paste, "paste $dataid wasn't modified in the conversion"); $this->assertEquals($this->_model->read($dataid), $paste, "paste $dataid wasn't modified in the conversion");
$storagedir .= $dataid . '.discussion' . DIRECTORY_SEPARATOR; $storagedir .= $dataid . '.discussion' . DIRECTORY_SEPARATOR;
$this->assertFileExists($storagedir . $dataid . '.' . $commentid . '.' . $dataid . '.php', "comment of $dataid exists in new format"); $this->assertFileExists($storagedir . $dataid . '.' . $commentid . '.' . $dataid . '.php', "comment of $dataid exists in new format");
$this->assertFileNotExists($storagedir . $dataid . '.' . $commentid . '.' . $dataid, "old format comment of $dataid got removed"); $this->assertFileDoesNotExist($storagedir . $dataid . '.' . $commentid . '.' . $dataid, "old format comment of $dataid got removed");
$this->assertTrue($this->_model->existsComment($dataid, $dataid, $commentid), "comment in paste $dataid exists"); $this->assertTrue($this->_model->existsComment($dataid, $dataid, $commentid), "comment in paste $dataid exists");
$comment = $comment; $comment = $comment;
$comment['id'] = $commentid; $comment['id'] = $commentid;

View file

@ -13,12 +13,10 @@ class FilterTest extends TestCase
$this->assertEquals('6 months', Filter::formatHumanReadableTime('6months')); $this->assertEquals('6 months', Filter::formatHumanReadableTime('6months'));
} }
/**
* @expectedException Exception
* @expectedExceptionCode 30
*/
public function testFilterFailTimesHumanlyReadable() public function testFilterFailTimesHumanlyReadable()
{ {
$this->expectException(Exception::class);
$this->expectExceptionCode(30);
Filter::formatHumanReadableTime('five_minutes'); Filter::formatHumanReadableTime('five_minutes');
} }

View file

@ -18,7 +18,7 @@ class I18nTest extends TestCase
public function tearDown(): void public function tearDown(): void
{ {
/* Tear Down Routine */ unset($_COOKIE['lang'], $_SERVER['HTTP_ACCEPT_LANGUAGE']);
} }
public function testTranslationFallback() public function testTranslationFallback()

View file

@ -116,10 +116,6 @@ class ModelTest extends TestCase
$this->assertEquals(Helper::getPasteId(), $comment->getParentId(), 'comment parent ID gets initialized to paste ID'); $this->assertEquals(Helper::getPasteId(), $comment->getParentId(), 'comment parent ID gets initialized to paste ID');
} }
/**
* @expectedException Exception
* @expectedExceptionCode 75
*/
public function testPasteDuplicate() public function testPasteDuplicate()
{ {
$pasteData = Helper::getPastePost(); $pasteData = Helper::getPastePost();
@ -131,13 +127,11 @@ class ModelTest extends TestCase
$paste = $this->_model->getPaste(); $paste = $this->_model->getPaste();
$paste->setData($pasteData); $paste->setData($pasteData);
$this->expectException(Exception::class);
$this->expectExceptionCode(75);
$paste->store(); $paste->store();
} }
/**
* @expectedException Exception
* @expectedExceptionCode 69
*/
public function testCommentDuplicate() public function testCommentDuplicate()
{ {
$pasteData = Helper::getPastePost(); $pasteData = Helper::getPastePost();
@ -154,6 +148,8 @@ class ModelTest extends TestCase
$comment = $paste->getComment(Helper::getPasteId()); $comment = $paste->getComment(Helper::getPasteId());
$comment->setData($commentData); $comment->setData($commentData);
$this->expectException(Exception::class);
$this->expectExceptionCode(69);
$comment->store(); $comment->store();
} }
@ -185,40 +181,30 @@ class ModelTest extends TestCase
$this->assertFalse(Paste::isValidId('../bar/baz'), 'path attack'); $this->assertFalse(Paste::isValidId('../bar/baz'), 'path attack');
} }
/**
* @expectedException Exception
* @expectedExceptionCode 64
*/
public function testInvalidPaste() public function testInvalidPaste()
{ {
$this->_model->getPaste(Helper::getPasteId())->delete(); $this->_model->getPaste(Helper::getPasteId())->delete();
$paste = $this->_model->getPaste(Helper::getPasteId()); $paste = $this->_model->getPaste(Helper::getPasteId());
$this->expectException(Exception::class);
$this->expectExceptionCode(64);
$paste->get(); $paste->get();
} }
/**
* @expectedException Exception
* @expectedExceptionCode 60
*/
public function testInvalidPasteId() public function testInvalidPasteId()
{ {
$this->expectException(Exception::class);
$this->expectExceptionCode(60);
$this->_model->getPaste(''); $this->_model->getPaste('');
} }
/**
* @expectedException Exception
* @expectedExceptionCode 62
*/
public function testInvalidComment() public function testInvalidComment()
{ {
$paste = $this->_model->getPaste(); $paste = $this->_model->getPaste();
$this->expectException(Exception::class);
$this->expectExceptionCode(62);
$paste->getComment(Helper::getPasteId()); $paste->getComment(Helper::getPasteId());
} }
/**
* @expectedException Exception
* @expectedExceptionCode 67
*/
public function testInvalidCommentDeletedPaste() public function testInvalidCommentDeletedPaste()
{ {
$pasteData = Helper::getPastePost(); $pasteData = Helper::getPastePost();
@ -228,13 +214,11 @@ class ModelTest extends TestCase
$comment = $paste->getComment(Helper::getPasteId()); $comment = $paste->getComment(Helper::getPasteId());
$paste->delete(); $paste->delete();
$this->expectException(Exception::class);
$this->expectExceptionCode(67);
$comment->store(); $comment->store();
} }
/**
* @expectedException Exception
* @expectedExceptionCode 68
*/
public function testInvalidCommentData() public function testInvalidCommentData()
{ {
$pasteData = Helper::getPastePost(); $pasteData = Helper::getPastePost();
@ -244,18 +228,17 @@ class ModelTest extends TestCase
$paste->store(); $paste->store();
$comment = $paste->getComment(Helper::getPasteId()); $comment = $paste->getComment(Helper::getPasteId());
$this->expectException(Exception::class);
$this->expectExceptionCode(68);
$comment->store(); $comment->store();
} }
/**
* @expectedException Exception
* @expectedExceptionCode 65
*/
public function testInvalidCommentParent() public function testInvalidCommentParent()
{ {
$paste = $this->_model->getPaste(Helper::getPasteId()); $paste = $this->_model->getPaste(Helper::getPasteId());
$comment = $paste->getComment(''); $this->expectException(Exception::class);
$comment->store(); $this->expectExceptionCode(65);
$paste->getComment('');
} }
public function testExpiration() public function testExpiration()
@ -273,10 +256,6 @@ class ModelTest extends TestCase
$this->assertEquals((float) 300, (float) $paste['meta']['time_to_live'], 'remaining time is set correctly', 1.0); $this->assertEquals((float) 300, (float) $paste['meta']['time_to_live'], 'remaining time is set correctly', 1.0);
} }
/**
* @expectedException Exception
* @expectedExceptionCode 64
*/
public function testCommentDeletion() public function testCommentDeletion()
{ {
$pasteData = Helper::getPastePost(); $pasteData = Helper::getPastePost();
@ -285,6 +264,8 @@ class ModelTest extends TestCase
$paste = $this->_model->getPaste(); $paste = $this->_model->getPaste();
$paste->setData($pasteData); $paste->setData($pasteData);
$paste->store(); $paste->store();
$this->expectException(Exception::class);
$this->expectExceptionCode(64);
$paste->getComment(Helper::getPasteId())->delete(); $paste->getComment(Helper::getPasteId())->delete();
} }

View file

@ -51,22 +51,16 @@ class ServerSaltTest extends TestCase
$this->assertEquals($salt, ServerSalt::get()); $this->assertEquals($salt, ServerSalt::get());
} }
/**
* @expectedException Exception
* @expectedExceptionCode 11
*/
public function testPathShenanigans() public function testPathShenanigans()
{ {
// try setting an invalid path // try setting an invalid path
chmod($this->_invalidPath, 0000); chmod($this->_invalidPath, 0000);
ServerSalt::setPath($this->_invalidPath); ServerSalt::setPath($this->_invalidPath);
$this->expectException(Exception::class);
$this->expectExceptionCode(11);
ServerSalt::get(); ServerSalt::get();
} }
/**
* @expectedException Exception
* @expectedExceptionCode 20
*/
public function testFileRead() public function testFileRead()
{ {
// try setting an invalid file // try setting an invalid file
@ -74,13 +68,11 @@ class ServerSaltTest extends TestCase
file_put_contents($this->_invalidFile, ''); file_put_contents($this->_invalidFile, '');
chmod($this->_invalidFile, 0000); chmod($this->_invalidFile, 0000);
ServerSalt::setPath($this->_invalidPath); ServerSalt::setPath($this->_invalidPath);
$this->expectException(Exception::class);
$this->expectExceptionCode(20);
ServerSalt::get(); ServerSalt::get();
} }
/**
* @expectedException Exception
* @expectedExceptionCode 13
*/
public function testFileWrite() public function testFileWrite()
{ {
// try setting an invalid file // try setting an invalid file
@ -92,18 +84,18 @@ class ServerSaltTest extends TestCase
file_put_contents($this->_invalidPath . DIRECTORY_SEPARATOR . '.htaccess', ''); file_put_contents($this->_invalidPath . DIRECTORY_SEPARATOR . '.htaccess', '');
chmod($this->_invalidPath, 0500); chmod($this->_invalidPath, 0500);
ServerSalt::setPath($this->_invalidPath); ServerSalt::setPath($this->_invalidPath);
$this->expectException(Exception::class);
$this->expectExceptionCode(13);
ServerSalt::get(); ServerSalt::get();
} }
/**
* @expectedException Exception
* @expectedExceptionCode 10
*/
public function testPermissionShenanigans() public function testPermissionShenanigans()
{ {
// try creating an invalid path // try creating an invalid path
chmod($this->_invalidPath, 0000); chmod($this->_invalidPath, 0000);
ServerSalt::setPath($this->_invalidPath . DIRECTORY_SEPARATOR . 'baz'); ServerSalt::setPath($this->_invalidPath . DIRECTORY_SEPARATOR . 'baz');
$this->expectException(Exception::class);
$this->expectExceptionCode(10);
ServerSalt::get(); ServerSalt::get();
} }
} }

View file

@ -95,28 +95,28 @@ class ViewTest extends TestCase
public function testTemplateRendersCorrectly() public function testTemplateRendersCorrectly()
{ {
foreach ($this->_content as $template => $content) { foreach ($this->_content as $template => $content) {
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '#s', '#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '#s',
$content, $content,
$template . ': outputs error correctly' $template . ': outputs error correctly'
); );
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<[^>]+id="password"[^>]*>#', '#<[^>]+id="password"[^>]*>#',
$content, $content,
$template . ': password available if configured' $template . ': password available if configured'
); );
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#', '#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
$content, $content,
$template . ': checked discussion if configured' $template . ': checked discussion if configured'
); );
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<[^>]+id="opendiscussionoption"[^>]*>#', '#<[^>]+id="opendiscussionoption"[^>]*>#',
$content, $content,
$template . ': discussions available if configured' $template . ': discussions available if configured'
); );
// testing version number in JS address, since other instances may not be present in different templates // testing version number in JS address, since other instances may not be present in different templates
$this->assertRegExp( $this->assertMatchesRegularExpression(
'#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#', '#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
$content, $content,
$template . ': outputs version correctly' $template . ': outputs version correctly'
@ -124,13 +124,11 @@ class ViewTest extends TestCase
} }
} }
/**
* @expectedException Exception
* @expectedExceptionCode 80
*/
public function testMissingTemplate() public function testMissingTemplate()
{ {
$test = new View; $test = new View;
$this->expectException(Exception::class);
$this->expectExceptionCode(80);
$test->draw('123456789 does not exist!'); $test->draw('123456789 does not exist!');
} }
} }

View file

@ -1,19 +1,22 @@
<phpunit bootstrap="Bootstrap.php" colors="true"> <?xml version="1.0"?>
<testsuite name="PrivateBin Test Suite"> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="Bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<directory suffix=".php">./</directory> <coverage>
<exclude>ConfigurationTestGenerator.php</exclude> <include>
</testsuite> <directory suffix=".php">../lib</directory>
<filter> </include>
<whitelist> <exclude>
<directory suffix=".php">../lib</directory> <file>../lib/Data/AbstractData.php</file>
<exclude> </exclude>
<file>../lib/Data/AbstractData.php</file> <report>
</exclude> <clover outputFile="log/coverage-clover.xml"/>
</whitelist> <html outputDirectory="log/php-coverage-report" lowUpperBound="50" highLowerBound="80"/>
</filter> </report>
<logging> </coverage>
<log type="coverage-clover" target="log/coverage-clover.xml" /> <testsuite name="PrivateBin Test Suite">
<log type="coverage-html" target="log/php-coverage-report" lowUpperBound="50" highLowerBound="80" /> <directory suffix=".php">./</directory>
<log type="testdox-html" target="log/testdox.html" /> <exclude>ConfigurationTestGenerator.php</exclude>
</logging> </testsuite>
<logging>
<testdoxHtml outputFile="log/testdox.html"/>
</logging>
</phpunit> </phpunit>