Skip to content

Commit 79e058e

Browse files
committed
mv rest_api_reference_test.php to raml2html.php test
1 parent 648bb8d commit 79e058e

File tree

4 files changed

+483
-1
lines changed

4 files changed

+483
-1
lines changed

tools/raml2html/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,27 @@ composer install;
1414

1515
## Usage
1616

17+
Note: If PHP 7.2 is not the default PHP, please, adapt.
18+
1719
To generate static HTML from RAML definitions, use the following code from project root:
1820

1921
```sh
2022
php tools/raml2html/raml2html.php build --non-standard-http-methods=COPY,MOVE,PUBLISH,SWAP -t default -o docs/api/rest_api/rest_api_reference/output/ docs/api/rest_api/rest_api_reference/input/ez.raml
2123
```
2224

23-
Note: If PHP 7.2 is not the default PHP, please, adapt.
25+
To test static HTML against an Ibexa DXP to find route removed and missing routes:
26+
27+
```sh
28+
php tools/raml2html/raml2html.php test docs/api/rest_api/rest_api_reference/rest_api_reference.html ~/ibexa-dxp
29+
```
30+
31+
Note: The Ibexa DXP doesn't need to run
32+
33+
```shell
34+
mkdir ~/ibexa-dxp;
35+
cd ~/ibexa-dxp;
36+
composer create-project ibexa/commerce-skeleton . --no-install --ignore-platform-reqs --no-scripts;
37+
composer install --ignore-platform-reqs --no-scripts;
38+
cd -;
39+
php tools/raml2html/raml2html.php test docs/api/rest_api/rest_api_reference/rest_api_reference.html ~/ibexa-dxp
40+
```

tools/raml2html/src/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use EzSystems\Raml2Html\Command\BuildCommand;
88
use EzSystems\Raml2Html\Command\ClearCacheCommand;
99
use EzSystems\Raml2Html\Command\LintTypesCommand;
10+
use EzSystems\Raml2Html\Command\TestCommand;
1011
use EzSystems\Raml2Html\Generator\Generator;
1112
use EzSystems\Raml2Html\RAML\ParserFactory;
1213
use EzSystems\Raml2Html\Twig\Extension\HashExtension;
@@ -39,6 +40,7 @@ protected function getDefaultCommands(): array
3940
$this->getRamlParserFactory()
4041
),
4142
new ClearCacheCommand(self::CACHE_DIR),
43+
new TestCommand(),
4244
]);
4345
}
4446

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace EzSystems\Raml2Html\Command;
6+
7+
use EzSystems\Raml2Html\Test\ReferenceTester;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Input\InputArgument;
11+
use Symfony\Component\Console\Input\InputOption;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
final class TestCommand extends Command
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
protected function configure(): void
20+
{
21+
$this->setName('test')
22+
->setDescription('Compare REST API Reference with Ibexa DXP routing configuration under /api/ibexa/v2 prefix')
23+
->setHelp('It is recommended to not use --console-path and --routing-file options while testing the Rest API Reference HTML file against configuration. Those options are used to test that the default configuration file list is up-to-date and other subtleties.')
24+
->addArgument('rest-api-reference', InputArgument::REQUIRED, 'Path to the REST API Reference HTML file')
25+
->addArgument('ibexa-dxp-root', InputArgument::REQUIRED, 'Path to an Ibexa DXP root directory')
26+
->addOption('console-path', 'c', InputOption::VALUE_OPTIONAL, 'Path to the console relative to Ibexa DXP root directory (if no value, use `bin/console`)', false)
27+
->addOption('routing-file', 'f', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Path to a routing configuration YAML file relative to Ibexa DXP root directory', ReferenceTester::DEFAULT_FILE_LIST)
28+
->addOption('tested-routes', 't', InputOption::VALUE_OPTIONAL,
29+
"ref: Test if reference routes are found in the configuration file;\n
30+
conf: Test if configuration routes are found in the reference file;\n
31+
both: Test both.", 'both');
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
protected function execute(InputInterface $input, OutputInterface $output): int
38+
{
39+
$restApiReference = $input->getArgument('rest-api-reference');
40+
if (!is_file($restApiReference)) {
41+
$output->writeln("<error>$restApiReference doesn't exist or is not a file.</error>");
42+
return 1;
43+
}
44+
45+
$dxpRoot = $input->getArgument('ibexa-dxp-root');
46+
if (!is_dir($dxpRoot)) {
47+
$output->writeln("<error>$dxpRoot doesn't exist or is not a directory.</error>");
48+
return 2;
49+
}
50+
51+
$consolePath = $input->getOption('console-path');
52+
if (null === $consolePath) {
53+
$consolePath = 'bin/console';
54+
}
55+
56+
$routingFiles = $input->getOption('routing-file');
57+
58+
$referenceTester = new ReferenceTester($restApiReference, $dxpRoot, $consolePath, $routingFiles);
59+
60+
$testedRoutes = @[
61+
'ref' => ReferenceTester::TEST_REFERENCE_ROUTES,
62+
'conf' => ReferenceTester::TEST_CONFIG_ROUTES,
63+
'both' => ReferenceTester::TEST_ALL_ROUTES,
64+
][$input->getOption('tested-routes')] ?? ReferenceTester::TEST_ALL_ROUTES;
65+
66+
$referenceTester->run($testedRoutes);
67+
68+
return 0;
69+
}
70+
71+
private function createParserConfigurationFromInput(InputInterface $input): ParserConfiguration
72+
{
73+
$configuration = new ParserConfiguration();
74+
75+
$nonStandardHTTPMethods = $input->getOption(self::OPTION_NON_STANDARD_HTTP_METHODS);
76+
if ($nonStandardHTTPMethods !== null) {
77+
$configuration->setNonStandardHttpMethods(explode(',', $nonStandardHTTPMethods));
78+
}
79+
80+
return $configuration;
81+
}
82+
83+
private function createGeneratorOptionsFromInput(InputInterface $input): GeneratorOptions
84+
{
85+
$generatorOptions = new GeneratorOptions();
86+
$generatorOptions->setOutputDir($input->getOption(self::OPTION_OUTPUT_DIR));
87+
$generatorOptions->setTheme($input->getOption(self::OPTION_THEME));
88+
89+
return $generatorOptions;
90+
}
91+
}

0 commit comments

Comments
 (0)