]> git.mxchange.org Git - friendica.git/blob - tests/Util/RendererMockTrait.php
403f25f14dcf5f195f1c5fab200b22407239c2fc
[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 bool                $overwriteURL if the URL should get overwritten
41          * @param string              $return       the return value of the mock
42          * @param null|int            $times        How often the method will get used
43          */
44         public function mockReplaceMacros($template, $args = null, $overwriteURL = true, $return = '', $times = null)
45         {
46                 if (!isset($this->rendererMock)) {
47                         $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
48                 }
49
50                 if (!isset($args)) {
51                         $args = [];
52                 }
53
54                 if ($overwriteURL) {
55                         $this->rendererMock
56                                 ->shouldReceive('replaceMacros')
57                                 ->with($template, $args)
58                                 ->times($times)
59                                 ->andReturn($return);
60                 } else {
61                         $this->rendererMock
62                                 ->shouldReceive('replaceMacros')
63                                 ->with($template, $args, false)
64                                 ->times($times)
65                                 ->andReturn($return);
66                 }
67         }
68 }