]> git.mxchange.org Git - friendica.git/blob - tests/Util/DBAMockTrait.php
Test enhancements
[friendica.git] / tests / Util / DBAMockTrait.php
1 <?php
2
3 namespace Friendica\Test\Util;
4
5 use Mockery\MockInterface;
6
7 /**
8  * Trait to mock the DBA connection status
9  */
10 trait DBAMockTrait
11 {
12         /**
13          * @var MockInterface The mocking interface of Friendica\Database\DBA
14          */
15         private $dbaMock;
16
17         /**
18          * Mocking DBA::connect()
19          *
20          * @param bool $return True, if the connect was successful, otherwise false
21          * @param null|int $times How often the method will get used
22          */
23         public function mockConnect($return = true, $times = null)
24         {
25                 if (!isset($this->dbaMock)) {
26                         $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
27                 }
28
29                 $this->dbaMock
30                         ->shouldReceive('connect')
31                         ->times($times)
32                         ->andReturn($return);
33         }
34
35         /**
36          * Mocking DBA::connected()
37          *
38          * @param bool $return True, if the DB is connected, otherwise false
39          * @param null|int $times How often the method will get used
40          */
41         public function mockConnected($return = true, $times = null)
42         {
43                 if (!isset($this->dbaMock)) {
44                         $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
45                 }
46
47                 $this->dbaMock
48                         ->shouldReceive('connected')
49                         ->times($times)
50                         ->andReturn($return);
51         }
52
53         /**
54          * Mocking DBA::fetchFirst()
55          *
56          * @param string $arg The argument of fetchFirst
57          * @param bool $return True, if the DB is connected, otherwise false
58          * @param null|int $times How often the method will get used
59          */
60         public function mockFetchFirst($arg, $return = true, $times = null)
61         {
62                 if (!isset($this->dbaMock)) {
63                         $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
64                 }
65
66                 $this->dbaMock
67                         ->shouldReceive('fetchFirst')
68                         ->with($arg)
69                         ->times($times)
70                         ->andReturn($return);
71         }
72 }