]> git.mxchange.org Git - friendica.git/blob - tests/Util/L10nMockTrait.php
updated the credits
[friendica.git] / tests / Util / L10nMockTrait.php
1 <?php
2
3 namespace Friendica\Test\Util;
4
5 use Mockery\MockInterface;
6
7 trait L10nMockTrait
8 {
9         /**
10          * @var MockInterface The interface for L10n mocks
11          */
12         private $l10nMock;
13
14         /**
15          * Mocking the 'L10n::t()' method
16          *
17          * @param null|string $input Either an input (string) or null for EVERY input is possible
18          * @param null|int $times How often will it get called
19          * @param null|string $return Either an return (string) or null for return the input
20          */
21         public function mockL10nT($input = null, $times = null, $return = null)
22         {
23                 if (!isset($this->l10nMock)) {
24                         $this->l10nMock = \Mockery::mock('alias:Friendica\Core\L10n');
25                 }
26
27                 $with = isset($input) ? $input : \Mockery::any();
28
29                 $return = isset($return) ? $return : $with;
30
31                 if ($return instanceof \Mockery\Matcher\Any) {
32                         $this->l10nMock
33                                 ->shouldReceive('t')
34                                 ->with($with)
35                                 ->times($times)
36                                 ->andReturnUsing(function($arg) { return $arg; });
37                 } else {
38                         $this->l10nMock
39                                 ->shouldReceive('t')
40                                 ->with($with)
41                                 ->times($times)
42                                 ->andReturn($return);
43                 }
44         }
45 }