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