|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Console; |
| 4 | + |
| 5 | +use App\Helpers\Mocks\MockHelper; |
| 6 | +use App\V1Module\Presenters\RegistrationPresenter; |
| 7 | +use Nette\Application\Request; |
| 8 | +use Symfony\Component\Console\Command\Command; |
| 9 | +use Symfony\Component\Console\Input\InputInterface; |
| 10 | +use Symfony\Component\Console\Output\OutputInterface; |
| 11 | +use OpenApi\Generator; |
| 12 | + |
| 13 | +/** |
| 14 | + * Command that consumes a temporary file containing endpoint annotations and generates a swagger documentation. |
| 15 | + */ |
| 16 | +class TestFormatPerformance extends Command |
| 17 | +{ |
| 18 | + protected static $defaultName = 'meta:performance'; |
| 19 | + |
| 20 | + protected function configure() |
| 21 | + { |
| 22 | + $this->setName(self::$defaultName)->setDescription( |
| 23 | + 'Generate an OpenAPI documentation from the temporary file created by the swagger:annotate command.' |
| 24 | + . ' The temporary file is deleted afterwards.' |
| 25 | + ); |
| 26 | + } |
| 27 | + |
| 28 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 29 | + { |
| 30 | + $output->writeln("test"); |
| 31 | + |
| 32 | + $presenter = new RegistrationPresenter(); |
| 33 | + MockHelper::initPresenter($presenter); |
| 34 | + |
| 35 | + $request = new Request( |
| 36 | + "name", |
| 37 | + method: "POST", |
| 38 | + params: ["action" => "test", "a" => "497dcba3-ecbf-4587-a2dd-5eb0665e6880", "b" => "1"], |
| 39 | + post: ["c" => 1.1] |
| 40 | + ); |
| 41 | + |
| 42 | + // test whether the request works |
| 43 | + $response = $presenter->run($request); |
| 44 | + if ($response->getPayload()["payload"] != "OK") { |
| 45 | + $output->writeln("The endpoint did not run correctly."); |
| 46 | + return Command::FAILURE; |
| 47 | + } |
| 48 | + |
| 49 | + $startTime = microtime(true); |
| 50 | + $iterations = 100_000; |
| 51 | + for ($i = 0; $i < $iterations; $i++) { |
| 52 | + $response = $presenter->run($request); |
| 53 | + } |
| 54 | + $endTime = microtime(true); |
| 55 | + |
| 56 | + $elapsed = $endTime - $startTime; |
| 57 | + $output->writeln($elapsed); |
| 58 | + |
| 59 | + return Command::SUCCESS; |
| 60 | + } |
| 61 | +} |
0 commit comments