]> git.mxchange.org Git - friendica.git/blob - tests/Util/ConfigMockTrait.php
Bugfixing & Enhancement
[friendica.git] / tests / Util / ConfigMockTrait.php
1 <?php
2
3 namespace Friendica\Test\Util;
4
5 /**
6  * Trait to Mock Config settings
7  */
8 trait ConfigMockTrait
9 {
10         private $configMock;
11
12         /**
13          * Mocking a config setting
14          *
15          * @param string $family The family of the config double
16          * @param string $key The key of the config double
17          * @param mixed $value The value of the config double
18          * @param null|int $times How often the Config will get used
19          */
20         public function mockConfigGet($family, $key, $value, $times = null)
21         {
22                 if (!isset($this->configMock)) {
23                         $this->configMock = \Mockery::mock('alias:Friendica\Core\Config');
24                 }
25
26                 $this->configMock
27                         ->shouldReceive('get')
28                         ->times($times)
29                         ->with($family, $key)
30                         ->andReturn($value);
31         }
32
33         /**
34          * Mocking setting a new config entry
35          *
36          * @param string $family The family of the config double
37          * @param string $key The key of the config double
38          * @param mixed $value The value of the config double
39          * @param null|int $times How often the Config will get used
40          * @param bool $return Return value of the set (default is true)
41          */
42         public function mockConfigSet($family, $key, $value, $times = null, $return = true)
43         {
44                 if (!isset($this->configMock)) {
45                         $this->configMock = \Mockery::mock('alias:Friendica\Core\Config');
46                 }
47
48                 $this->mockConfigGet($family, $key, false, 1);
49                 if ($return) {
50                         $this->mockConfigGet($family, $key, $value, 1);
51                 }
52
53                 $this->configMock
54                         ->shouldReceive('set')
55                         ->times($times)
56                         ->with($family, $key, $value)
57                         ->andReturn($return);
58         }
59 }