Skip to content

Commit e88ab2e

Browse files
author
Jérôme Deuchnord
committed
Ask before adding all Schema.org's vocabulary
1 parent 68f4224 commit e88ab2e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Command/GenerateTypesCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Console\Input\InputInterface;
2525
use Symfony\Component\Console\Logger\ConsoleLogger;
2626
use Symfony\Component\Console\Output\OutputInterface;
27+
use Symfony\Component\Console\Question\ConfirmationQuestion;
2728
use Symfony\Component\Yaml\Parser;
2829
use Twig\Environment;
2930
use Twig\Extension\DebugExtension;
@@ -119,6 +120,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
119120
$config = $parser->parse(file_get_contents(self::DEFAULT_CONFIG_FILE));
120121
unset($parser);
121122
} else {
123+
$helper = $this->getHelper('question');
124+
$question = new ConfirmationQuestion('Your project has no config file. The entire Schema.org vocabulary will be built.'.PHP_EOL.'Continue? [yN]', false);
125+
126+
if (!$helper->ask($input, $output, $question)) {
127+
return 0;
128+
}
129+
122130
$config = [];
123131
}
124132

tests/Command/GenerateTypesCommandTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\SchemaGenerator\Command\GenerateTypesCommand;
1717
use PHPUnit\Framework\TestCase;
18+
use Symfony\Component\Console\Application;
1819
use Symfony\Component\Console\Tester\CommandTester;
1920
use Symfony\Component\Filesystem\Filesystem;
2021

@@ -434,4 +435,17 @@ public function testSupersededProperties(): void
434435
PHP
435436
, $creativeWork);
436437
}
438+
439+
public function testGenerationWithoutConfigFileQuestion(): void
440+
{
441+
// No config file is given.
442+
$application = new Application();
443+
$application->add(new GenerateTypesCommand());
444+
445+
$command = $application->find('generate-types');
446+
$commandTester = new CommandTester($command);
447+
$commandTester->setInputs(['n']);
448+
self::assertEquals(0, $commandTester->execute([]));
449+
$this->assertRegExp('/The entire Schema\.org vocabulary will be built/', $commandTester->getDisplay());
450+
}
437451
}

0 commit comments

Comments
 (0)