diff --git a/bin/composer-post-install-script.php b/bin/composer-post-install-script.php index 79ec95a..f8740d5 100644 --- a/bin/composer-post-install-script.php +++ b/bin/composer-post-install-script.php @@ -2,29 +2,51 @@ declare(strict_types=1); +const ENVIRONMENT_DEVELOPMENT = 'development'; +const ENVIRONMENT_PRODUCTION = 'production'; + // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols /** - * @param array{source: string, destination: string} $file + * @param array{source: string, destination: string, environment: array} $file */ function copyFile(array $file): void { + if (! in_array(getEnvironment(), $file['environment'])) { + echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL; + return; + } + if (is_readable($file['destination'])) { - echo "File {$file['destination']} already exists." . PHP_EOL; + echo "File {$file['destination']} already exists. Skipping..." . PHP_EOL; + return; + } + + if (! copy($file['source'], $file['destination'])) { + echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL; } else { - if (! copy($file['source'], $file['destination'])) { - echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL; - } else { - echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL; - } + echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL; } } +function getEnvironment(): string +{ + return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION; +} + $files = [ [ 'source' => 'config/autoload/local.php.dist', 'destination' => 'config/autoload/local.php', + 'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION], + ], + [ + 'source' => 'config/autoload/local.test.php.dist', + 'destination' => 'config/autoload/local.test.php', + 'environment' => [ENVIRONMENT_DEVELOPMENT], ], ]; +echo "Using environment setting: " . getEnvironment() . PHP_EOL; + array_walk($files, 'copyFile'); diff --git a/config/autoload/local.test.php.dist b/config/autoload/local.test.php.dist index 8f9543a..d0f65d8 100644 --- a/config/autoload/local.test.php.dist +++ b/config/autoload/local.test.php.dist @@ -4,7 +4,7 @@ declare(strict_types=1); use LightTest\Common\TestMode; -if (! TestMode::class::isEnabled()) { +if (! TestMode::isEnabled()) { return []; } diff --git a/src/App/src/ConfigProvider.php b/src/App/src/ConfigProvider.php index c7157af..8798e27 100644 --- a/src/App/src/ConfigProvider.php +++ b/src/App/src/ConfigProvider.php @@ -31,6 +31,7 @@ * @phpstan-type ConfigType array{ * dependencies: DependenciesType, * doctrine: DoctrineConfigType, + * templates: TemplatesType, * resultCacheLifetime: int, * } * @phpstan-type DoctrineConfigType array{ @@ -84,6 +85,9 @@ * factories: array, * aliases: array, * } + * @phpstan-type TemplatesType array{ + * paths: non-empty-array, + * } **/ class ConfigProvider { @@ -127,15 +131,7 @@ public function getDependencies(): array } /** - * @return array{ - * paths: array{ - * app: array{literal-string&non-falsy-string}, - * error: array{literal-string&non-falsy-string}, - * jsonld: array{literal-string&non-falsy-string}, - * layout: array{literal-string&non-falsy-string}, - * partial: array{literal-string&non-falsy-string}, - * } - * } + * @return TemplatesType */ public function getTemplates(): array { diff --git a/src/App/templates/app/index.html.twig b/src/App/templates/app/index.html.twig index d0d0e2a..6aba3e9 100644 --- a/src/App/templates/app/index.html.twig +++ b/src/App/templates/app/index.html.twig @@ -88,17 +88,17 @@
Headless Platform

Three applications, one platform

-

API, Admin and Queue declare the same Core namespaces — the same entities, repositories and services. +

API, Admin and Queue declare the same Core namespaces — the same entities, repositories and services. A User means the same thing to the endpoint that creates it, the admin screen that moderates it and the worker that emails it. Three deployables that scale independently and never disagree about the domain.

-
- Shared domain layer - Core\App Core\Admin Core\User - Core\Security Core\Setting -

One set of entities and repositorie. Committed in each repo so a single-component start just works — lift it into its own repo and share it as a Git submodule when you add a second.

-
+
+ Shared domain layer + Core\App Core\Admin Core\User + Core\Security Core\Setting +

One set of entities and repository. Committed in each repo so a single-component start just works — lift it into its own repo and share it as a Git submodule when you add a second.

