]> git.mxchange.org Git - friendica.git/blob - tests/Util/DBStructureMockTrait.php
Add ContentType Injection for HTTPInputData tests
[friendica.git] / tests / Util / DBStructureMockTrait.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\Util;
23
24 use Friendica\Database\DBStructure;
25 use Mockery\MockInterface;
26
27 /**
28  * Trait to mock the DBStructure connection status
29  */
30 trait DBStructureMockTrait
31 {
32         /**
33          * @var MockInterface The mocking interface of Friendica\Database\DBStructure
34          */
35         private $dbStructure;
36
37         /**
38          * Mocking DBStructure::update()
39          * @see DBStructure::update();
40          *
41          * @param array $args The arguments for the update call
42          * @param bool $return True, if the connect was successful, otherwise false
43          * @param null|int $times How often the method will get used
44          */
45         public function mockUpdate(array $args = [], bool $return = true, int $times = null)
46         {
47                 if (!isset($this->dbStructure)) {
48                         $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class);
49                 }
50
51                 $this->dbStructure
52                         ->shouldReceive('update')
53                         ->withArgs($args)
54                         ->times($times)
55                         ->andReturn($return);
56         }
57
58         /**
59          * Mocking DBStructure::existsTable()
60          *
61          * @param string   $tableName The name of the table to check
62          * @param bool     $return    True, if the connect was successful, otherwise false
63          * @param null|int $times     How often the method will get used
64          */
65         public function mockExistsTable(string $tableName, bool $return = true, int $times = null)
66         {
67                 if (!isset($this->dbStructure)) {
68                         $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class);
69                 }
70
71                 $this->dbStructure
72                         ->shouldReceive('existsTable')
73                         ->with($tableName)
74                         ->times($times)
75                         ->andReturn($return);
76         }
77 }