3 namespace Friendica\Test\Util;
5 use Mockery\MockInterface;
8 * Trait to mock the DBA connection status
13 * @var MockInterface The mocking interface of Friendica\Database\DBA
18 * Mocking DBA::connect()
20 * @param bool $return True, if the connect was successful, otherwise false
21 * @param null|int $times How often the method will get used
23 public function mockConnect($return = true, $times = null)
25 if (!isset($this->dbaMock)) {
26 $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
30 ->shouldReceive('connect')
36 * Mocking DBA::connected()
38 * @param bool $return True, if the DB is connected, otherwise false
39 * @param null|int $times How often the method will get used
41 public function mockConnected($return = true, $times = null)
43 if (!isset($this->dbaMock)) {
44 $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
48 ->shouldReceive('connected')
54 * Mocking DBA::fetchFirst()
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
60 public function mockFetchFirst($arg, $return = true, $times = null)
62 if (!isset($this->dbaMock)) {
63 $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
67 ->shouldReceive('fetchFirst')
75 * Mocking DBA::select()
77 * @param string $tableName The name of the table
78 * @param array $select The Select Array (Default is [])
79 * @param array $where The Where Array (Default is [])
80 * @param object $return The array to return (Default is [])
81 * @param null|int $times How often the method will get used
83 public function mockSelect($tableName, $select = [], $where = [], $return = null, $times = null)
85 if (!isset($this->dbaMock)) {
86 $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
90 ->shouldReceive('select')
91 ->with($tableName, $select, $where)
97 * Mocking DBA::selectFirst()
99 * @param string $tableName The name of the table
100 * @param array $select The Select Array (Default is [])
101 * @param array $where The Where Array (Default is [])
102 * @param array $return The array to return (Default is [])
103 * @param null|int $times How often the method will get used
105 public function mockSelectFirst($tableName, $select = [], $where = [], $return = [], $times = null)
107 if (!isset($this->dbaMock)) {
108 $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
112 ->shouldReceive('selectFirst')
113 ->with($tableName, $select, $where)
115 ->andReturn($return);
119 * Mocking DBA::isResult()
121 * @param object $record The record to test
122 * @param bool $return True, if the DB is connected, otherwise false
123 * @param null|int $times How often the method will get used
125 public function mockIsResult($record, $return = true, $times = null)
127 if (!isset($this->dbaMock)) {
128 $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
132 ->shouldReceive('isResult')
135 ->andReturn($return);
139 * Mocking DBA::isResult()
141 * @param object $record The record to test
142 * @param array $return The array to return
143 * @param null|int $times How often the method will get used
145 public function mockToArray($record = null, $return = [], $times = null)
147 if (!isset($this->dbaMock)) {
148 $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
152 ->shouldReceive('toArray')
155 ->andReturn($return);
162 * @param string $sql The SQL statement
163 * @param object $return The object to return
164 * @param null|int $times How often the method will get used
166 public function mockP($sql = null, $return = null, $times = null)
168 if (!isset($this->dbaMock)) {
169 $this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
176 ->andReturn($return);
182 ->andReturn($return);