2018-10-31 05:16:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Test\Util;
|
|
|
|
|
2018-10-31 05:24:07 -04:00
|
|
|
use Mockery\MockInterface;
|
|
|
|
|
2018-10-31 05:16:15 -04:00
|
|
|
/**
|
|
|
|
* Trait to mock the DBA connection status
|
|
|
|
*/
|
|
|
|
trait DBAMockTrait
|
|
|
|
{
|
2018-10-31 05:24:07 -04:00
|
|
|
/**
|
|
|
|
* @var MockInterface The mocking interface of Friendica\Database\DBA
|
|
|
|
*/
|
2018-10-31 05:16:15 -04:00
|
|
|
private $dbaMock;
|
|
|
|
|
2018-10-31 05:24:07 -04:00
|
|
|
/**
|
|
|
|
* Mocking DBA::connect()
|
|
|
|
*
|
|
|
|
* @param bool $return True, if the connect was successful, otherwise false
|
|
|
|
* @param null|int $times How often the method will get used
|
|
|
|
*/
|
2018-10-31 05:16:15 -04:00
|
|
|
public function mockConnect($return = true, $times = null)
|
|
|
|
{
|
|
|
|
if (!isset($this->dbaMock)) {
|
|
|
|
$this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->dbaMock
|
|
|
|
->shouldReceive('connect')
|
|
|
|
->times($times)
|
|
|
|
->andReturn($return);
|
|
|
|
}
|
|
|
|
|
2018-10-31 05:24:07 -04:00
|
|
|
/**
|
|
|
|
* Mocking DBA::connected()
|
|
|
|
*
|
|
|
|
* @param bool $return True, if the DB is connected, otherwise false
|
|
|
|
* @param null|int $times How often the method will get used
|
|
|
|
*/
|
2018-10-31 05:16:15 -04:00
|
|
|
public function mockConnected($return = true, $times = null)
|
|
|
|
{
|
|
|
|
if (!isset($this->dbaMock)) {
|
|
|
|
$this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->dbaMock
|
|
|
|
->shouldReceive('connected')
|
|
|
|
->times($times)
|
|
|
|
->andReturn($return);
|
|
|
|
}
|
|
|
|
}
|