X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FCore%2FLock%2FDatabaseLockDriverTest.php;h=5f3ef13c128e7de90e9c021aed061dbc92fd235e;hb=bc5a1e5acee9ceb61cd08734c554f69850120d76;hp=3d641376995549a91e3c1664b8f41a3919dbc5c8;hpb=deaecfaf790b4e7942dac753efe5eab9caf3c8dc;p=friendica.git diff --git a/tests/src/Core/Lock/DatabaseLockDriverTest.php b/tests/src/Core/Lock/DatabaseLockDriverTest.php index 3d64137699..5f3ef13c12 100644 --- a/tests/src/Core/Lock/DatabaseLockDriverTest.php +++ b/tests/src/Core/Lock/DatabaseLockDriverTest.php @@ -1,107 +1,62 @@ . + * + */ namespace Friendica\Test\src\Core\Lock; -use Friendica\Core\Cache; -use Friendica\Core\Lock\DatabaseLockDriver; -use Friendica\Test\Util\DbaLockMockTrait; +use Friendica\Core\Lock\DatabaseLock; +use Friendica\Factory\ConfigFactory; +use Friendica\Test\DatabaseTestTrait; +use Friendica\Test\Util\Database\StaticDatabase; +use Friendica\Test\Util\VFSTrait; +use Friendica\Util\ConfigFileLoader; +use Friendica\Util\Profiler; +use Psr\Log\NullLogger; -/** - * @runTestsInSeparateProcesses - * @preserveGlobalState disabled - */ class DatabaseLockDriverTest extends LockTest { - use DbaLockMockTrait; + use VFSTrait; + use DatabaseTestTrait; protected $pid = 123; protected function setUp() { - $this->mockConnected(); - $this->mockConnect(); - - $this->mockReleaseAll($this->pid, 2); + $this->setUpVfsDir(); parent::setUp(); } protected function getInstance() { - return new DatabaseLockDriver($this->pid); - } - - public function testLock() - { - $this->mockIsLocked('foo', false, $this->startTime, 1); - $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1); - $this->mockIsLocked('foo', true, $this->startTime, 1); - $this->mockIsLocked('bar', false, $this->startTime, 1); - - parent::testLock(); - } - - public function testDoubleLock() - { - $this->mockIsLocked('foo', false, $this->startTime, 1); - $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1); - $this->mockIsLocked('foo', true, $this->startTime, 1); - $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, true, $this->pid, true, $this->startTime, 1); - - parent::testDoubleLock(); - } - - public function testReleaseLock() - { - $this->mockIsLocked('foo', false, $this->startTime, 1); - $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1); - $this->mockIsLocked('foo', true, $this->startTime, 1); - $this->mockReleaseLock('foo', $this->pid, 1); - $this->mockIsLocked('foo', false, $this->startTime, 1); - - parent::testReleaseLock(); - } - - public function testReleaseAll() - { - $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1); - $this->mockAcquireLock('bar', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1); - $this->mockAcquireLock('nice', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1); - - $this->mockIsLocked('foo', true, $this->startTime, 1); - $this->mockIsLocked('bar', true, $this->startTime, 1); - $this->mockIsLocked('nice', true, $this->startTime, 1); - - $this->mockReleaseAll($this->pid, 1); - - $this->mockIsLocked('foo', false, $this->startTime, 1); - $this->mockIsLocked('bar', false, $this->startTime, 1); - $this->mockIsLocked('nice', false, $this->startTime, 1); - - parent::testReleaseAll(); - } - - public function testReleaseAfterUnlock() - { - $this->mockIsLocked('foo', false, $this->startTime, 1); - $this->mockIsLocked('bar', false, $this->startTime, 1); - $this->mockIsLocked('nice', false, $this->startTime, 1); - - $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1); - $this->mockAcquireLock('bar', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1); - $this->mockAcquireLock('nice', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1); - - $this->mockReleaseLock('foo', $this->pid, 1); - - $this->mockIsLocked('foo', false, $this->startTime, 1); - $this->mockIsLocked('bar', true, $this->startTime, 1); - $this->mockIsLocked('nice', true, $this->startTime, 1); + $logger = new NullLogger(); + $profiler = \Mockery::mock(Profiler::class); + $profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true); - $this->mockReleaseAll($this->pid, 1); + // load real config to avoid mocking every config-entry which is related to the Database class + $configFactory = new ConfigFactory(); + $loader = new ConfigFileLoader($this->root->url()); + $configCache = $configFactory->createCache($loader); - $this->mockIsLocked('bar', false, $this->startTime, 1); - $this->mockIsLocked('nice', false, $this->startTime, 1); + $dba = new StaticDatabase($configCache, $profiler, $logger); - parent::testReleaseAfterUnlock(); + return new DatabaseLock($dba, $this->pid); } }