Skip to content

Commit 402cef8

Browse files
committed
Update CI
1 parent 49f55fb commit 402cef8

10 files changed

Lines changed: 83 additions & 41 deletions

File tree

bin/composer-post-install-script.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,50 @@
22

33
declare(strict_types=1);
44

5+
const ENVIRONMENT_DEVELOPMENT = 'development';
6+
const ENVIRONMENT_PRODUCTION = 'production';
57
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
68

79
/**
8-
* @param array{source: string, destination: string} $file
10+
* @param array{source: string, destination: string, environment: array<string>} $file
911
*/
1012
function copyFile(array $file): void
1113
{
14+
if (! in_array(getEnvironment(), $file['environment'])) {
15+
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
16+
return;
17+
}
18+
1219
if (is_readable($file['destination'])) {
13-
echo "File {$file['destination']} already exists." . PHP_EOL;
20+
echo "File {$file['destination']} already exists. Skipping..." . PHP_EOL;
21+
return;
22+
}
23+
24+
if (! copy($file['source'], $file['destination'])) {
25+
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
1426
} else {
15-
if (! copy($file['source'], $file['destination'])) {
16-
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
17-
} else {
18-
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
19-
}
27+
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
2028
}
2129
}
2230

31+
function getEnvironment(): string
32+
{
33+
return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
34+
}
35+
2336
$files = [
2437
[
2538
'source' => 'config/autoload/local.php.dist',
2639
'destination' => 'config/autoload/local.php',
40+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
41+
],
42+
[
43+
'source' => 'config/autoload/local.test.php.dist',
44+
'destination' => 'config/autoload/local.test.php',
45+
'environment' => [ENVIRONMENT_DEVELOPMENT],
2746
],
2847
];
2948

49+
echo "Using environment setting: " . getEnvironment() . PHP_EOL;
50+
3051
array_walk($files, 'copyFile');

config/autoload/local.test.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare(strict_types=1);
44

55
use LightTest\Common\TestMode;
66

