]> git.mxchange.org Git - friendica.git/blob - tests/Util/RendererMockTrait.php
Merge pull request #6703 from tobiasd/2019.03-CHANGELOG
[friendica.git] / tests / Util / RendererMockTrait.php
1 <?php
2
3 namespace Friendica\Test\Util;
4
5 use Friendica\Core\Renderer;
6 use Mockery\MockInterface;
7
8 trait RendererMockTrait
9 {
10         /**
11          * @var MockInterface The Interface for mocking a renderer
12          */
13         private $rendererMock;
14
15         /**
16          * Mocking the method 'Renderer::getMarkupTemplate()'
17          *
18          * @param string $templateName The name of the template which should get
19          * @param string $return the return value of the mock (should be defined to have it later for followUp use)
20          * @param null|int $times How often the method will get used
21          */
22         public function mockGetMarkupTemplate($templateName, $return = '', $times = null)
23         {
24                 if (!isset($this->rendererMock)) {
25                         $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
26                 }
27
28                 $this->rendererMock
29                         ->shouldReceive('getMarkupTemplate')
30                         ->with($templateName)
31                         ->times($times)
32                         ->andReturn($return);
33         }
34
35         /**
36          * Mocking the method 'Renderer::replaceMacros()'
37          *
38          * @param string $template The template to use (normally, it is the mock result of 'mockGetMarkupTemplate()'
39          * @param array $args The arguments to pass to the macro
40          * @param string $return the return value of the mock
41          * @param null|int $times How often the method will get used
42          */
43         public function mockReplaceMacros($template, $args = [], $return = '', $times = null)
44         {
45                 if (!isset($this->rendererMock)) {
46                         $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
47                 }
48
49                 $this->rendererMock
50                         ->shouldReceive('replaceMacros')
51                         ->with($template, $args)
52                         ->times($times)
53                         ->andReturn($return);
54         }
55 }