+
diff --git a/src/Page/src/ConfigProvider.php b/src/Page/src/ConfigProvider.php index 6041f62..d241aa1 100644 --- a/src/Page/src/ConfigProvider.php +++ b/src/Page/src/ConfigProvider.php @@ -11,13 +11,24 @@ use Light\Page\Service\PageServiceInterface; use Mezzio\Application; +/** + * @phpstan-type ConfigType array{ + * dependencies: DependenciesType, + * templates: TemplatesType, + * } + * @phpstan-type DependenciesType array{ + * delegators: non-empty-array>, + * factories: array, + * aliases: array, + * } + * @phpstan-type TemplatesType array{ + * paths: non-empty-array, + * } + **/ class ConfigProvider { /** - @return array{ - * dependencies: array, - * templates: array, - * } + * @return ConfigType */ public function __invoke(): array { @@ -28,11 +39,7 @@ public function __invoke(): array } /** - @return array{ - * delegators: array>, - * factories: array, - * aliases: array - * } + * @return DependenciesType */ public function getDependencies(): array { @@ -53,9 +60,7 @@ public function getDependencies(): array } /** - @return array{ - * paths: array{page: array{literal-string&non-falsy-string}} - * } + * @return TemplatesType */ public function getTemplates(): array { diff --git a/test/Common/TestCase.php b/test/Common/TestCase.php index f386ea9..686815e 100644 --- a/test/Common/TestCase.php +++ b/test/Common/TestCase.php @@ -17,12 +17,20 @@ class TestCase extends \PHPUnit\Framework\TestCase protected ?ContainerInterface $container = null; protected ?EntityManagerInterface $entityManager = null; + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ protected function setUp(): void { TestMode::enable(); $this->ensureTestMode(); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function ensureTestMode(): void { if (! TestMode::isEnabled()) { diff --git a/test/Unit/App/ConfigProviderTest.php b/test/Unit/App/ConfigProviderTest.php index 827e927..86aa9b3 100644 --- a/test/Unit/App/ConfigProviderTest.php +++ b/test/Unit/App/ConfigProviderTest.php @@ -6,11 +6,17 @@ use Light\App\ConfigProvider; use Light\App\Handler\GetIndexViewHandler; -use PHPUnit\Framework\TestCase; +use LightTest\Unit\UnitTest; -class ConfigProviderTest extends TestCase +/** + * @phpstan-import-type ConfigType from ConfigProvider + */ +class ConfigProviderTest extends UnitTest { - /** @var array */ + /** + * @phpstan-var ConfigType $config + * @phpstan-ignore property.defaultValue + */ protected array $config = []; protected function setup(): void diff --git a/test/Unit/Page/ConfigProviderTest.php b/test/Unit/Page/ConfigProviderTest.php index 67cd02f..5e0a7ca 100644 --- a/test/Unit/Page/ConfigProviderTest.php +++ b/test/Unit/Page/ConfigProviderTest.php @@ -8,12 +8,18 @@ use Light\Page\RoutesDelegator; use Light\Page\Service\PageService; use Light\Page\Service\PageServiceInterface; +use LightTest\Unit\UnitTest; use Mezzio\Application; -use PHPUnit\Framework\TestCase; -class ConfigProviderTest extends TestCase +/** + * @phpstan-import-type ConfigType from ConfigProvider + */ +class ConfigProviderTest extends UnitTest { - /** @var array>*/ + /** + * @phpstan-var ConfigType $config + * @phpstan-ignore property.defaultValue + */ protected array $config = []; protected function setup(): void diff --git a/test/Unit/Page/Handler/PageHandlerTest.php b/test/Unit/Page/Handler/PageHandlerTest.php index ebf25a4..02a4bcf 100644 --- a/test/Unit/Page/Handler/PageHandlerTest.php +++ b/test/Unit/Page/Handler/PageHandlerTest.php @@ -8,14 +8,14 @@ use Light\Blog\Repository\CategoryRepository; use Light\Blog\Repository\PostRepository; use Light\Page\Handler\GetPageViewHandler; +use LightTest\Unit\UnitTest; use Mezzio\Router\RouteResult; use Mezzio\Template\TemplateRendererInterface; use PHPUnit\Framework\MockObject\Exception; -use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; -class PageHandlerTest extends TestCase +class PageHandlerTest extends UnitTest { /** * @throws Exception diff --git a/test/Unit/Page/RoutesDelegatorTest.php b/test/Unit/Page/RoutesDelegatorTest.php index 46aca7d..a529cd3 100644 --- a/test/Unit/Page/RoutesDelegatorTest.php +++ b/test/Unit/Page/RoutesDelegatorTest.php @@ -6,17 +6,17 @@ use Light\Page\Handler\GetPageViewHandler; use Light\Page\RoutesDelegator; +use LightTest\Unit\UnitTest; use Mezzio\Application; use Mezzio\Router\Route; use PHPUnit\Framework\MockObject\Exception; -use PHPUnit\Framework\TestCase; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use function sprintf; -class RoutesDelegatorTest extends TestCase +class RoutesDelegatorTest extends UnitTest { /** * @throws ContainerExceptionInterface diff --git a/test/Unit/Page/Service/PageServiceTest.php b/test/Unit/Page/Service/PageServiceTest.php index db69d7a..eb15edb 100644 --- a/test/Unit/Page/Service/PageServiceTest.php +++ b/test/Unit/Page/Service/PageServiceTest.php @@ -6,9 +6,9 @@ use Light\Page\Service\PageService; use Light\Page\Service\PageServiceInterface; -use PHPUnit\Framework\TestCase; +use LightTest\Unit\UnitTest; -class PageServiceTest extends TestCase +class PageServiceTest extends UnitTest { public function testWillInstantiate(): void {