Skip to content

Commit ae94e71

Browse files
committed
initial test approach
1 parent 685be46 commit ae94e71

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

app/V1Module/presenters/RegistrationPresenter.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
use App\Helpers\RegistrationConfig;
2828
use App\Helpers\InvitationHelper;
2929
use App\Helpers\MetaFormats\Attributes\Format;
30+
use App\Helpers\MetaFormats\Attributes\Path;
31+
use App\Helpers\MetaFormats\Attributes\Query;
3032
use App\Helpers\MetaFormats\FormatDefinitions\UserFormat;
33+
use App\Helpers\MetaFormats\Validators\VDouble;
34+
use App\Helpers\MetaFormats\Validators\VInt;
35+
use App\Helpers\MetaFormats\Validators\VUuid;
3136
use App\Security\Roles;
3237
use App\Security\ACL\IUserPermissions;
3338
use App\Security\ACL\IGroupPermissions;
@@ -447,4 +452,18 @@ public function actionAcceptInvitation()
447452
IResponse::S201_Created
448453
);
449454
}
455+
456+
/**
457+
* Endpoint for performance testing.
458+
* @POST
459+
* @throws BadRequestException
460+
* @throws InvalidArgumentException
461+
*/
462+
#[Path("a", new VUuid())]
463+
#[Query("b", new VInt())]
464+
#[Post("c", new VDouble())]
465+
public function actionTest()
466+
{
467+
$this->sendSuccessResponse("OK");
468+
}
450469
}

app/V1Module/router/RouterFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ private static function createUsersRoutes(string $prefix): RouteList
478478
$router[] = new PostRoute("$prefix/list", "Users:listByIds");
479479
$router[] = new GetRoute("$prefix/ical/<id>", "UserCalendars:");
480480
$router[] = new DeleteRoute("$prefix/ical/<id>", "UserCalendars:expireCalendar");
481+
$router[] = new PostRoute("$prefix/test", "Registration:test");
481482
$router[] = new PostRoute("$prefix/invite", "Registration:createInvitation");
482483
$router[] = new PostRoute("$prefix/accept-invitation", "Registration:acceptInvitation");
483484

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

app/config/config.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ services:
322322
- App\Console\ExportDatabase
323323
- App\Console\MetaConverter
324324
- App\Console\GenerateSwagger
325+
- App\Console\TestFormatPerformance
325326
- App\Console\SwaggerAnnotator
326327
- App\Console\CleanupLocalizedTexts
327328
- App\Console\CleanupExerciseConfigs

0 commit comments

Comments
 (0)