]> git.mxchange.org Git - friendica.git/blob - tests/Util/RendererMockTrait.php
Merge pull request #7643 from nupplaphil/task/add_drone_ci
[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|\Closure|null $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 = null, $return = '', $times = null)
44         {
45                 if (!isset($this->rendererMock)) {
46                         $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
47                 }
48
49                 if (!isset($args)) {
50                         $args = [];
51                 }
52
53                 $this->rendererMock
54                         ->shouldReceive('replaceMacros')
55                         ->with($template, $args)
56                         ->times($times)
57                         ->andReturn($return);
58         }
59 }