Skip to content

Commit baaa6bc

Browse files
committed
Cleanup test generators
1 parent 83a6320 commit baaa6bc

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ Enums generator does NOT support `allOf`, `anyOf` and `oneOf` at the moment.
8989
### 'pest_tests' => PestTestsGenerator::class
9090

9191
Generates Pest test file for each `x-lg-handler`
92+
You can exclude oas3 path from test generation using `x-lg-skip-tests-generation: true`.
9293
If a test file already exists it is NOT overriden.
93-
Controller class IS meant to be modified after generation.
94+
Test file class IS meant to be modified after generation.
9495

9596
## Contributing
9697

src/Generators/PestTestsGenerator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ protected function convertRoutesToTestsString(array $routes, string $serversUrl)
6161

6262
return implode("\n", $testsFunctions);
6363
}
64+
65+
protected function getTemplateName(): string
66+
{
67+
return "PestTest.template";
68+
}
6469
}

src/Generators/TestsGenerator.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ abstract protected function convertRoutesToTestsString(array $routes, string $se
1212

1313
abstract protected function convertRoutesToImportsString(array $routes): string;
1414

15+
abstract protected function getTemplateName(): string;
16+
1517
public function generate(SpecObjectInterface $specObject, string|array $namespaceData): void
1618
{
1719
if (!is_array($namespaceData)) {
18-
throw new InvalidArgumentException("PestTestsGenerator supports only arrays as namespaceData");
20+
throw new InvalidArgumentException("TestsGenerator supports only arrays as namespaceData");
1921
}
2022

2123
$openApiData = $specObject->getSerializableData();
2224
$serversUrl = $openApiData?->servers[0]?->url ?? '';
2325
$tests = $this->constructTests($openApiData, $namespaceData);
26+
$template = $this->templatesManager->getTemplate($this->getTemplateName());
2427

25-
$this->createTestsFiles($tests, $this->templatesManager->getTemplate('PestTest.template'), $serversUrl);
28+
$this->createTestsFiles($tests, $template, $serversUrl);
2629
}
2730

2831
protected function constructTests(stdClass $openApiData, array $namespaceData): array

0 commit comments

Comments
 (0)