]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Config/JitPConfigurationTest.php
Adapt test for mockery assertion
[friendica.git] / tests / src / Core / Config / JitPConfigurationTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core\Config;
4
5 use Friendica\Core\Config\JitPConfiguration;
6
7 class JitPConfigurationTest extends PConfigurationTest
8 {
9         public function getInstance()
10         {
11                 return new JitPConfiguration($this->configCache, $this->configModel);
12         }
13
14         /**
15          * @dataProvider dataConfigLoad
16          */
17         public function testLoad(int $uid, array $data, array $possibleCats, array $load)
18         {
19                 $this->configModel->shouldReceive('isConnected')
20                                   ->andReturn(true)
21                                   ->times(count($load));
22
23                 foreach ($load as $loadCat) {
24                         $this->configModel->shouldReceive('load')
25                                           ->with($uid, $loadCat)
26                                           ->andReturn([$loadCat => $data[$loadCat]])
27                                           ->once();
28                 }
29
30                 parent::testLoad($uid, $data, $possibleCats, $load);
31         }
32
33         /**
34          * @dataProvider dataDoubleLoad
35          */
36         public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
37         {
38                 $this->configModel->shouldReceive('isConnected')
39                                   ->andReturn(true)
40                                   ->times(count($data1) + count($data2));
41
42                 foreach ($data1 as $cat => $data) {
43                         $this->configModel->shouldReceive('load')
44                                           ->with($uid, $cat)
45                                           ->andReturn([$cat => $data])
46                                           ->once();
47                 }
48
49
50                 foreach ($data2 as $cat => $data) {
51                         $this->configModel->shouldReceive('load')
52                                           ->with($uid, $cat)
53                                           ->andReturn([$cat => $data])
54                                           ->once();
55                 }
56
57                 parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
58
59                 // Assert the expected categories
60                 foreach ($data2 as $cat => $data) {
61                         $this->assertConfig($uid, $cat, $expect[$cat]);
62                 }
63         }
64
65         /**
66          * @dataProvider dataTests
67          */
68         public function testSetGetWithoutDB(int $uid, $data)
69         {
70                 $this->configModel->shouldReceive('isConnected')
71                                   ->andReturn(false)
72                                   ->times(2);
73
74                 parent::testSetGetWithoutDB($uid, $data);
75         }
76
77         /**
78          * @dataProvider dataTests
79          */
80         public function testSetGetWithDB(int $uid, $data)
81         {
82                 $this->configModel->shouldReceive('isConnected')
83                                   ->andReturn(true)
84                                   ->times(2);
85
86                 parent::testSetGetWithDB($uid, $data);
87         }
88
89         /**
90          * @dataProvider dataTests
91          */
92         public function testGetWithRefresh(int $uid, $data)
93         {
94                 $this->configModel->shouldReceive('isConnected')
95                                   ->andReturn(true)
96                                   ->times(3);
97
98                 // mocking one get without result
99                 $this->configModel->shouldReceive('get')
100                                   ->with($uid, 'test', 'it')
101                                   ->andReturn(null)
102                                   ->once();
103
104                 // mocking the data get
105                 $this->configModel->shouldReceive('get')
106                                   ->with($uid, 'test', 'it')
107                                   ->andReturn($data)
108                                   ->once();
109
110                 // mocking second get
111                 $this->configModel->shouldReceive('get')
112                                   ->with($uid, 'test', 'not')
113                                   ->andReturn(null)
114                                   ->once();
115
116                 parent::testGetWithRefresh($uid, $data);
117         }
118
119         /**
120          * @dataProvider dataTests
121          */
122         public function testDeleteWithoutDB(int $uid, $data)
123         {
124                 $this->configModel->shouldReceive('isConnected')
125                                   ->andReturn(false)
126                                   ->times(3);
127
128                 parent::testDeleteWithoutDB($uid, $data);
129         }
130
131         public function testDeleteWithDB()
132         {
133                 $this->configModel->shouldReceive('isConnected')
134                                   ->andReturn(true)
135                                   ->times(5);
136
137                 // mocking one get without result
138                 $this->configModel->shouldReceive('get')
139                                   ->with(42, 'test', 'it')
140                                   ->andReturn(null)
141                                   ->once();
142
143                 parent::testDeleteWithDB();
144         }
145 }