|
11 | 11 |
|
12 | 12 | namespace CodeIgniter\Config; |
13 | 13 |
|
| 14 | +use CodeIgniter\Autoloader\FileLocator; |
14 | 15 | use CodeIgniter\Test\CIUnitTestCase; |
| 16 | +use Config\Modules; |
15 | 17 | use Encryption; |
| 18 | +use PHPUnit\Framework\MockObject\MockObject; |
16 | 19 | use RegistrarConfig; |
17 | 20 | use RuntimeException; |
18 | 21 | use SimpleConfig; |
@@ -45,6 +48,8 @@ protected function setUp(): void |
45 | 48 | if (! class_exists('Encryption', false)) { |
46 | 49 | require $this->fixturesFolder . '/Encryption.php'; |
47 | 50 | } |
| 51 | + |
| 52 | + BaseConfig::$registrars = []; |
48 | 53 | } |
49 | 54 |
|
50 | 55 | public function testBasicValues(): void |
@@ -265,32 +270,27 @@ public function testBadRegistrar(): void |
265 | 270 | $this->assertSame('bar', $config->foo); |
266 | 271 | } |
267 | 272 |
|
268 | | - public function testNotEnabled(): void |
| 273 | + public function testDiscoveryNotEnabledWillNotPopulateRegistrarsArray(): void |
269 | 274 | { |
270 | | - $modulesConfig = config('Modules'); |
271 | | - $modulesConfig->enabled = false; |
272 | | - |
273 | | - $config = new RegistrarConfig(); |
274 | | - $config::$registrars = []; |
275 | | - $expected = $config::$registrars; |
| 275 | + /** @var MockObject&Modules $modules */ |
| 276 | + $modules = $this->createMock(Modules::class); |
| 277 | + $modules->method('shouldDiscover')->with('registrars')->willReturn(false); |
276 | 278 |
|
277 | | - $method = $this->getPrivateMethodInvoker($config, 'registerProperties'); |
278 | | - $method(); |
| 279 | + $config = new RegistrarConfig($modules); |
279 | 280 |
|
280 | | - $this->assertSame($expected, $config::$registrars); |
| 281 | + $this->assertSame([], $config::$registrars); |
281 | 282 | } |
282 | 283 |
|
283 | | - public function testDidDiscovery(): void |
| 284 | + public function testRedoingDiscoveryWillStillSetDidDiscoveryPropertyToTrue(): void |
284 | 285 | { |
285 | | - $modulesConfig = config('Modules'); |
286 | | - $modulesConfig->enabled = true; |
| 286 | + /** @var FileLocator&MockObject $locator */ |
| 287 | + $locator = $this->createMock(FileLocator::class); |
| 288 | + $locator->method('search')->with('Config/Registrar.php')->willReturn([]); |
| 289 | + Services::injectMock('locator', $locator); |
287 | 290 |
|
288 | | - $config = new RegistrarConfig(); |
289 | | - $config::$registrars = []; |
| 291 | + $config = new RegistrarConfig(); |
290 | 292 | $this->setPrivateProperty($config, 'didDiscovery', false); |
291 | | - |
292 | | - $method = $this->getPrivateMethodInvoker($config, 'registerProperties'); |
293 | | - $method(); |
| 293 | + ($this->getPrivateMethodInvoker($config, 'registerProperties'))(); |
294 | 294 |
|
295 | 295 | $this->assertTrue($this->getPrivateProperty($config, 'didDiscovery')); |
296 | 296 | } |
|
0 commit comments