Skip to content

Commit b75ea6d

Browse files
committed
[generator] make import tests into a unit test
When we run safe with multiple different PHP versions, we want to make sure importing the library works under all versions - not just the version we generate with
1 parent 4362e78 commit b75ea6d

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

generator/src/GenerateCommand.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5353

5454
$this->runCsFix($output);
5555

56-
// Let's require the generated file to check there is no error.
57-
$files = \glob(__DIR__.'/../../generated/*.php');
58-
if ($files === false) {
59-
throw new \RuntimeException('Failed to require the generated file');
60-
}
61-
62-
foreach ($files as $file) {
63-
require($file);
64-
}
65-
66-
$files = \glob(__DIR__.'/../../generated/Exceptions/*.php');
67-
if ($files === false) {
68-
throw new \RuntimeException('Failed to require the generated exception file');
69-
}
70-
71-
require_once __DIR__.'/../../lib/Exceptions/SafeExceptionInterface.php';
72-
foreach ($files as $file) {
73-
require($file);
74-
}
75-
7656
// Finally, let's edit the composer.json file
7757
$output->writeln('Editing composer.json');
7858
ComposerJsonEditor::editComposerFileForGeneration(\array_values($modules));

tests/GeneratedFilesTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class GeneratedFilesTest extends TestCase
8+
{
9+
public function testRequireModules(): void
10+
{
11+
self::expectNotToPerformAssertions();
12+
13+
$files = \glob(__DIR__.'/../generated/*.php');
14+
if ($files === false) {
15+
throw new \RuntimeException('Failed to require the generated file');
16+
}
17+
18+
foreach ($files as $file) {
19+
require_once($file);
20+
}
21+
}
22+
23+
public function testRequireExceptions(): void
24+
{
25+
self::expectNotToPerformAssertions();
26+
27+
$files = \glob(__DIR__.'/../../generated/Exceptions/*.php');
28+
if ($files === false) {
29+
throw new \RuntimeException('Failed to require the generated exception file');
30+
}
31+
foreach ($files as $file) {
32+
require_once($file);
33+
}
34+
}
35+
36+
public function testRequireExceptionInterface(): void
37+
{
38+
self::expectNotToPerformAssertions();
39+
40+
require_once __DIR__.'/../../lib/Exceptions/SafeExceptionInterface.php';
41+
}
42+
}

0 commit comments

Comments
 (0)