diff --git a/tests/example/cases/ProjectTest.php b/tests/example/cases/ProjectTest.php index 3a056ee..da6831e 100644 --- a/tests/example/cases/ProjectTest.php +++ b/tests/example/cases/ProjectTest.php @@ -26,11 +26,23 @@ public function executeProject(): void fwrite(STDOUT, print_r(app()->resolve(Logger::class)->allLogs(), true)); } + protected function checkLateModule(bool $expectToBeThere = false): void + { + if (!$expectToBeThere) { + static::assertTrue(app()->status()->isBooted()); + static::assertNull(app()->resolve('dummy-test')); + return; + } + static::assertNotNull(app()->resolve('dummy-test')); + static::assertEquals(app()->resolve('dummy-test')->text(), 'Hello World'); + } + /** * @return void */ protected function onBeforePlugins(): void { + $this->checkLateModule(); } /** @@ -38,6 +50,7 @@ protected function onBeforePlugins(): void */ protected function onAfterPlugins(): void { + $this->checkLateModule(); } /** @@ -45,6 +58,7 @@ protected function onAfterPlugins(): void */ protected function onAfterTheme(): void { + $this->checkLateModule(); } /** @@ -61,6 +75,8 @@ protected function onAfterInit(): void static::assertTrue($logger->hasLog("{$pre} 'Lorem Ipsum'")); static::assertTrue($logger->hasLog("{$pre} 'Dolor Sit Amet'")); static::assertFalse($logger->hasLog("{$pre} '[From Plugin 2] Plugin Two is Good For You'")); + + $this->checkLateModule(true); } /** diff --git a/tests/example/sources/libraries/modularity-lib/src/LateModule.php b/tests/example/sources/libraries/modularity-lib/src/LateModule.php index e1c0c3d..f2539f9 100644 --- a/tests/example/sources/libraries/modularity-lib/src/LateModule.php +++ b/tests/example/sources/libraries/modularity-lib/src/LateModule.php @@ -5,6 +5,7 @@ namespace Inpsyde\App\Tests\Project\ModularityLib; use Inpsyde\App\Tests\Project\ModularityPlugin3\Calc; +use Inpsyde\Modularity\Module\ServiceModule; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -28,4 +29,22 @@ static function () use ($container): void { return parent::run($container); } + + public function services(): array + { + return array_merge( + parent::services(), + [ + // phpcs:ignore Inpsyde.CodeQuality.ReturnTypeDeclaration.NoReturnType + 'dummy-test' => static function () { + return new class { + public function text(): string + { + return 'Hello World'; + } + }; + }, + ] + ); + } } diff --git a/tests/unit/AppTest.php b/tests/unit/AppTest.php index cfb412f..1335d1f 100644 --- a/tests/unit/AppTest.php +++ b/tests/unit/AppTest.php @@ -5,6 +5,7 @@ namespace Inpsyde\App\Tests; use Inpsyde\App\App; +use Inpsyde\App\AppStatus; use Inpsyde\App\CompositeContainer; use Inpsyde\Modularity\Module\ServiceModule; use Inpsyde\Modularity\Package; @@ -25,6 +26,8 @@ class AppTest extends TestCase private $appHandleModularityBoot; /** @var \ReflectionMethod */ private $appSyncModularityStatus; + /** @var \ReflectionClass */ + private $appStatusReflection; protected function setUp(): void { @@ -41,6 +44,9 @@ protected function setUp(): void $this->appBootQueueProp->setAccessible(true); $this->appHandleModularityBoot = $reflectedApp->getMethod('handleModularityBoot'); $this->appSyncModularityStatus = $reflectedApp->getMethod('syncModularityStatus'); + + $this->appStatusReflection = new \ReflectionClass(AppStatus::class); + parent::setUp(); } @@ -112,6 +118,11 @@ public function testAddEarlyModule() static::assertInstanceOf(\ArrayObject::class, $app->resolve($moduleServiceId)); } + /** + * + * @return void + * @throws \ReflectionException + */ public function testAddModule() { $context = WpContext::new()->force(WpContext::CORE); @@ -123,8 +134,16 @@ public function testAddModule() $app->addModule($module); // We expect the service is not resolvable if the App Container is not booted static::assertEquals(null, $app->resolve($moduleServiceId)); + + // we have to force the internal status of the AppStatus + // we need $lastRun to be true when calling isThemeStep inside boot + $appStatusInternalStatusProp = $this->appStatusReflection->getProperty('status'); + $appStatusInternalStatusProp->setValue( + $this->appStatusProp->getValue($app), + AppStatus::REGISTERING_THEMES + ); + $app->boot(); - // TODO: check how addModule was meant to work static::assertInstanceOf(\ArrayObject::class, $app->resolve($moduleServiceId)); }