X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fupdater%2FUpdaterTest.php;h=cadd826538f2e76f08bffe27bb3d105abcf43375;hb=302662797cb5e8ac6579a99297ceae301f7927a6;hp=c801d451fecc526bc8de258e4701a54a26f5d605;hpb=c4ad3d4f061d05a01db25aa54dda830ba776792d;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index c801d451..cadd8265 100644 --- a/tests/updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php @@ -2,17 +2,19 @@ namespace Shaarli\Updater; use Exception; +use malkusch\lock\mutex\NoMutex; use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; use Shaarli\History; +use Shaarli\TestCase; /** * Class UpdaterTest. * Runs unit tests against the updater class. */ -class UpdaterTest extends \PHPUnit\Framework\TestCase +class UpdaterTest extends TestCase { /** * @var string Path to test datastore. @@ -41,14 +43,15 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase /** * Executed before each test. */ - public function setUp() + protected function setUp(): void { + $mutex = new NoMutex(); $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php'); $this->conf = new ConfigManager(self::$configFile); - $this->bookmarkService = new BookmarkFileService($this->conf, $this->createMock(History::class), true); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->createMock(History::class), $mutex, true); $this->updater = new Updater([], $this->bookmarkService, $this->conf, true); } @@ -57,10 +60,10 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase */ public function testReadEmptyUpdatesFile() { - $this->assertEquals(array(), UpdaterUtils::read_updates_file('')); + $this->assertEquals(array(), UpdaterUtils::readUpdatesFile('')); $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; touch($updatesFile); - $this->assertEquals(array(), UpdaterUtils::read_updates_file($updatesFile)); + $this->assertEquals(array(), UpdaterUtils::readUpdatesFile($updatesFile)); unlink($updatesFile); } @@ -72,42 +75,42 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; $updatesMethods = array('m1', 'm2', 'm3'); - UpdaterUtils::write_updates_file($updatesFile, $updatesMethods); - $readMethods = UpdaterUtils::read_updates_file($updatesFile); + UpdaterUtils::writeUpdatesFile($updatesFile, $updatesMethods); + $readMethods = UpdaterUtils::readUpdatesFile($updatesFile); $this->assertEquals($readMethods, $updatesMethods); // Update $updatesMethods[] = 'm4'; - UpdaterUtils::write_updates_file($updatesFile, $updatesMethods); - $readMethods = UpdaterUtils::read_updates_file($updatesFile); + UpdaterUtils::writeUpdatesFile($updatesFile, $updatesMethods); + $readMethods = UpdaterUtils::readUpdatesFile($updatesFile); $this->assertEquals($readMethods, $updatesMethods); unlink($updatesFile); } /** * Test errors in UpdaterUtils::write_updates_file(): empty updates file. - * - * @expectedException Exception - * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/ */ public function testWriteEmptyUpdatesFile() { - UpdaterUtils::write_updates_file('', array('test')); + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/'); + + UpdaterUtils::writeUpdatesFile('', array('test')); } /** * Test errors in UpdaterUtils::write_updates_file(): not writable updates file. - * - * @expectedException Exception - * @expectedExceptionMessageRegExp /Unable to write(.*)/ */ public function testWriteUpdatesFileNotWritable() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/Unable to write(.*)/'); + $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; touch($updatesFile); chmod($updatesFile, 0444); try { - @UpdaterUtils::write_updates_file($updatesFile, array('test')); + @UpdaterUtils::writeUpdatesFile($updatesFile, array('test')); } catch (Exception $e) { unlink($updatesFile); throw $e; @@ -167,11 +170,11 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase /** * Test Update failed. - * - * @expectedException \Exception */ public function testUpdateFailed() { + $this->expectException(\Exception::class); + $updates = array( 'updateMethodDummy1', 'updateMethodDummy2', @@ -194,7 +197,6 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase public function testUpdateMethodRelativeHomeLinkDoNotRename(): void { - $this->updater->setBasePath('/subfolder'); $this->conf->set('general.header_link', '~/my-blog'); $this->updater->updateMethodRelativeHomeLink(); @@ -204,8 +206,6 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase public function testUpdateMethodMigrateExistingNotesUrl(): void { - $this->updater->setBasePath('/subfolder'); - $this->updater->updateMethodMigrateExistingNotesUrl(); static::assertSame($this->refDB->getLinks()[0]->getUrl(), $this->bookmarkService->get(0)->getUrl()); @@ -215,9 +215,9 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase static::assertSame($this->refDB->getLinks()[7]->getUrl(), $this->bookmarkService->get(7)->getUrl()); static::assertSame($this->refDB->getLinks()[8]->getUrl(), $this->bookmarkService->get(8)->getUrl()); static::assertSame($this->refDB->getLinks()[9]->getUrl(), $this->bookmarkService->get(9)->getUrl()); - static::assertSame('/subfolder/shaare/WDWyig', $this->bookmarkService->get(42)->getUrl()); - static::assertSame('/subfolder/shaare/WDWyig', $this->bookmarkService->get(41)->getUrl()); - static::assertSame('/subfolder/shaare/0gCTjQ', $this->bookmarkService->get(10)->getUrl()); - static::assertSame('/subfolder/shaare/PCRizQ', $this->bookmarkService->get(11)->getUrl()); + static::assertSame('/shaare/WDWyig', $this->bookmarkService->get(42)->getUrl()); + static::assertSame('/shaare/WDWyig', $this->bookmarkService->get(41)->getUrl()); + static::assertSame('/shaare/0gCTjQ', $this->bookmarkService->get(10)->getUrl()); + static::assertSame('/shaare/PCRizQ', $this->bookmarkService->get(11)->getUrl()); } }