Skip to content

Commit

Permalink
Merge pull request #191 from Deuchnord/ask-before-generate-whole-schema
Browse files Browse the repository at this point in the history
Ask before adding all Schema.org's vocabulary
  • Loading branch information
soyuka committed Jan 17, 2020
2 parents 2938bd2 + e88ab2e commit 9ab29eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Command/GenerateTypesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Yaml\Parser;
use Twig\Environment;
use Twig\Extension\DebugExtension;
Expand Down Expand Up @@ -119,6 +120,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$config = $parser->parse(file_get_contents(self::DEFAULT_CONFIG_FILE));
unset($parser);
} else {
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('Your project has no config file. The entire Schema.org vocabulary will be built.'.PHP_EOL.'Continue? [yN]', false);

if (!$helper->ask($input, $output, $question)) {
return 0;
}

$config = [];
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Command/GenerateTypesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\SchemaGenerator\Command\GenerateTypesCommand;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Filesystem;

Expand Down Expand Up @@ -436,4 +437,17 @@ public function testSupersededProperties(): void
PHP
, $creativeWork);
}

public function testGenerationWithoutConfigFileQuestion(): void
{
// No config file is given.
$application = new Application();
$application->add(new GenerateTypesCommand());

$command = $application->find('generate-types');
$commandTester = new CommandTester($command);
$commandTester->setInputs(['n']);
self::assertEquals(0, $commandTester->execute([]));
$this->assertRegExp('/The entire Schema\.org vocabulary will be built/', $commandTester->getDisplay());
}
}

0 comments on commit 9ab29eb

Please sign in to comment.