install:
# install/update composer and php dependencies
- - composer install --prefer-dist
+ - composer config --unset platform && composer config platform.php $TRAVIS_PHP_VERSION
+ - composer update
before_script:
- PATH=${PATH//:\.\/node_modules\/\.bin/}
"require-dev": {
"roave/security-advisories": "dev-master",
"phpunit/phpcov": "*",
- "phpunit/phpunit": "^7.5",
+ "phpunit/phpunit": "^7.5 || ^8.0",
"squizlabs/php_codesniffer": "3.*"
},
"suggest": {
/**
* Reset test data for each test
*/
- public function setUp()
+ protected function setUp(): void
{
FakeApplicationUtils::$VERSION_CODE = '';
if (file_exists(self::$testUpdateFile)) {
/**
* Remove test version file if it exists
*/
- public function tearDown()
+ protected function tearDown(): void
{
if (is_file('sandbox/version.php')) {
unlink('sandbox/version.php');
/**
* Test update checks - invalid Git branch
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Invalid branch selected for updates/
*/
public function testCheckUpdateInvalidGitBranch()
{
+ $this->expectExceptionMessageRegExp('/Invalid branch selected for updates/');
+
ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable');
}
/**
* Check a unsupported PHP version
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
*/
public function testCheckSupportedPHPVersion51()
{
+ $this->expectExceptionMessageRegExp('/Your PHP version is obsolete/');
+
$this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.1.0'));
}
/**
* Check another unsupported PHP version
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
*/
public function testCheckSupportedPHPVersion52()
{
+ $this->expectExceptionMessageRegExp('/Your PHP version is obsolete/');
+
$this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.2'));
}
/**
* Delete test file after every test.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$file);
}
/**
* File not writable: raise an exception.
- *
- * @expectedException Shaarli\Exceptions\IOException
- * @expectedExceptionMessage Error accessing "sandbox/flat.db"
*/
public function testWriteWithoutPermission()
{
+ $this->expectException(\Shaarli\Exceptions\IOException::class);
+ $this->expectExceptionMessage('Error accessing "sandbox/flat.db"');
+
touch(self::$file);
chmod(self::$file, 0440);
FileUtils::writeFlatDB(self::$file, null);
/**
* Folder non existent: raise an exception.
- *
- * @expectedException Shaarli\Exceptions\IOException
- * @expectedExceptionMessage Error accessing "nopefolder"
*/
public function testWriteFolderDoesNotExist()
{
+ $this->expectException(\Shaarli\Exceptions\IOException::class);
+ $this->expectExceptionMessage('Error accessing "nopefolder"');
+
FileUtils::writeFlatDB('nopefolder/file', null);
}
/**
* Folder non writable: raise an exception.
- *
- * @expectedException Shaarli\Exceptions\IOException
- * @expectedExceptionMessage Error accessing "sandbox"
*/
public function testWriteFolderPermission()
{
+ $this->expectException(\Shaarli\Exceptions\IOException::class);
+ $this->expectExceptionMessage('Error accessing "sandbox"');
+
chmod(dirname(self::$file), 0555);
try {
FileUtils::writeFlatDB(self::$file, null);
/**
* Delete history file.
*/
- public function setUp()
+ protected function setUp(): void
{
if (file_exists(self::$historyFilePath)) {
unlink(self::$historyFilePath);
/**
* Not writable history file: raise an exception.
- *
- * @expectedException Exception
- * @expectedExceptionMessage History file isn't readable or writable
*/
public function testConstructNotWritable()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('History file isn\'t readable or writable');
+
touch(self::$historyFilePath);
chmod(self::$historyFilePath, 0440);
$history = new History(self::$historyFilePath);
/**
* Not parsable history file: raise an exception.
- *
- * @expectedException Exception
- * @expectedExceptionMessageRegExp /Could not parse history file/
*/
public function testConstructNotParsable()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessageRegExp('/Could not parse history file/');
+
file_put_contents(self::$historyFilePath, 'not parsable');
$history = new History(self::$historyFilePath);
// gzinflate generates a warning
/**
*
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager(self::$configFile);
}
*/
protected $conf;
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('thumbnails.mode', Thumbnailer::MODE_ALL);
WTConfigManager::addFile('tests/utils/config/wt.json');
}
- public function tearDown()
+ protected function tearDown(): void
{
$this->rrmdirContent('sandbox/');
}
*/
protected $installedTimezones;
- public function setUp()
+ protected function setUp(): void
{
$this->installedTimezones = [
'Antarctica/Syowa',
/**
* Assign reference data
*/
- public static function setUpBeforeClass()
+ public static function setUpBeforeClass(): void
{
self::$defaultTimeZone = date_default_timezone_get();
// Timezone without DST for test consistency
/**
* Reset the timezone
*/
- public static function tearDownAfterClass()
+ public static function tearDownAfterClass(): void
{
date_default_timezone_set(self::$defaultTimeZone);
}
/**
* Resets test data before each test
*/
- protected function setUp()
+ protected function setUp(): void
{
if (file_exists(self::$testLogFile)) {
unlink(self::$testLogFile);
/**
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('api.secret', 'NapoleonWasALizard');
/**
* After every test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
}
/**
* Force the timezone for ISO datetimes.
*/
- public static function setUpBeforeClass()
+ public static function setUpBeforeClass(): void
{
date_default_timezone_set('UTC');
}
/**
* Test validateJwtToken() with a malformed JWT token.
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Malformed JWT token
*/
public function testValidateJwtTokenMalformed()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Malformed JWT token');
+
$token = 'ABC.DEF';
ApiUtils::validateJwtToken($token, 'foo');
}
/**
* Test validateJwtToken() with an empty JWT token.
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Malformed JWT token
*/
public function testValidateJwtTokenMalformedEmpty()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Malformed JWT token');
+
$token = false;
ApiUtils::validateJwtToken($token, 'foo');
}
/**
* Test validateJwtToken() with a JWT token without header.
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Malformed JWT token
*/
public function testValidateJwtTokenMalformedEmptyHeader()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Malformed JWT token');
+
$token = '.payload.signature';
ApiUtils::validateJwtToken($token, 'foo');
}
/**
* Test validateJwtToken() with a JWT token without payload
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Malformed JWT token
*/
public function testValidateJwtTokenMalformedEmptyPayload()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Malformed JWT token');
+
$token = 'header..signature';
ApiUtils::validateJwtToken($token, 'foo');
}
/**
* Test validateJwtToken() with a JWT token with an empty signature.
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Invalid JWT signature
*/
public function testValidateJwtTokenInvalidSignatureEmpty()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Invalid JWT signature');
+
$token = 'header.payload.';
ApiUtils::validateJwtToken($token, 'foo');
}
/**
* Test validateJwtToken() with a JWT token with an invalid signature.
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Invalid JWT signature
*/
public function testValidateJwtTokenInvalidSignature()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Invalid JWT signature');
+
$token = 'header.payload.nope';
ApiUtils::validateJwtToken($token, 'foo');
}
/**
* Test validateJwtToken() with a JWT token with a signature generated with the wrong API secret.
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Invalid JWT signature
*/
public function testValidateJwtTokenInvalidSignatureSecret()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Invalid JWT signature');
+
ApiUtils::validateJwtToken(self::generateValidJwtToken('foo'), 'bar');
}
/**
* Test validateJwtToken() with a JWT token with a an invalid header (not JSON).
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Invalid JWT header
*/
public function testValidateJwtTokenInvalidHeader()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Invalid JWT header');
+
$token = $this->generateCustomJwtToken('notJSON', '{"JSON":1}', 'secret');
ApiUtils::validateJwtToken($token, 'secret');
}
/**
* Test validateJwtToken() with a JWT token with a an invalid payload (not JSON).
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Invalid JWT payload
*/
public function testValidateJwtTokenInvalidPayload()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Invalid JWT payload');
+
$token = $this->generateCustomJwtToken('{"JSON":1}', 'notJSON', 'secret');
ApiUtils::validateJwtToken($token, 'secret');
}
/**
* Test validateJwtToken() with a JWT token without issued time.
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Invalid JWT issued time
*/
public function testValidateJwtTokenInvalidTimeEmpty()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Invalid JWT issued time');
+
$token = $this->generateCustomJwtToken('{"JSON":1}', '{"JSON":1}', 'secret');
ApiUtils::validateJwtToken($token, 'secret');
}
/**
* Test validateJwtToken() with an expired JWT token.
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Invalid JWT issued time
*/
public function testValidateJwtTokenInvalidTimeExpired()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Invalid JWT issued time');
+
$token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() - 600) . '}', 'secret');
ApiUtils::validateJwtToken($token, 'secret');
}
/**
* Test validateJwtToken() with a JWT token issued in the future.
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
- * @expectedExceptionMessage Invalid JWT issued time
*/
public function testValidateJwtTokenInvalidTimeFuture()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
+ $this->expectExceptionMessage('Invalid JWT issued time');
+
$token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret');
ApiUtils::validateJwtToken($token, 'secret');
}
/**
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->refHistory = new \ReferenceHistory();
/**
* After every test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testHistory);
}
/**
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
/**
* After every test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
}
/**
* Before each test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
/**
* After each test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
@unlink(self::$testHistory);
/**
* Test DELETE link endpoint: reach not existing ID.
- *
- * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException
*/
public function testDeleteLink404()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
+
$id = -1;
$this->assertFalse($this->bookmarkService->exists($id));
$env = Environment::mock([
/**
* Before each test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
/**
* After each test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
}
/**
* Test basic getLink service: get non existent link => ApiLinkNotFoundException.
- *
- * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException
- * @expectedExceptionMessage Link not found
*/
public function testGetLink404()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
+ $this->expectExceptionMessage('Link not found');
+
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
]);
/**
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
/**
* After every test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
}
/**
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
/**
* After every test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
@unlink(self::$testHistory);
/**
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
/**
* After every test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
@unlink(self::$testHistory);
/**
* Test link update on non existent link => ApiLinkNotFoundException.
- *
- * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException
- * @expectedExceptionMessage Link not found
*/
public function testGetLink404()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
+ $this->expectExceptionMessage('Link not found');
+
$env = Environment::mock([
'REQUEST_METHOD' => 'PUT',
]);
/**
* Before each test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
/**
* After each test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
@unlink(self::$testHistory);
/**
* Test DELETE tag endpoint: reach not existing tag.
- *
- * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException
- * @expectedExceptionMessage Tag not found
*/
public function testDeleteLink404()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class);
+ $this->expectExceptionMessage('Tag not found');
+
$tagName = 'nopenope';
$tags = $this->bookmarkService->bookmarksCountPerTag();
$this->assertFalse(isset($tags[$tagName]));
/**
* Before each test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
/**
* After each test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
}
/**
* Test basic getTag service: get non existent tag => ApiTagNotFoundException.
- *
- * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException
- * @expectedExceptionMessage Tag not found
*/
public function testGetTag404()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class);
+ $this->expectExceptionMessage('Tag not found');
+
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
]);
/**
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
/**
* After every test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
}
/**
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
/**
* After every test, remove the test datastore.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$testDatastore);
@unlink(self::$testHistory);
/**
* Test tag update with an empty new tag name => ApiBadParametersException
- *
- * @expectedException Shaarli\Api\Exceptions\ApiBadParametersException
- * @expectedExceptionMessage New tag name is required in the request body
*/
public function testPutTagEmpty()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiBadParametersException::class);
+ $this->expectExceptionMessage('New tag name is required in the request body');
+
$tagName = 'gnu';
$newName = '';
/**
* Test tag update on non existent tag => ApiTagNotFoundException.
- *
- * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException
- * @expectedExceptionMessage Tag not found
*/
public function testPutTag404()
{
+ $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class);
+ $this->expectExceptionMessage('Tag not found');
+
$env = Environment::mock([
'REQUEST_METHOD' => 'PUT',
]);
/**
* Test adding a bad entry: wrong type
- *
- * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
*/
public function testArrayAccessAddBadEntryInstance()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
+
$array = new BookmarkArray();
$array[] = 'nope';
}
/**
* Test adding a bad entry: no id
- *
- * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
*/
public function testArrayAccessAddBadEntryNoId()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
+
$array = new BookmarkArray();
$bookmark = new Bookmark();
$array[] = $bookmark;
/**
* Test adding a bad entry: no url
- *
- * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
*/
public function testArrayAccessAddBadEntryNoUrl()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
+
$array = new BookmarkArray();
$bookmark = (new Bookmark())->setId(11);
$array[] = $bookmark;
/**
* Test adding a bad entry: invalid offset
- *
- * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
*/
public function testArrayAccessAddBadEntryOffset()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
+
$array = new BookmarkArray();
$bookmark = (new Bookmark())->setId(11);
$bookmark->validate();
/**
* Test adding a bad entry: invalid ID type
- *
- * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
*/
public function testArrayAccessAddBadEntryIdType()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
+
$array = new BookmarkArray();
$bookmark = (new Bookmark())->setId('nope');
$bookmark->validate();
/**
* Test adding a bad entry: ID/offset not consistent
- *
- * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
*/
public function testArrayAccessAddBadEntryIdOffset()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
+
$array = new BookmarkArray();
$bookmark = (new Bookmark())->setId(11);
$bookmark->validate();
*
* Resets test data for each test
*/
- protected function setUp()
+ protected function setUp(): void
{
if (file_exists(self::$testDatastore)) {
unlink(self::$testDatastore);
/**
* Test get() method for an undefined bookmark
- *
- * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
*/
public function testGetUndefined()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
+
$this->privateLinkDB->get(666);
}
/**
* Test add() method for a bookmark without any field set and without writing the data store
- *
- * @expectedExceptionMessage Shaarli\Bookmark\Exception\BookmarkNotFoundException
*/
public function testAddMinimalNoWrite()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
+
$bookmark = new Bookmark();
- $this->privateLinkDB->add($bookmark);
+ $this->privateLinkDB->add($bookmark, false);
$bookmark = $this->privateLinkDB->get(43);
$this->assertEquals(43, $bookmark->getId());
/**
* Test add() method while logged out
- *
- * @expectedException \Exception
- * @expectedExceptionMessage You're not authorized to alter the datastore
*/
public function testAddLoggedOut()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
+
$this->publicLinkDB->add(new Bookmark());
}
/**
* Test add() method with an entry which is not a bookmark instance
- *
- * @expectedException \Exception
- * @expectedExceptionMessage Provided data is invalid
*/
public function testAddNotABookmark()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Provided data is invalid');
+
$this->privateLinkDB->add(['title' => 'hi!']);
}
/**
* Test add() method with a Bookmark already containing an ID
- *
- * @expectedException \Exception
- * @expectedExceptionMessage This bookmarks already exists
*/
public function testAddWithId()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('This bookmarks already exists');
+
$bookmark = new Bookmark();
$bookmark->setId(43);
$this->privateLinkDB->add($bookmark);
/**
* Test set() method while logged out
- *
- * @expectedException \Exception
- * @expectedExceptionMessage You're not authorized to alter the datastore
*/
public function testSetLoggedOut()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
+
$this->publicLinkDB->set(new Bookmark());
}
/**
* Test set() method with an entry which is not a bookmark instance
- *
- * @expectedException \Exception
- * @expectedExceptionMessage Provided data is invalid
*/
public function testSetNotABookmark()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Provided data is invalid');
+
$this->privateLinkDB->set(['title' => 'hi!']);
}
/**
* Test set() method with a Bookmark without an ID defined.
- *
- * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
*/
public function testSetWithoutId()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
+
$bookmark = new Bookmark();
$this->privateLinkDB->set($bookmark);
}
/**
* Test set() method with a Bookmark with an unknow ID
- *
- * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
*/
public function testSetWithUnknownId()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
+
$bookmark = new Bookmark();
$bookmark->setId(666);
$this->privateLinkDB->set($bookmark);
/**
* Test addOrSet() method while logged out
- *
- * @expectedException \Exception
- * @expectedExceptionMessage You're not authorized to alter the datastore
*/
public function testAddOrSetLoggedOut()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
+
$this->publicLinkDB->addOrSet(new Bookmark());
}
/**
* Test addOrSet() method with an entry which is not a bookmark instance
- *
- * @expectedException \Exception
- * @expectedExceptionMessage Provided data is invalid
*/
public function testAddOrSetNotABookmark()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Provided data is invalid');
+
$this->privateLinkDB->addOrSet(['title' => 'hi!']);
}
/**
* Test remove() method with an existing Bookmark
- *
- * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
*/
public function testRemoveExisting()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
+
$bookmark = $this->privateLinkDB->get(42);
$this->privateLinkDB->remove($bookmark);
/**
* Test remove() method while logged out
- *
- * @expectedException \Exception
- * @expectedExceptionMessage You're not authorized to alter the datastore
*/
public function testRemoveLoggedOut()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
+
$bookmark = $this->privateLinkDB->get(42);
$this->publicLinkDB->remove($bookmark);
}
/**
* Test remove() method with an entry which is not a bookmark instance
- *
- * @expectedException \Exception
- * @expectedExceptionMessage Provided data is invalid
*/
public function testRemoveNotABookmark()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Provided data is invalid');
+
$this->privateLinkDB->remove(['title' => 'hi!']);
}
/**
* Test remove() method with a Bookmark with an unknown ID
- *
- * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
*/
public function testRemoveWithUnknownId()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
+
$bookmark = new Bookmark();
$bookmark->setId(666);
$this->privateLinkDB->remove($bookmark);
* to make sure that nothing have been broken in the migration process.
* They mostly cover search/filters. Some of them might be redundant with the previous ones.
*/
-
/**
* Attempt to instantiate a LinkDB whereas the datastore is not writable
*
* @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException
- * @expectedExceptionMessageRegExp #Couldn't load data from the data store file "null".*#
*/
public function testConstructDatastoreNotWriteable()
{
+ $this->expectExceptionMessageRegExp('#Couldn\'t load data from the data store file "null".*#');
+
$conf = new ConfigManager('tests/utils/config/configJson');
$conf->set('resource.datastore', 'null/store.db');
new BookmarkFileService($conf, $this->history, true);
/**
* Use an invalid date format
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Invalid date format/
*/
public function testFilterInvalidDayWithChars()
{
+ $this->expectExceptionMessageRegExp('/Invalid date format/');
+
self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away');
}
/**
* Use an invalid date format
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Invalid date format/
*/
public function testFilterInvalidDayDigits()
{
+ $this->expectExceptionMessageRegExp('/Invalid date format/');
+
self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20');
}
/**
* No link for this hash
- *
- * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
*/
public function testFilterUnknownSmallHash()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
+
self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah');
}
*/
protected $configIO;
- public function setUp()
+ protected function setUp(): void
{
$this->configIO = new ConfigJson();
}
/**
* Read a non existent config file -> empty array.
- *
- * @expectedException \Exception
- * @expectedExceptionMessageRegExp /An error occurred while parsing JSON configuration file \([\w\/\.]+\): error code #4/
*/
public function testReadInvalidJson()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessageRegExp(' /An error occurred while parsing JSON configuration file \\([\\w\\/\\.]+\\): error code #4/');
+
$this->configIO->read('tests/utils/config/configInvalid.json.php');
}
/**
* Write to invalid path.
- *
- * @expectedException \Shaarli\Exceptions\IOException
*/
public function testWriteInvalidArray()
{
+ $this->expectException(\Shaarli\Exceptions\IOException::class);
+
$conf = array('conf' => 'value');
@$this->configIO->write(array(), $conf);
}
/**
* Write to invalid path.
- *
- * @expectedException \Shaarli\Exceptions\IOException
*/
public function testWriteInvalidBlank()
{
+ $this->expectException(\Shaarli\Exceptions\IOException::class);
+
$conf = array('conf' => 'value');
@$this->configIO->write('', $conf);
}
*/
protected $conf;
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager('tests/utils/config/configJson');
}
/**
* Set with an empty key.
- *
- * @expectedException \Exception
- * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
*/
public function testSetEmptyKey()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
+
$this->conf->set('', 'stuff');
}
/**
* Set with an array key.
- *
- * @expectedException \Exception
- * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
*/
public function testSetArrayKey()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
+
$this->conf->set(array('foo' => 'bar'), 'stuff');
}
/**
* Remove with an empty key.
- *
- * @expectedException \Exception
- * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
*/
public function testRmoveEmptyKey()
{
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
+
$this->conf->remove('');
}
/**
* Try to write the config without mandatory parameter (e.g. 'login').
- *
- * @expectedException Shaarli\Config\Exception\MissingFieldConfigException
*/
public function testWriteMissingParameter()
{
+ $this->expectException(\Shaarli\Config\Exception\MissingFieldConfigException::class);
+
$this->conf->setConfigFile('tests/utils/config/configTmp');
$this->assertFalse(file_exists($this->conf->getConfigFileExt()));
$this->conf->reload();
*/
protected $configIO;
- public function setUp()
+ protected function setUp(): void
{
$this->configIO = new ConfigPhp();
}
/**
* Test save_plugin_config with invalid data.
- *
- * @expectedException Shaarli\Config\Exception\PluginConfigOrderException
*/
public function testSavePluginConfigInvalid()
{
+ $this->expectException(\Shaarli\Config\Exception\PluginConfigOrderException::class);
+
$data = array(
'plugin2' => 0,
'plugin3' => 0,
/**
* Create the cache directory if needed
*/
- public static function setUpBeforeClass()
+ public static function setUpBeforeClass(): void
{
if (!is_dir(self::$testCacheDir)) {
mkdir(self::$testCacheDir);
/**
* Reset the page cache
*/
- public function setUp()
+ protected function setUp(): void
{
if (file_exists(self::$filename)) {
unlink(self::$filename);
/**
* Initialize formatter instance.
*/
- public function setUp()
+ protected function setUp(): void
{
copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
$this->conf = new ConfigManager(self::$testConf);
/**
* Initialize formatter instance.
*/
- public function setUp()
+ protected function setUp(): void
{
copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
$this->conf = new ConfigManager(self::$testConf);
/**
* Initialize formatter instance.
*/
- public function setUp()
+ protected function setUp(): void
{
copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
$this->conf = new ConfigManager(self::$testConf);
/**
* Initialize FormatterFactory instance
*/
- public function setUp()
+ protected function setUp(): void
{
copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
$this->conf = new ConfigManager(self::$testConf);
/**
* Init: force French
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new ConfigManager(self::$configFile);
$this->conf->set('translation.language', 'fr');
/**
* Reset the locale since gettext seems to mess with it, making it too long
*/
- public static function tearDownAfterClass()
+ public static function tearDownAfterClass(): void
{
if (! empty(getenv('UT_LOCALE'))) {
setlocale(LC_ALL, getenv('UT_LOCALE'));
*
* Resets test data for each test
*/
- protected function setUp()
+ protected function setUp(): void
{
if (file_exists(self::$testDatastore)) {
unlink(self::$testDatastore);
* Attempt to instantiate a LinkDB whereas the datastore is not writable
*
* @expectedException Shaarli\Exceptions\IOException
- * @expectedExceptionMessageRegExp /Error accessing "null"/
*/
public function testConstructDatastoreNotWriteable()
{
+ $this->expectExceptionMessageRegExp('/Error accessing "null"/');
+
new LegacyLinkDB('null/store.db', false, false);
}
/**
* Test filterHash() with an invalid smallhash.
- *
- * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
*/
public function testFilterHashInValid1()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
+
$request = 'blabla';
self::$publicLinkDB->filterHash($request);
}
/**
* Test filterHash() with an empty smallhash.
- *
- * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
*/
public function testFilterHashInValid()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
+
self::$publicLinkDB->filterHash('');
}
/**
* Instantiate linkFilter with ReferenceLinkDB data.
*/
- public static function setUpBeforeClass()
+ public static function setUpBeforeClass(): void
{
self::$refDB = new ReferenceLinkDB(true);
self::$refDB->write(self::$testDatastore);
/**
* Use an invalid date format
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Invalid date format/
*/
public function testFilterInvalidDayWithChars()
{
+ $this->expectExceptionMessageRegExp('/Invalid date format/');
+
self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, 'Rainy day, dream away');
}
/**
* Use an invalid date format
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Invalid date format/
*/
public function testFilterInvalidDayDigits()
{
+ $this->expectExceptionMessageRegExp('/Invalid date format/');
+
self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, '20');
}
/**
* No link for this hash
- *
- * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
*/
public function testFilterUnknownSmallHash()
{
+ $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
+
self::$linkFilter->filter(LegacyLinkFilter::$FILTER_HASH, 'Iblaah');
}
/**
* Executed before each test.
*/
- public function setUp()
+ protected function setUp(): void
{
copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php');
$this->conf = new ConfigManager(self::$configFile);
* Test errors in UpdaterUtils::write_updates_file(): empty updates file.
*
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/
*/
public function testWriteEmptyUpdatesFile()
{
+ $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
+
UpdaterUtils::write_updates_file('', array('test'));
}
* Test errors in UpdaterUtils::write_updates_file(): not writable updates file.
*
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Unable to write(.*)/
*/
public function testWriteUpdatesFileNotWritable()
{
+ $this->expectExceptionMessageRegExp('/Unable to write(.*)/');
+
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
touch($updatesFile);
chmod($updatesFile, 0444);
/**
* Test Update failed.
- *
- * @expectedException \Exception
*/
public function testUpdateFailed()
{
+ $this->expectException(\Exception::class);
+
$updates = array(
'updateMethodDummy1',
'updateMethodDummy2',
if (isset($_SESSION['warnings'])) {
unset($_SESSION['warnings']);
}
-
+
$updater = new LegacyUpdater([], [], $this->conf, true, $_SESSION);
$this->assertTrue($updater->updateMethodWebThumbnailer());
$this->assertFalse($this->conf->exists('thumbnail'));
/**
* Instantiate reference data
*/
- public static function setUpBeforeClass()
+ public static function setUpBeforeClass(): void
{
static::$conf = new ConfigManager('tests/utils/config/configJson');
static::$conf->set('resource.datastore', static::$testDatastore);
/**
* Attempt to export an invalid link selection
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Invalid export selection/
*/
public function testFilterAndFormatInvalid()
{
+ $this->expectExceptionMessageRegExp('/Invalid export selection/');
+
$this->netscapeBookmarkUtils->filterAndFormat(
self::$formatter,
'derp',
*/
protected static $defaultTimeZone;
- public static function setUpBeforeClass()
+ public static function setUpBeforeClass(): void
{
self::$defaultTimeZone = date_default_timezone_get();
// Timezone without DST for test consistency
/**
* Resets test data before each test
*/
- protected function setUp()
+ protected function setUp(): void
{
if (file_exists(self::$testDatastore)) {
unlink(self::$testDatastore);
/**
* Delete history file.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$historyFilePath);
}
- public static function tearDownAfterClass()
+ public static function tearDownAfterClass(): void
{
date_default_timezone_set(self::$defaultTimeZone);
}
/**
* Reset plugin path.
*/
- public function setUp()
+ protected function setUp(): void
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Reset plugin path
*/
- public function setUp()
+ protected function setUp(): void
{
PluginManager::$PLUGINS_PATH = 'sandbox';
mkdir(PluginManager::$PLUGINS_PATH . '/default_colors/');
/**
* Remove sandbox files and folder
*/
- public function tearDown()
+ protected function tearDown(): void
{
if (file_exists('sandbox/default_colors/default_colors.css.template')) {
unlink('sandbox/default_colors/default_colors.css.template');
/**
* Reset plugin path
*/
- public function setUp()
+ protected function setUp(): void
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Reset plugin path
*/
- public function setUp()
+ protected function setUp(): void
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Reset plugin path
*/
- public function setUp()
+ protected function setUp(): void
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Reset plugin path
*/
- public function setUp()
+ protected function setUp(): void
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Reset plugin path
*/
- public function setUp()
+ protected function setUp(): void
{
$this->instance = 'http://some.url';
}
/**
* Populate the cache with dummy files
*/
- public function setUp()
+ protected function setUp(): void
{
$this->cacheManager = new PageCacheManager(static::$testCacheDir, true);
/**
* Remove dummycache folder after each tests.
*/
- public function tearDown()
+ protected function tearDown(): void
{
array_map('unlink', glob(self::$testCacheDir . '/*'));
rmdir(self::$testCacheDir);
/**
* Prepare or reset test resources
*/
- public function setUp()
+ protected function setUp(): void
{
if (file_exists($this->banFile)) {
unlink($this->banFile);
/**
* Prepare or reset test resources
*/
- public function setUp()
+ protected function setUp(): void
{
if (file_exists($this->banFile)) {
unlink($this->banFile);
/**
* Assign reference data
*/
- public static function setUpBeforeClass()
+ public static function setUpBeforeClass(): void
{
self::$sidHashes = \ReferenceSessionIdHashes::getHashes();
}
/**
* Initialize or reset test resources
*/
- public function setUp()
+ protected function setUp(): void
{
$this->conf = new \FakeConfigManager([
'credentials.login' => 'johndoe',
/**
* Executed before each test.
*/
- public function setUp()
+ protected function setUp(): void
{
$this->refDB = new \ReferenceLinkDB();
$this->refDB->write(self::$testDatastore);
* Test errors in UpdaterUtils::write_updates_file(): empty updates file.
*
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/
*/
public function testWriteEmptyUpdatesFile()
{
+ $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
+
UpdaterUtils::write_updates_file('', array('test'));
}
* Test errors in UpdaterUtils::write_updates_file(): not writable updates file.
*
* @expectedException Exception
- * @expectedExceptionMessageRegExp /Unable to write(.*)/
*/
public function testWriteUpdatesFileNotWritable()
{
+ $this->expectExceptionMessageRegExp('/Unable to write(.*)/');
+
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
touch($updatesFile);
chmod($updatesFile, 0444);
/**
* Test Update failed.
- *
- * @expectedException \Exception
*/
public function testUpdateFailed()
{
+ $this->expectException(\Exception::class);
+
$updates = array(
'updateMethodDummy1',
'updateMethodDummy2',