Passed
Push — master ( 283335...4a2fc2 )
by Fran
18:22 queued 08:26
created

DocumentorServiceTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A clearContext() 0 4 1
A testApiDocumentation() 0 14 2
A prepareDocumentRoot() 0 10 2
1
<?php
2
3
namespace PSFS\tests\services;
4
5
use PHPUnit\Framework\Attributes\Before;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Attributes\Before was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use PSFS\base\Router;
7
use PSFS\base\types\helpers\GeneratorHelper;
8
use PSFS\services\DocumentorService as Service;
9
10
/**
11
 * Class DocumentServiceTest
12
 * @package PSFS\tests\services
13
 */
14
class DocumentorServiceTest extends GeneratorServiceTest
15
{
16
17
    public static $namespaces = [
18
        '\CLIENT\Api\Test\Test',
19
        '\CLIENT\Api\Related\Related',
20
        '\CLIENT\Api\Solo',
21
    ];
22
23
    /**
24
     * @throws \PSFS\base\exception\GeneratorException
25
     */
26
    #[Before]
27
    public function prepareDocumentRoot(): void
28
    {
29
        if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json')) {
30
            unlink(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json');
31
        }
32
        $this->assertFileDoesNotExist(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', 'Previous generated domains json, please delete it before testing');
33
        GeneratorHelper::deleteDir(CACHE_DIR);
34
        $this->assertDirectoryDoesNotExist(CACHE_DIR, 'Cache folder already exists with data');
35
        GeneratorHelper::createRoot(WEB_DIR, null, true);
36
    }
37
38
    /**
39
     * @param string $modulePath
40
     */
41
    protected function clearContext(string $modulePath): void
42
    {
43
        GeneratorHelper::deleteDir($modulePath);
44
        $this->assertDirectoryDoesNotExist($modulePath, 'Error trying to delete the module');
45
    }
46
47
    /**
48
     * @throws \PSFS\base\exception\GeneratorException
49
     * @throws \ReflectionException
50
     */
51
    public function testApiDocumentation()
52
    {
53
        $modulePath = $this->checkCreateExistingModule();
54
        $this->assertDirectoryExists($modulePath, 'Module did not exists');
55
56
        Router::getInstance()->init();
57
        $documentorService = Service::getInstance();
58
        $module = $documentorService->getModules(self::MODULE_NAME);
59
        $doc = $documentorService->extractApiEndpoints($module);
60
        foreach ($doc as $namespace => $endpoints) {
61
            $this->assertContains($namespace, self::$namespaces, 'Namespace not included in the test');
62
            $this->assertCount(7, $endpoints, 'Different number of endpoints');
63
        }
64
        $this->clearContext($modulePath);
65
    }
66
}
67