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