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