Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions bin/composer-post-install-script.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} $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');
2 changes: 1 addition & 1 deletion config/autoload/local.test.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare(strict_types=1);

use LightTest\Common\TestMode;

if (! TestMode::class::isEnabled()) {
if (! TestMode::isEnabled()) {
return [];
}

Expand Down
14 changes: 5 additions & 9 deletions src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @phpstan-type ConfigType array{
* dependencies: DependenciesType,
* doctrine: DoctrineConfigType,
* templates: TemplatesType,
* resultCacheLifetime: int,
* }
* @phpstan-type DoctrineConfigType array{
Expand Down Expand Up @@ -84,6 +85,9 @@
* factories: array<class-string|non-empty-string, class-string|non-empty-string>,
* aliases: array<class-string|non-empty-string, class-string|non-empty-string>,
* }
* @phpstan-type TemplatesType array{
* paths: non-empty-array<non-empty-string, non-empty-string[]>,
* }
**/
class ConfigProvider
{
Expand Down Expand Up @@ -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
{
Expand Down
14 changes: 7 additions & 7 deletions src/App/templates/app/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@
<div class="section-head">
<span class="eyebrow">Headless Platform</span>
<h2>Three applications, one platform</h2>
<p>API, Admin and Queue declare the same <code>Core</code> namespaces — the same entities, repositories and services.
<p>API, Admin and Queue declare the same <code>Core</code> namespaces — the same entities, repositories and services.
A <code>User</code> 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.</p>
</div>

<div class="core-band">
<span class="core-band-label">Shared domain layer</span>
<code>Core\App</code> <code>Core\Admin</code> <code>Core\User</code>
<code>Core\Security</code> <code>Core\Setting</code>
<p>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.</p>
</div>
<div class="core-band">
<span class="core-band-label">Shared domain layer</span>
<code>Core\App</code> <code>Core\Admin</code> <code>Core\User</code>
<code>Core\Security</code> <code>Core\Setting</code>
<p>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.</p>
</div>

<div class="products-grid">

Expand Down
29 changes: 17 additions & 12 deletions src/Page/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<class-string, array<class-string>>,
* factories: array<class-string|non-empty-string, class-string|non-empty-string>,
* aliases: array<class-string|non-empty-string, class-string|non-empty-string>,
* }
* @phpstan-type TemplatesType array{
* paths: non-empty-array<non-empty-string, non-empty-string[]>,
* }
**/
class ConfigProvider
{
/**
@return array{
* dependencies: array<mixed>,
* templates: array<mixed>,
* }
* @return ConfigType
*/
public function __invoke(): array
{
Expand All @@ -28,11 +39,7 @@ public function __invoke(): array
}

/**
@return array{
* delegators: array<class-string, array<class-string>>,
* factories: array<class-string, class-string>,
* aliases: array<class-string, class-string>
* }
* @return DependenciesType
*/
public function getDependencies(): array
{
Expand All @@ -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
{
Expand Down
8 changes: 8 additions & 0 deletions test/Common/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
12 changes: 9 additions & 3 deletions test/Unit/App/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<mixed> */
/**
* @phpstan-var ConfigType $config
* @phpstan-ignore property.defaultValue
*/
protected array $config = [];

protected function setup(): void
Expand Down
12 changes: 9 additions & 3 deletions test/Unit/Page/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, array<string, mixed>>*/
/**
* @phpstan-var ConfigType $config
* @phpstan-ignore property.defaultValue
*/
protected array $config = [];

protected function setup(): void
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Page/Handler/PageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Page/RoutesDelegatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Page/Service/PageServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down