|
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,9 @@ protected function setUp(): void |
45 | 48 | if (! class_exists('Encryption', false)) { |
46 | 49 | require $this->fixturesFolder . '/Encryption.php'; |
47 | 50 | } |
| 51 | + |
| 52 | + BaseConfig::$registrars = []; |
| 53 | + BaseConfig::setModules(new Modules()); // reset to clean copy of Modules |
48 | 54 | } |
49 | 55 |
|
50 | 56 | public function testBasicValues(): void |
@@ -265,32 +271,28 @@ public function testBadRegistrar(): void |
265 | 271 | $this->assertSame('bar', $config->foo); |
266 | 272 | } |
267 | 273 |
|
268 | | - public function testNotEnabled(): void |
| 274 | + public function testDiscoveryNotEnabledWillNotPopulateRegistrarsArray(): void |
269 | 275 | { |
270 | | - $modulesConfig = config('Modules'); |
271 | | - $modulesConfig->enabled = false; |
272 | | - |
273 | | - $config = new RegistrarConfig(); |
274 | | - $config::$registrars = []; |
275 | | - $expected = $config::$registrars; |
| 276 | + /** @var MockObject&Modules $modules */ |
| 277 | + $modules = $this->createMock(Modules::class); |
| 278 | + $modules->method('shouldDiscover')->with('registrars')->willReturn(false); |
276 | 279 |
|
277 | | - $method = $this->getPrivateMethodInvoker($config, 'registerProperties'); |
278 | | - $method(); |
| 280 | + RegistrarConfig::setModules($modules); |
| 281 | + $config = new RegistrarConfig(); |
279 | 282 |
|
280 | | - $this->assertSame($expected, $config::$registrars); |
| 283 | + $this->assertSame([], $config::$registrars); |
281 | 284 | } |
282 | 285 |
|
283 | | - public function testDidDiscovery(): void |
| 286 | + public function testRedoingDiscoveryWillStillSetDidDiscoveryPropertyToTrue(): void |
284 | 287 | { |
285 | | - $modulesConfig = config('Modules'); |
286 | | - $modulesConfig->enabled = true; |
| 288 | + /** @var FileLocator&MockObject $locator */ |
| 289 | + $locator = $this->createMock(FileLocator::class); |
| 290 | + $locator->method('search')->with('Config/Registrar.php')->willReturn([]); |
| 291 | + Services::injectMock('locator', $locator); |
287 | 292 |
|
288 | | - $config = new RegistrarConfig(); |
289 | | - $config::$registrars = []; |
290 | | - $this->setPrivateProperty($config, 'didDiscovery', false); |
| 293 | + $this->setPrivateProperty(RegistrarConfig::class, 'didDiscovery', false); |
291 | 294 |
|
292 | | - $method = $this->getPrivateMethodInvoker($config, 'registerProperties'); |
293 | | - $method(); |
| 295 | + $config = new RegistrarConfig(); |
294 | 296 |
|
295 | 297 | $this->assertTrue($this->getPrivateProperty($config, 'didDiscovery')); |
296 | 298 | } |
|
0 commit comments