|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Detain\MyAdminPleskAutomation\Tests; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | + |
| 9 | +/** |
| 10 | + * Tests that all expected source files exist and contain |
| 11 | + * the correct class/function declarations. |
| 12 | + */ |
| 13 | +class FileExistenceTest extends TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @dataProvider sourceFileProvider |
| 17 | + * |
| 18 | + * Verify each expected source file exists on disk. |
| 19 | + */ |
| 20 | + public function testSourceFileExists(string $relativePath): void |
| 21 | + { |
| 22 | + $fullPath = dirname(__DIR__) . '/src/' . $relativePath; |
| 23 | + $this->assertFileExists($fullPath); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Provides relative paths to all expected source files. |
| 28 | + */ |
| 29 | + public function sourceFileProvider(): array |
| 30 | + { |
| 31 | + return [ |
| 32 | + 'PPAConnector.php' => ['PPAConnector.php'], |
| 33 | + 'Plugin.php' => ['Plugin.php'], |
| 34 | + 'PPAFailedRequestException.php' => ['PPAFailedRequestException.php'], |
| 35 | + 'PPAMalformedRequestException.php' => ['PPAMalformedRequestException.php'], |
| 36 | + 'PPADomainDoesNotExistException.php' => ['PPADomainDoesNotExistException.php'], |
| 37 | + 'get_pleskautomation_info_from_domain.php' => ['get_pleskautomation_info_from_domain.php'], |
| 38 | + 'get_webhosting_ppa_instance.php' => ['get_webhosting_ppa_instance.php'], |
| 39 | + ]; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Verify PPAConnector.php declares the PPAConnector class. |
| 44 | + */ |
| 45 | + public function testPPAConnectorFileContainsClassDeclaration(): void |
| 46 | + { |
| 47 | + $content = file_get_contents(dirname(__DIR__) . '/src/PPAConnector.php'); |
| 48 | + $this->assertStringContainsString('class PPAConnector', $content); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Verify Plugin.php declares the Plugin class. |
| 53 | + */ |
| 54 | + public function testPluginFileContainsClassDeclaration(): void |
| 55 | + { |
| 56 | + $content = file_get_contents(dirname(__DIR__) . '/src/Plugin.php'); |
| 57 | + $this->assertStringContainsString('class Plugin', $content); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Verify PPAFailedRequestException.php declares the exception class. |
| 62 | + */ |
| 63 | + public function testFailedRequestExceptionFileContainsClass(): void |
| 64 | + { |
| 65 | + $content = file_get_contents(dirname(__DIR__) . '/src/PPAFailedRequestException.php'); |
| 66 | + $this->assertStringContainsString('class PPAFailedRequestException extends \\Exception', $content); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Verify PPAMalformedRequestException.php declares the exception class. |
| 71 | + */ |
| 72 | + public function testMalformedRequestExceptionFileContainsClass(): void |
| 73 | + { |
| 74 | + $content = file_get_contents(dirname(__DIR__) . '/src/PPAMalformedRequestException.php'); |
| 75 | + $this->assertStringContainsString('class PPAMalformedRequestException extends \\Exception', $content); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Verify PPADomainDoesNotExistException.php extends PPAFailedRequestException. |
| 80 | + */ |
| 81 | + public function testDomainDoesNotExistFileContainsClass(): void |
| 82 | + { |
| 83 | + $content = file_get_contents(dirname(__DIR__) . '/src/PPADomainDoesNotExistException.php'); |
| 84 | + $this->assertStringContainsString('class PPADomainDoesNotExistException extends PPAFailedRequestException', $content); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Verify get_pleskautomation_info_from_domain.php declares its function. |
| 89 | + */ |
| 90 | + public function testGetPleskautomationInfoFunctionFileContainsDeclaration(): void |
| 91 | + { |
| 92 | + $content = file_get_contents(dirname(__DIR__) . '/src/get_pleskautomation_info_from_domain.php'); |
| 93 | + $this->assertStringContainsString('function get_pleskautomation_info_from_domain', $content); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Verify get_webhosting_ppa_instance.php declares its function. |
| 98 | + */ |
| 99 | + public function testGetWebhostingPpaInstanceFileContainsDeclaration(): void |
| 100 | + { |
| 101 | + $content = file_get_contents(dirname(__DIR__) . '/src/get_webhosting_ppa_instance.php'); |
| 102 | + $this->assertStringContainsString('function get_webhosting_ppa_instance', $content); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Verify all source files use the correct namespace declaration. |
| 107 | + */ |
| 108 | + public function testNamespaceInClassFiles(): void |
| 109 | + { |
| 110 | + $classFiles = [ |
| 111 | + 'PPAConnector.php', |
| 112 | + 'Plugin.php', |
| 113 | + 'PPAFailedRequestException.php', |
| 114 | + 'PPAMalformedRequestException.php', |
| 115 | + 'PPADomainDoesNotExistException.php', |
| 116 | + ]; |
| 117 | + foreach ($classFiles as $file) { |
| 118 | + $content = file_get_contents(dirname(__DIR__) . '/src/' . $file); |
| 119 | + $this->assertStringContainsString( |
| 120 | + 'namespace Detain\\MyAdminPleskAutomation;', |
| 121 | + $content, |
| 122 | + "{$file} should declare the correct namespace" |
| 123 | + ); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Verify composer.json exists at the package root. |
| 129 | + */ |
| 130 | + public function testComposerJsonExists(): void |
| 131 | + { |
| 132 | + $this->assertFileExists(dirname(__DIR__) . '/composer.json'); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Verify composer.json is valid JSON. |
| 137 | + */ |
| 138 | + public function testComposerJsonIsValid(): void |
| 139 | + { |
| 140 | + $content = file_get_contents(dirname(__DIR__) . '/composer.json'); |
| 141 | + $decoded = json_decode($content, true); |
| 142 | + $this->assertNotNull($decoded, 'composer.json should be valid JSON'); |
| 143 | + $this->assertArrayHasKey('name', $decoded); |
| 144 | + $this->assertSame('detain/myadmin-pleskautomation-webhosting', $decoded['name']); |
| 145 | + } |
| 146 | +} |
0 commit comments