]> git.mxchange.org Git - friendica.git/blob - tests/Util/DBStructureMockTrait.php
Merge pull request #6061 from nupplaphil/autoinstall_test_fix
[friendica.git] / tests / Util / DBStructureMockTrait.php
1 <?php
2
3 namespace Friendica\Test\Util;
4
5 use Mockery\MockInterface;
6
7 /**
8  * Trait to mock the DBStructure connection status
9  */
10 trait DBStructureMockTrait
11 {
12         /**
13          * @var MockInterface The mocking interface of Friendica\Database\DBStructure
14          */
15         private $dbStructure;
16
17         /**
18          * Mocking DBStructure::update()
19          *
20          * @param array $args The arguments for the update call
21          * @param bool $return True, if the connect was successful, otherwise false
22          * @param null|int $times How often the method will get used
23          */
24         public function mockUpdate($args = [], $return = true, $times = null)
25         {
26                 if (!isset($this->dbStructure)) {
27                         $this->dbStructure = \Mockery::mock('alias:Friendica\Database\DBStructure');
28                 }
29
30                 $this->dbStructure
31                         ->shouldReceive('update')
32                         ->withArgs($args)
33                         ->times($times)
34                         ->andReturn($return);
35         }
36
37         /**
38          * Mocking DBStructure::existsTable()
39          *
40          * @param string $tableName The name of the table to check
41          * @param bool $return True, if the connect was successful, otherwise false
42          * @param null|int $times How often the method will get used
43          */
44         public function mockExistsTable($tableName, $return = true, $times = null)
45         {
46                 if (!isset($this->dbStructure)) {
47                         $this->dbStructure = \Mockery::mock('alias:Friendica\Database\DBStructure');
48                 }
49
50                 $this->dbStructure
51                         ->shouldReceive('existsTable')
52                         ->with($tableName)
53                         ->times($times)
54                         ->andReturn($return);
55         }
56 }