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