• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DerManoMann / openapi-verifier / 11750785900

08 Nov 2024 11:00PM UTC coverage: 52.941%. Remained the same
11750785900

push

github

web-flow
Use `swagger-php` `Generator` to generate the spec (#57)

Replaces the broken code that was still using the old `scan()` function that doesn't exist anym more.

0 of 1 new or added line in 1 file covered. (0.0%)

81 of 153 relevant lines covered (52.94%)

3.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.29
/src/Adapters/AbstractOpenApiResponseVerifier.php
1
<?php declare(strict_types=1);
2

3
namespace Radebatz\OpenApi\Verifier\Adapters;
4

5
use OpenApi\Generator;
6

7
trait AbstractOpenApiResponseVerifier
8
{
9
    protected function prepareOpenApiSpecificationLoader(string $srcDir, ?string $specification = null)
10
    {
11
        $appRoot = null;
1✔
12

13
        if ($specification) {
1✔
14
            $this->openapiSpecification = $specification;
1✔
15
        }
16

17
        // try loader
18
        $specificationLoader = $this->getOpenApiSpecificationLoader();
1✔
19

20
        if (!$specificationLoader) {
1✔
21
            $appRoot = $appRoot ?: $this->getAppRoot();
×
22

23
            // try some default filenames
24
            foreach (['openapi.json', 'openapi.yaml'] as $specfile) {
×
25
                if (file_exists($specification = $appRoot . '/tests/' . $specfile)) {
×
26
                    $this->openapiSpecification = $specification;
×
27
                    break;
×
28
                }
29
            }
30

31
            // try loader again
32
            $specificationLoader = $this->getOpenApiSpecificationLoader();
×
33
        }
34

35
        if (!$specificationLoader) {
1✔
36
            $appRoot = $appRoot ?: $this->getAppRoot();
×
37

NEW
38
            $openApi = (new Generator())->generate([$appRoot . '/' . $srcDir]);
×
39
            $this->openapiSpecification = json_decode($openApi->toJson());
×
40
        }
41
    }
42

43
    protected function getAppRoot()
44
    {
45
        $rc = new \ReflectionClass('\Composer\Autoload\ClassLoader');
×
46

47
        return dirname(dirname(dirname($rc->getFileName())));
×
48
    }
49
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc