Skip to content

Commit

Permalink
[generator] make import tests into a unit test
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shish committed Jan 19, 2025
1 parent cc0feee commit f3df831
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
20 changes: 0 additions & 20 deletions generator/src/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->runCsFix($output);

// Let's require the generated file to check there is no error.
$files = \glob(__DIR__.'/../../generated/*.php');
if ($files === false) {
throw new \RuntimeException('Failed to require the generated file');
}

foreach ($files as $file) {
require($file);
}

$files = \glob(__DIR__.'/../../generated/Exceptions/*.php');
if ($files === false) {
throw new \RuntimeException('Failed to require the generated exception file');
}

require_once __DIR__.'/../../lib/Exceptions/SafeExceptionInterface.php';
foreach ($files as $file) {
require($file);
}

// Finally, let's edit the composer.json file
$output->writeln('Editing composer.json');
ComposerJsonEditor::editComposerFileForGeneration(\array_values($modules));
Expand Down
42 changes: 42 additions & 0 deletions tests/GeneratedFilesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

use PHPUnit\Framework\TestCase;

final class GeneratedFilesTest extends TestCase
{
public function testRequireModules(): void
{
self::expectNotToPerformAssertions();

$files = \glob(__DIR__.'/../generated/*.php');
if ($files === false) {
throw new \RuntimeException('Failed to require the generated file');
}

foreach ($files as $file) {
require_once($file);
}
}

public function testRequireExceptions(): void
{
self::expectNotToPerformAssertions();

$files = \glob(__DIR__.'/../generated/Exceptions/*.php');
if ($files === false) {
throw new \RuntimeException('Failed to require the generated exception file');
}
foreach ($files as $file) {
require_once($file);
}
}

public function testRequireExceptionInterface(): void
{
self::expectNotToPerformAssertions();

require_once __DIR__.'/../lib/Exceptions/SafeExceptionInterface.php';
}
}

0 comments on commit f3df831

Please sign in to comment.