Skip to content

[generator] make import tests into a unit test #512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2025
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
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';
}
}