friendica/tests/Util/L10nMockTrait.php

47 lines
1.0 KiB
PHP
Raw Normal View History

2018-11-01 13:44:47 +01:00
<?php
namespace Friendica\Test\Util;
2019-02-24 13:40:54 +01:00
use Friendica\Core\L10n;
2018-11-01 13:44:47 +01:00
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)) {
2019-02-24 13:40:54 +01:00
$this->l10nMock = \Mockery::mock('alias:' . L10n::class);
2018-11-01 13:44:47 +01:00
}
$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);
}
}
}