From 493b4289911200bf65b3d566f07c54d820467851 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 18 Oct 2021 19:36:56 +0200 Subject: [PATCH 1/2] require_once dbstructure.config.php for HTTPClientFactory.php in case we didn't load the DB --- src/Factory/HTTPClientFactory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Factory/HTTPClientFactory.php b/src/Factory/HTTPClientFactory.php index 7db5ee7b92..12d9fd45fa 100644 --- a/src/Factory/HTTPClientFactory.php +++ b/src/Factory/HTTPClientFactory.php @@ -5,10 +5,8 @@ namespace Friendica\Factory; use Friendica\App; use Friendica\BaseFactory; use Friendica\Core\Config\IConfig; -use Friendica\Core\System; use Friendica\Network\HTTPClient; use Friendica\Network\IHTTPClient; -use Friendica\Util\Crypto; use Friendica\Util\Profiler; use Friendica\Util\Strings; use GuzzleHttp\Client; @@ -20,6 +18,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\UriInterface; use Psr\Log\LoggerInterface; +require_once __DIR__ . '/../../static/dbstructure.config.php'; + class HTTPClientFactory extends BaseFactory { /** @var IConfig */ From ef1e2ce77eafb40c590bf9f70f7d2af36f951ad7 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 18 Oct 2021 20:08:40 +0200 Subject: [PATCH 2/2] Cleanup tests - Remove DBAMockTrait - Remove DBStructureMockTrait --- tests/Util/DBAMockTrait.php | 354 ------------------ tests/Util/DBStructureMockTrait.php | 77 ---- tests/src/App/ModeTest.php | 56 ++- .../AutomaticInstallationConsoleTest.php | 4 - tests/src/Model/UserTest.php | 123 +++--- 5 files changed, 82 insertions(+), 532 deletions(-) delete mode 100644 tests/Util/DBAMockTrait.php delete mode 100644 tests/Util/DBStructureMockTrait.php diff --git a/tests/Util/DBAMockTrait.php b/tests/Util/DBAMockTrait.php deleted file mode 100644 index 8967348dae..0000000000 --- a/tests/Util/DBAMockTrait.php +++ /dev/null @@ -1,354 +0,0 @@ -. - * - */ - -namespace Friendica\Test\Util; - -use Friendica\Database\DBA; -use Mockery\MockInterface; - -class DBAStub -{ - public static $connected = true; -} - -/** - * Trait to mock the DBA connection status - */ -trait DBAMockTrait -{ - /** - * @var MockInterface The mocking interface of Friendica\Database\DBA - */ - private $dbaMock; - - private function checkMock() - { - if (!isset($this->dbaMock)) { - $this->dbaMock = \Mockery::namedMock(DBA::class, DBAStub::class); - } - } - - /** - * Mocking DBA::connect() - * - * @param bool $return True, if the connect was successful, otherwise false - * @param null|int $times How often the method will get used - */ - public function mockConnect($return = true, $times = null) - { - $this->checkMock(); - - $this->dbaMock - ->shouldReceive('connect') - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::connected() - * - * @param bool $return True, if the DB is connected, otherwise false - * @param null|int $times How often the method will get used - */ - public function mockConnected($return = true, $times = null) - { - $this->checkMock(); - - $this->dbaMock - ->shouldReceive('connected') - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::fetchFirst() - * - * @param string $arg The argument of fetchFirst - * @param bool $return True, if the DB is connected, otherwise false - * @param null|int $times How often the method will get used - */ - public function mockFetchFirst(string $arg, bool $return = true, int $times = null) - { - $this->checkMock(); - - $this->dbaMock - ->shouldReceive('fetchFirst') - ->with($arg) - ->times($times) - ->andReturn($return); - } - - /** - * Mocking each DBA::fetch() call of an statement - * - * @param array $stmt The result statement (array) - * @param null|int $times How often the method will get used - */ - public function mockFetchLoop($stmt = [], $times = null) - { - $this->checkMock(); - - foreach ($stmt as $item) { - $this->dbaMock - ->shouldReceive('fetch') - ->times($times) - ->andReturn($item); - } - - // The last mock call of a fetch (=> breaking the loop) - $this->dbaMock - ->shouldReceive('fetch') - ->times($times) - ->andReturn(false); - } - - /** - * Mocking DBA::close() - * - * @param array $return The return per fetch - * @param null|int $times How often the method will get used - */ - public function mockDbaClose($return = [], $times = null) - { - $this->checkMock(); - - $this->dbaMock - ->shouldReceive('close') - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::select() - * - * @param string $tableName The name of the table - * @param array $select The Select Array (Default is []) - * @param array $where The Where Array (Default is []) - * @param object $return The array to return (Default is []) - * @param null|int $times How often the method will get used - */ - public function mockSelect(string $tableName, array $select = [], array $where = [], $return = null, int $times = null) - { - $this->checkMock(); - - $this->dbaMock - ->shouldReceive('select') - ->with($tableName, $select, $where) - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::delete() - * - * @param string $tableName The name of the table - * @param array $where The Where Array (Default is []) - * @param bool $return The array to return (Default is true) - * @param null|int $times How often the method will get used - */ - public function mockDBADelete(string $tableName, array $where = [], bool $return = true, int $times = null) - { - $this->checkMock(); - - $this->dbaMock - ->shouldReceive('delete') - ->with($tableName, $where) - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::update() - * - * @param string $expTableName The name of the table - * @param array $expFields The Fields Array - * @param array $expCondition The Condition Array - * @param array $expOld_fields The Old Fieldnames (Default is []) - * @param bool $return true if the update was successful - * @param null|int $times How often the method will get used - */ - public function mockDBAUpdate(string $expTableName, array $expFields, array $expCondition, array $expOld_fields = [], bool $return = true, int $times = null) - { - $this->checkMock(); - - $closure = function ($tableName, $fields, $condition, $old_fields = []) use ($expTableName, $expFields, $expCondition, $expOld_fields) { - return - $tableName == $expTableName && - $fields == $expFields && - $condition == $expCondition && - $old_fields == $expOld_fields; - }; - - $this->dbaMock - ->shouldReceive('update') - ->withArgs($closure) - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::insert() - * - * @param string $expTableName The name of the table - * @param array $expParam The Parameters Array - * @param bool $expOnDuplUpdate Update on a duplicated entry - * @param bool $return True if the insert was successful - * @param null|int $times How often the method will get used - */ - public function mockDBAInsert(string $expTableName, array $expParam, bool $expOnDuplUpdate = false, bool $return = true, int $times = null) - { - $this->checkMock(); - - $closure = function ($tableName, $param, $on_duplicate_update = false) use ($expTableName, $expParam, $expOnDuplUpdate) { - return $tableName == $expTableName - && $param == $expParam - && $on_duplicate_update == $expOnDuplUpdate; - - }; - - $this->dbaMock - ->shouldReceive('insert') - ->withArgs($closure) - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::selectFirst() - * - * @param string $expTableName The name of the table - * @param array $expSelect The Select Array (Default is []) - * @param array $expWhere The Where Array (Default is []) - * @param array $return The array to return (Default is []) - * @param null|int $times How often the method will get used - */ - public function mockSelectFirst(string $expTableName, array $expSelect = [], array $expWhere = [], array $return = [], int $times = null) - { - $this->checkMock(); - - $closure = function ($tableName, $select = [], $where = []) use ($expTableName, $expSelect, $expWhere) { - return $tableName === $expTableName - && $select === $expSelect - && $where === $expWhere; - }; - - $this->dbaMock - ->shouldReceive('selectFirst') - ->withArgs($closure) - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::isResult() - * - * @param object $record The record to test - * @param bool $return True, if the DB is connected, otherwise false - * @param null|int $times How often the method will get used - */ - public function mockIsResult($record, $return = true, $times = null) - { - $this->checkMock(); - - $this->dbaMock - ->shouldReceive('isResult') - ->with($record) - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::isResult() - * - * @param object $record The record to test - * @param array $return The array to return - * @param null|int $times How often the method will get used - */ - public function mockToArray($record = null, $return = [], $times = null) - { - $this->checkMock(); - - $this->dbaMock - ->shouldReceive('toArray') - ->with($record) - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::p() - * - * @param string $sql The SQL statement - * @param object $return The object to return - * @param null|int $times How often the method will get used - */ - public function mockP($sql = null, $return = null, $times = null) - { - $this->checkMock(); - - if (!isset($sql)) { - $this->dbaMock - ->shouldReceive('p') - ->times($times) - ->andReturn($return); - } else { - $this->dbaMock - ->shouldReceive('p') - ->with($sql) - ->times($times) - ->andReturn($return); - } - } - - /** - * Mocking DBA::lock() - * - * @param string $table The table to lock - * @param bool $return True, if the lock is set successful - * @param null|int $times How often the method will get used - */ - public function mockDbaLock(string $table, bool $return = true, int $times = null) - { - $this->checkMock(); - - $this->dbaMock - ->shouldReceive('lock') - ->with($table) - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBA::unlock() - * - * @param bool $return True, if the lock is set successful - * @param null|int $times How often the method will get used - */ - public function mockDbaUnlock( $return = true, $times = null) - { - $this->checkMock(); - - $this->dbaMock - ->shouldReceive('unlock') - ->times($times) - ->andReturn($return); - } -} diff --git a/tests/Util/DBStructureMockTrait.php b/tests/Util/DBStructureMockTrait.php deleted file mode 100644 index 02f508fe6b..0000000000 --- a/tests/Util/DBStructureMockTrait.php +++ /dev/null @@ -1,77 +0,0 @@ -. - * - */ - -namespace Friendica\Test\Util; - -use Friendica\Database\DBStructure; -use Mockery\MockInterface; - -/** - * Trait to mock the DBStructure connection status - */ -trait DBStructureMockTrait -{ - /** - * @var MockInterface The mocking interface of Friendica\Database\DBStructure - */ - private $dbStructure; - - /** - * Mocking DBStructure::update() - * @see DBStructure::update(); - * - * @param array $args The arguments for the update call - * @param bool $return True, if the connect was successful, otherwise false - * @param null|int $times How often the method will get used - */ - public function mockUpdate(array $args = [], bool $return = true, int $times = null) - { - if (!isset($this->dbStructure)) { - $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class); - } - - $this->dbStructure - ->shouldReceive('update') - ->withArgs($args) - ->times($times) - ->andReturn($return); - } - - /** - * Mocking DBStructure::existsTable() - * - * @param string $tableName The name of the table to check - * @param bool $return True, if the connect was successful, otherwise false - * @param null|int $times How often the method will get used - */ - public function mockExistsTable(string $tableName, bool $return = true, int $times = null) - { - if (!isset($this->dbStructure)) { - $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class); - } - - $this->dbStructure - ->shouldReceive('existsTable') - ->with($tableName) - ->times($times) - ->andReturn($return); - } -} diff --git a/tests/src/App/ModeTest.php b/tests/src/App/ModeTest.php index 28393c6c26..36ca6b21d6 100644 --- a/tests/src/App/ModeTest.php +++ b/tests/src/App/ModeTest.php @@ -27,7 +27,6 @@ use Friendica\App\Module; use Friendica\Core\Config\Cache; use Friendica\Database\Database; use Friendica\Test\MockedTest; -use Friendica\Test\Util\DBAMockTrait; use Friendica\Test\Util\VFSTrait; use Friendica\Util\BasePath; use Mockery; @@ -36,7 +35,6 @@ use Mockery\MockInterface; class ModeTest extends MockedTest { use VFSTrait; - use DBAMockTrait; /** * @var BasePath|MockInterface @@ -53,14 +51,14 @@ class ModeTest extends MockedTest */ private $configCacheMock; - protected function setUp() : void + protected function setUp(): void { parent::setUp(); $this->setUpVfsDir(); - $this->basePathMock = Mockery::mock(BasePath::class); - $this->databaseMock = Mockery::mock(Database::class); + $this->basePathMock = Mockery::mock(BasePath::class); + $this->databaseMock = Mockery::mock(Database::class); $this->configCacheMock = Mockery::mock(Cache::class); } @@ -110,7 +108,7 @@ class ModeTest extends MockedTest $this->databaseMock->shouldReceive('connected')->andReturn(true)->once(); $this->databaseMock->shouldReceive('fetchFirst') - ->with('SHOW TABLES LIKE \'config\'')->andReturn(false)->once(); + ->with('SHOW TABLES LIKE \'config\'')->andReturn(false)->once(); $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock); @@ -126,9 +124,9 @@ class ModeTest extends MockedTest $this->databaseMock->shouldReceive('connected')->andReturn(true)->once(); $this->databaseMock->shouldReceive('fetchFirst') - ->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once(); + ->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once(); $this->configCacheMock->shouldReceive('get')->with('system', 'maintenance') - ->andReturn(true)->once(); + ->andReturn(true)->once(); $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock); @@ -145,12 +143,12 @@ class ModeTest extends MockedTest $this->databaseMock->shouldReceive('connected')->andReturn(true)->once(); $this->databaseMock->shouldReceive('fetchFirst') - ->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once(); + ->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once(); $this->configCacheMock->shouldReceive('get')->with('system', 'maintenance') - ->andReturn(false)->once(); + ->andReturn(false)->once(); $this->databaseMock->shouldReceive('selectFirst') - ->with('config', ['v'], ['cat' => 'system', 'k' => 'maintenance']) - ->andReturn(['v' => null])->once(); + ->with('config', ['v'], ['cat' => 'system', 'k' => 'maintenance']) + ->andReturn(['v' => null])->once(); $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock); @@ -170,12 +168,12 @@ class ModeTest extends MockedTest $this->databaseMock->shouldReceive('connected')->andReturn(true)->once(); $this->databaseMock->shouldReceive('fetchFirst') - ->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once(); + ->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once(); $this->configCacheMock->shouldReceive('get')->with('system', 'maintenance') - ->andReturn(false)->once(); + ->andReturn(false)->once(); $this->databaseMock->shouldReceive('selectFirst') - ->with('config', ['v'], ['cat' => 'system', 'k' => 'maintenance']) - ->andReturn(['v' => '0'])->once(); + ->with('config', ['v'], ['cat' => 'system', 'k' => 'maintenance']) + ->andReturn(['v' => '0'])->once(); $mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock); @@ -205,8 +203,8 @@ class ModeTest extends MockedTest */ public function testIsBackendNotIsBackend() { - $server = []; - $module = new Module(); + $server = []; + $module = new Module(); $mobileDetect = new MobileDetect(); $mode = (new Mode())->determineRunMode(true, $module, $server, $mobileDetect); @@ -219,8 +217,8 @@ class ModeTest extends MockedTest */ public function testIsBackendButIndex() { - $server = []; - $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], true); + $server = []; + $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], true); $mobileDetect = new MobileDetect(); $mode = (new Mode())->determineRunMode(false, $module, $server, $mobileDetect); @@ -233,8 +231,8 @@ class ModeTest extends MockedTest */ public function testIsNotBackend() { - $server = []; - $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); + $server = []; + $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); $mobileDetect = new MobileDetect(); $mode = (new Mode())->determineRunMode(false, $module, $server, $mobileDetect); @@ -252,7 +250,7 @@ class ModeTest extends MockedTest 'HTTP_X_REQUESTED_WITH' => 'xmlhttprequest', ]; - $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); + $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); $mobileDetect = new MobileDetect(); $mode = (new Mode())->determineRunMode(true, $module, $server, $mobileDetect); @@ -265,8 +263,8 @@ class ModeTest extends MockedTest */ public function testIsNotAjax() { - $server = []; - $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); + $server = []; + $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); $mobileDetect = new MobileDetect(); $mode = (new Mode())->determineRunMode(true, $module, $server, $mobileDetect); @@ -279,8 +277,8 @@ class ModeTest extends MockedTest */ public function testIsMobileIsTablet() { - $server = []; - $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); + $server = []; + $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); $mobileDetect = Mockery::mock(MobileDetect::class); $mobileDetect->shouldReceive('isMobile')->andReturn(true); $mobileDetect->shouldReceive('isTablet')->andReturn(true); @@ -297,8 +295,8 @@ class ModeTest extends MockedTest */ public function testIsNotMobileIsNotTablet() { - $server = []; - $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); + $server = []; + $module = new Module(Module::DEFAULT, Module::DEFAULT_CLASS, [], false); $mobileDetect = Mockery::mock(MobileDetect::class); $mobileDetect->shouldReceive('isMobile')->andReturn(false); $mobileDetect->shouldReceive('isTablet')->andReturn(false); diff --git a/tests/src/Console/AutomaticInstallationConsoleTest.php b/tests/src/Console/AutomaticInstallationConsoleTest.php index fcb3289b8a..01a57b57e9 100644 --- a/tests/src/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Console/AutomaticInstallationConsoleTest.php @@ -30,8 +30,6 @@ use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Database\Database; use Friendica\DI; -use Friendica\Test\Util\DBAMockTrait; -use Friendica\Test\Util\DBStructureMockTrait; use Friendica\Test\Util\RendererMockTrait; use Friendica\Test\Util\VFSTrait; use Friendica\Util\Logger\VoidLogger; @@ -43,8 +41,6 @@ use org\bovigo\vfs\vfsStreamFile; class AutomaticInstallationConsoleTest extends ConsoleTest { use VFSTrait; - use DBAMockTrait; - use DBStructureMockTrait; use RendererMockTrait; /** diff --git a/tests/src/Model/UserTest.php b/tests/src/Model/UserTest.php index 8f8b2c3d7d..a382806fb7 100644 --- a/tests/src/Model/UserTest.php +++ b/tests/src/Model/UserTest.php @@ -21,54 +21,58 @@ namespace Friendica\Test\src\Model; +use Dice\Dice; +use Friendica\Database\Database; +use Friendica\DI; use Friendica\Model\User; use Friendica\Test\MockedTest; -use Friendica\Test\Util\DBAMockTrait; +use Mockery\MockInterface; -/** - * @runTestsInSeparateProcesses - * @preserveGlobalState disabled - */ class UserTest extends MockedTest { - use DBAMockTrait; - private $parent; private $child; private $manage; + /** @var Database|MockInterface */ + private $dbMock; + protected function setUp(): void { parent::setUp(); + $this->dbMock = \Mockery::mock(Database::class); + + $diceMock = \Mockery::mock(Dice::class)->makePartial(); + /** @var Dice|MockInterface $diceMock */ + $diceMock = $diceMock->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); + $diceMock->shouldReceive('create')->withArgs([Database::class])->andReturn($this->dbMock); + DI::init($diceMock); + $this->parent = [ - 'uid' => 1, - 'username' => 'maxmuster', - 'nickname' => 'Max Muster' + 'uid' => 1, + 'username' => 'maxmuster', + 'nickname' => 'Max Muster' ]; $this->child = [ - 'uid' => 2, - 'username' => 'johndoe', - 'nickname' => 'John Doe' + 'uid' => 2, + 'username' => 'johndoe', + 'nickname' => 'John Doe' ]; $this->manage = [ - 'uid' => 3, - 'username' => 'janesmith', - 'nickname' => 'Jane Smith' + 'uid' => 3, + 'username' => 'janesmith', + 'nickname' => 'Jane Smith' ]; } public function testIdentitiesEmpty() { - $this->mockSelectFirst('user', - ['uid', 'nickname', 'username', 'parent-uid'], - ['uid' => $this->parent['uid']], - $this->parent, - 1 - ); - $this->mockIsResult($this->parent, false, 1); + $this->dbMock->shouldReceive('selectFirst')->with('user', + ['uid', 'nickname', 'username', 'parent-uid'],['uid' => $this->parent['uid']], [])->andReturn($this->parent)->once(); + $this->dbMock->shouldReceive('isResult')->with($this->parent)->andReturn(false)->once(); $record = User::identities($this->parent['uid']); @@ -77,35 +81,28 @@ class UserTest extends MockedTest public function testIdentitiesAsParent() { - $parentSelect = $this->parent; + $parentSelect = $this->parent; $parentSelect['parent-uid'] = 0; // Select the user itself (=parent) - $this->mockSelectFirst('user', - ['uid', 'nickname', 'username', 'parent-uid'], - ['uid' => $this->parent['uid']], - $parentSelect, - 1 - ); - $this->mockIsResult($parentSelect, true, 1); + $this->dbMock->shouldReceive('selectFirst')->with('user', + ['uid', 'nickname', 'username', 'parent-uid'],['uid' => $this->parent['uid']], [])->andReturn($parentSelect)->once(); + $this->dbMock->shouldReceive('isResult')->with($parentSelect)->andReturn(true)->once(); // Select one child - $this->mockSelect('user', + $this->dbMock->shouldReceive('select')->with('user', ['uid', 'username', 'nickname'], [ - 'parent-uid' => $this->parent['uid'], + 'parent-uid' => $this->parent['uid'], 'account_removed' => false - ], - 'objectReturn', - 1 - ); - $this->mockIsResult('objectReturn', true, 1); - $this->mockToArray('objectReturn', [ $this->child ], 1); + ], [])->andReturn('objectReturn')->once(); + $this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once(); + $this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->child])->once(); // Select the manage - $this->mockP(null, 'objectTwo', 1); - $this->mockIsResult('objectTwo', true, 1); - $this->mockToArray('objectTwo', [ $this->manage ], 1); + $this->dbMock->shouldReceive('p')->withAnyArgs()->andReturn('objectTwo')->once(); + $this->dbMock->shouldReceive('isResult')->with('objectTwo')->andReturn(true)->once(); + $this->dbMock->shouldReceive('toArray')->with('objectTwo', true, 0)->andReturn([$this->manage])->once(); $record = User::identities($this->parent['uid']); @@ -118,47 +115,37 @@ class UserTest extends MockedTest public function testIdentitiesAsChild() { - $childSelect = $this->child; + $childSelect = $this->child; $childSelect['parent-uid'] = $this->parent['uid']; // Select the user itself (=child) - $this->mockSelectFirst('user', - ['uid', 'nickname', 'username', 'parent-uid'], - ['uid' => $this->child['uid']], - $childSelect, - 1 - ); - $this->mockIsResult($childSelect, true, 1); + $this->dbMock->shouldReceive('selectFirst')->with('user', + ['uid', 'nickname', 'username', 'parent-uid'],['uid' => $this->child['uid']], [])->andReturn($childSelect)->once(); + $this->dbMock->shouldReceive('isResult')->with($childSelect)->andReturn(true)->once(); // Select the parent - $this->mockSelect('user', + $this->dbMock->shouldReceive('select')->with('user', ['uid', 'username', 'nickname'], [ - 'uid' => $this->parent['uid'], + 'uid' => $this->parent['uid'], 'account_removed' => false - ], - 'objectReturn', - 1 - ); - $this->mockIsResult('objectReturn', true, 1); - $this->mockToArray('objectReturn', [ $this->parent ], 1); + ], [])->andReturn('objectReturn')->once(); + $this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once(); + $this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->parent])->once(); // Select the childs (user & manage) - $this->mockSelect('user', + $this->dbMock->shouldReceive('select')->with('user', ['uid', 'username', 'nickname'], [ - 'parent-uid' => $this->parent['uid'], + 'parent-uid' => $this->parent['uid'], 'account_removed' => false - ], - 'objectReturn', - 1 - ); - $this->mockIsResult('objectReturn', true, 1); - $this->mockToArray('objectReturn', [ $this->child, $this->manage ], 1); + ], [])->andReturn('objectReturn')->once(); + $this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once(); + $this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->child, $this->manage])->once(); // Select the manage - $this->mockP(null, 'objectTwo', 1); - $this->mockIsResult('objectTwo', false, 1); + $this->dbMock->shouldReceive('p')->withAnyArgs()->andReturn('objectTwo')->once(); + $this->dbMock->shouldReceive('isResult')->with('objectTwo')->andReturn(false)->once(); $record = User::identities($this->child['uid']);