Test enhancements
This commit is contained in:
parent
70f9d3c596
commit
83ead5ec48
12 changed files with 154 additions and 71 deletions
|
@ -27,11 +27,6 @@ trait AppMockTrait
|
|||
*/
|
||||
public function mockApp($root)
|
||||
{
|
||||
// simply returning the input when using L10n::t()
|
||||
$l10nMock = \Mockery::mock('alias:Friendica\Core\L10n');
|
||||
$l10nMock->shouldReceive('t')
|
||||
->andReturnUsing(function ($arg) { return $arg; });
|
||||
|
||||
$this->mockConfigGet('system', 'theme', 'testtheme');
|
||||
|
||||
// Mocking App and most used functions
|
||||
|
|
|
@ -49,4 +49,24 @@ trait DBAMockTrait
|
|||
->times($times)
|
||||
->andReturn($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocking DBA::fetchFirst()
|
||||
*
|
||||
* @param string $arg The argument of fetchFirst
|
||||
* @param bool $return True, if the DB is connected, otherwise false
|
||||
* @param null|int $times How often the method will get used
|
||||
*/
|
||||
public function mockFetchFirst($arg, $return = true, $times = null)
|
||||
{
|
||||
if (!isset($this->dbaMock)) {
|
||||
$this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
|
||||
}
|
||||
|
||||
$this->dbaMock
|
||||
->shouldReceive('fetchFirst')
|
||||
->with($arg)
|
||||
->times($times)
|
||||
->andReturn($return);
|
||||
}
|
||||
}
|
||||
|
|
45
tests/Util/L10nMockTrait.php
Normal file
45
tests/Util/L10nMockTrait.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Util;
|
||||
|
||||
use Mockery\MockInterface;
|
||||
|
||||
trait L10nMockTrait
|
||||
{
|
||||
/**
|
||||
* @var MockInterface The interface for L10n mocks
|
||||
*/
|
||||
private $l10nMock;
|
||||
|
||||
/**
|
||||
* Mocking the 'L10n::t()' method
|
||||
*
|
||||
* @param null|string $input Either an input (string) or null for EVERY input is possible
|
||||
* @param null|int $times How often will it get called
|
||||
* @param null|string $return Either an return (string) or null for return the input
|
||||
*/
|
||||
public function mockL10nT($input = null, $times = null, $return = null)
|
||||
{
|
||||
if (!isset($this->l10nMock)) {
|
||||
$this->l10nMock = \Mockery::mock('alias:Friendica\Core\L10n');
|
||||
}
|
||||
|
||||
$with = isset($input) ? $input : \Mockery::any();
|
||||
|
||||
$return = isset($return) ? $return : $with;
|
||||
|
||||
if ($return instanceof \Mockery\Matcher\Any) {
|
||||
$this->l10nMock
|
||||
->shouldReceive('t')
|
||||
->with($with)
|
||||
->times($times)
|
||||
->andReturnUsing(function($arg) { return $arg; });
|
||||
} else {
|
||||
$this->l10nMock
|
||||
->shouldReceive('t')
|
||||
->with($with)
|
||||
->times($times)
|
||||
->andReturn($return);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue