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