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