From fd1ddad98df45bc3c18be7980c1cbe68ce6b219c Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 26 Sep 2020 14:18:01 +0200 Subject: Add mutex on datastore I/O operations To make sure that there is no concurrent operation on the datastore file. Fixes #1132 --- tests/updater/UpdaterTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/updater/UpdaterTest.php') diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index a6280b8c..47332544 100644 --- a/tests/updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php @@ -2,6 +2,7 @@ namespace Shaarli\Updater; use Exception; +use malkusch\lock\mutex\NoMutex; use Shaarli\Bookmark\BookmarkFileService; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; @@ -44,12 +45,13 @@ class UpdaterTest extends TestCase */ 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); } -- cgit v1.2.3 From b99e00f7cd5f7e2090f44cd97bfb426db55340c2 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 8 Nov 2020 15:02:45 +0100 Subject: Manually fix remaining PHPCS errors --- tests/updater/UpdaterTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/updater/UpdaterTest.php') diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index 47332544..cadd8265 100644 --- a/tests/updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php @@ -60,10 +60,10 @@ class UpdaterTest extends 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); } @@ -75,14 +75,14 @@ class UpdaterTest extends 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); } @@ -95,7 +95,7 @@ class UpdaterTest extends TestCase $this->expectException(\Exception::class); $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/'); - UpdaterUtils::write_updates_file('', array('test')); + UpdaterUtils::writeUpdatesFile('', array('test')); } /** @@ -110,7 +110,7 @@ class UpdaterTest extends TestCase 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; -- cgit v1.2.3