Merge pull request #7379 from nupplaphil/task/refactor_l10n_for_test
Refactor L10n for testing
This commit is contained in:
commit
0b97b32a59
13 changed files with 596 additions and 450 deletions
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Util;
|
||||
|
||||
use Friendica\Core\L10n;
|
||||
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:' . L10n::class);
|
||||
}
|
||||
|
||||
$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