7-
if (! TestMode::class::isEnabled()) {
7+
if (! TestMode::isEnabled()) {
88
return [];
99
}
1010

src/App/src/ConfigProvider.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* @phpstan-type ConfigType array{
3232
* dependencies: DependenciesType,
3333
* doctrine: DoctrineConfigType,
34+
* templates: TemplatesType,
3435
* resultCacheLifetime: int,
3536
* }
3637
* @phpstan-type DoctrineConfigType array{
@@ -84,6 +85,9 @@
8485
* factories: array<class-string|non-empty-string, class-string|non-empty-string>,
8586
* aliases: array<class-string|non-empty-string, class-string|non-empty-string>,
8687
* }
88+
* @phpstan-type TemplatesType array{
89+
* paths: non-empty-array<non-empty-string, non-empty-string[]>,
90+
* }
8791
**/
8892
class ConfigProvider
8993
{
@@ -127,15 +131,7 @@ public function getDependencies(): array
127131
}
128132

129133
/**
130-
* @return array{
131-
* paths: array{
132-
* app: array{literal-string&non-falsy-string},
133-
* error: array{literal-string&non-falsy-string},
134-
* jsonld: array{literal-string&non-falsy-string},
135-
* layout: array{literal-string&non-falsy-string},
136-
* partial: array{literal-string&non-falsy-string},
137-
* }
138-
* }
134+
* @return TemplatesType
139135
*/
140136
public function getTemplates(): array
141137
{

src/Page/src/ConfigProvider.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,24 @@
1111
use Light\Page\Service\PageServiceInterface;
1212
use Mezzio\Application;
1313

14+
/**
15+
* @phpstan-type ConfigType array{
16+
* dependencies: DependenciesType,
17+
* templates: TemplatesType,
18+
* }
19+
* @phpstan-type DependenciesType array{
20+
* delegators: non-empty-array<class-string, array<class-string>>,
21+
* factories: array<class-string|non-empty-string, class-string|non-empty-string>,
22+
* aliases: array<class-string|non-empty-string, class-string|non-empty-string>,
23+
* }
24+
* @phpstan-type TemplatesType array{
25+
* paths: non-empty-array<non-empty-string, non-empty-string[]>,
26+
* }
27+
**/
1428
class ConfigProvider
1529
{
1630
/**
17-
@return array{
18-
* dependencies: array<mixed>,
19-
* templates: array<mixed>,
20-
* }
31+
* @return ConfigType
2132
*/
2233
public function __invoke(): array
2334
{
@@ -28,11 +39,7 @@ public function __invoke(): array
2839
}
2940

3041
/**
31-
@return array{
32-
* delegators: array<class-string, array<class-string>>,
33-
* factories: array<class-string, class-string>,
34-
* aliases: array<class-string, class-string>
35-
* }
42+
* @return DependenciesType
3643
*/
3744
public function getDependencies(): array
3845
{
@@ -53,9 +60,7 @@ public function getDependencies(): array
5360
}
5461

5562
/**
56-
@return array{
57-
* paths: array{page: array{literal-string&non-falsy-string}}
58-
* }
63+
* @return TemplatesType
5964
*/
6065
public function getTemplates(): array
6166
{

test/Common/TestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ class TestCase extends \PHPUnit\Framework\TestCase
1717
protected ?ContainerInterface $container = null;
1818
protected ?EntityManagerInterface $entityManager = null;
1919

20+
/**
21+
* @throws ContainerExceptionInterface
22+
* @throws NotFoundExceptionInterface
23+
*/
2024
protected function setUp(): void
2125
{
2226
TestMode::enable();
2327
$this->ensureTestMode();
2428
}
2529

30+
/**
31+
* @throws ContainerExceptionInterface
32+
* @throws NotFoundExceptionInterface
33+
*/
2634
private function ensureTestMode(): void
2735
{
2836
if (! TestMode::isEnabled()) {

test/Unit/App/ConfigProviderTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66

77
use Light\App\ConfigProvider;
88
use Light\App\Handler\GetIndexViewHandler;
9-
use PHPUnit\Framework\TestCase;
9+
use LightTest\Unit\UnitTest;
1010

11-
class ConfigProviderTest extends TestCase
11+
/**
12+
* @phpstan-import-type ConfigType from ConfigProvider
13+
*/
14+
class ConfigProviderTest extends UnitTest
1215
{
13-
/** @var array<mixed> */
16+
/**
17+
* @phpstan-var ConfigType $config
18+
* @phpstan-ignore property.defaultValue
19+
*/
1420
protected array $config = [];
1521

1622
protected function setup(): void

test/Unit/Page/ConfigProviderTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88
use Light\Page\RoutesDelegator;
99
use Light\Page\Service\PageService;
1010
use Light\Page\Service\PageServiceInterface;
11+
use LightTest\Unit\UnitTest;
1112
use Mezzio\Application;
12-
use PHPUnit\Framework\TestCase;
1313

14-
class ConfigProviderTest extends TestCase
14+
/**
15+
* @phpstan-import-type ConfigType from ConfigProvider
16+
*/
17+
class ConfigProviderTest extends UnitTest
1518
{
16-
/** @var array<string, array<string, mixed>>*/
19+
/**
20+
* @phpstan-var ConfigType $config
21+
* @phpstan-ignore property.defaultValue
22+
*/
1723
protected array $config = [];
1824

1925
protected function setup(): void

test/Unit/Page/Handler/PageHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
use Light\Blog\Repository\CategoryRepository;
99
use Light\Blog\Repository\PostRepository;
1010
use Light\Page\Handler\GetPageViewHandler;
11+
use LightTest\Unit\UnitTest;
1112
use Mezzio\Router\RouteResult;
1213
use Mezzio\Template\TemplateRendererInterface;
1314
use PHPUnit\Framework\MockObject\Exception;
14-
use PHPUnit\Framework\TestCase;
1515
use Psr\Http\Message\ServerRequestInterface;
1616
use Psr\Http\Server\RequestHandlerInterface;
1717

18-
class PageHandlerTest extends TestCase
18+
class PageHandlerTest extends UnitTest
1919
{
2020
/**
2121
* @throws Exception

test/Unit/Page/RoutesDelegatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
use Light\Page\Handler\GetPageViewHandler;
88
use Light\Page\RoutesDelegator;
9+
use LightTest\Unit\UnitTest;
910
use Mezzio\Application;
1011
use Mezzio\Router\Route;
1112
use PHPUnit\Framework\MockObject\Exception;
12-
use PHPUnit\Framework\TestCase;
1313
use Psr\Container\ContainerExceptionInterface;
1414
use Psr\Container\ContainerInterface;
1515
use Psr\Container\NotFoundExceptionInterface;
1616

1717
use function sprintf;
1818

19-
class RoutesDelegatorTest extends TestCase
19+
class RoutesDelegatorTest extends UnitTest
2020
{
2121
/**
2222
* @throws ContainerExceptionInterface

test/Unit/Page/Service/PageServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use Light\Page\Service\PageService;
88
use Light\Page\Service\PageServiceInterface;
9-
use PHPUnit\Framework\TestCase;
9+
use LightTest\Unit\UnitTest;
1010

11-
class PageServiceTest extends TestCase
11+
class PageServiceTest extends UnitTest
1212
{
1313
public function testWillInstantiate(): void
1414
{

0 commit comments

Comments
 (0)