Update copyright
[friendica.git/.git] / tests / Util / RendererMockTrait.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\Util;
23
24 use Friendica\Core\Renderer;
25 use Mockery\MockInterface;
26
27 trait RendererMockTrait
28 {
29         /**
30          * @var MockInterface The Interface for mocking a renderer
31          */
32         private $rendererMock;
33
34         /**
35          * Mocking the method 'Renderer::getMarkupTemplate()'
36          *
37          * @param string   $templateName The name of the template which should get
38          * @param string   $return       the return value of the mock (should be defined to have it later for followUp use)
39          * @param null|int $times        How often the method will get used
40          */
41         public function mockGetMarkupTemplate(string $templateName, string $return = '', int $times = null)
42         {
43                 if (!isset($this->rendererMock)) {
44                         $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
45                 }
46
47                 $this->rendererMock
48                         ->shouldReceive('getMarkupTemplate')
49                         ->with($templateName)
50                         ->times($times)
51                         ->andReturn($return);
52         }
53
54         /**
55          * Mocking the method 'Renderer::replaceMacros()'
56          *
57          * @param string              $template The template to use (normally, it is the mock result of 'mockGetMarkupTemplate()'
58          * @param array|\Closure|null $args     The arguments to pass to the macro
59          * @param string              $return   the return value of the mock
60          * @param null|int            $times    How often the method will get used
61          */
62         public function mockReplaceMacros(string $template, $args = null, string $return = '', int $times = null)
63         {
64                 if (!isset($this->rendererMock)) {
65                         $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
66                 }
67
68                 if (!isset($args)) {
69                         $args = [];
70                 }
71
72                 $this->rendererMock
73                         ->shouldReceive('replaceMacros')
74                         ->with($template, $args)
75                         ->times($times)
76                         ->andReturn($return);
77         }
78 }