|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Detain\MyAdminCloudlinux\Tests; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | + |
| 7 | +/** |
| 8 | + * Tests that verify the composer.json configuration is correct. |
| 9 | + * |
| 10 | + * Ensures proper autoloading, dependencies, and package metadata. |
| 11 | + */ |
| 12 | +class ComposerConfigTest extends TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var array Parsed composer.json contents |
| 16 | + */ |
| 17 | + private $composerConfig; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var string Path to composer.json |
| 21 | + */ |
| 22 | + private $composerPath; |
| 23 | + |
| 24 | + protected function setUp(): void |
| 25 | + { |
| 26 | + $this->composerPath = dirname(__DIR__) . '/composer.json'; |
| 27 | + $content = file_get_contents($this->composerPath); |
| 28 | + $this->composerConfig = json_decode($content, true); |
| 29 | + $this->assertNotNull($this->composerConfig, 'composer.json should be valid JSON'); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Tests that composer.json exists and is readable. |
| 34 | + */ |
| 35 | + public function testComposerJsonExists(): void |
| 36 | + { |
| 37 | + $this->assertFileExists($this->composerPath); |
| 38 | + $this->assertFileIsReadable($this->composerPath); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Tests that the package name follows the vendor/package convention. |
| 43 | + */ |
| 44 | + public function testPackageName(): void |
| 45 | + { |
| 46 | + $this->assertSame('detain/myadmin-cloudlinux-licensing', $this->composerConfig['name']); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Tests that the package type is set to myadmin-plugin. |
| 51 | + * This type is used by the custom installer for MyAdmin plugins. |
| 52 | + */ |
| 53 | + public function testPackageType(): void |
| 54 | + { |
| 55 | + $this->assertSame('myadmin-plugin', $this->composerConfig['type']); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Tests that the license is correctly set to LGPL-2.1-only. |
| 60 | + */ |
| 61 | + public function testLicense(): void |
| 62 | + { |
| 63 | + $this->assertSame('LGPL-2.1-only', $this->composerConfig['license']); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Tests that autoloading is configured with PSR-4 for the correct namespace. |
| 68 | + */ |
| 69 | + public function testAutoloadPsr4(): void |
| 70 | + { |
| 71 | + $this->assertArrayHasKey('autoload', $this->composerConfig); |
| 72 | + $this->assertArrayHasKey('psr-4', $this->composerConfig['autoload']); |
| 73 | + $this->assertArrayHasKey('Detain\\MyAdminCloudlinux\\', $this->composerConfig['autoload']['psr-4']); |
| 74 | + $this->assertSame('src/', $this->composerConfig['autoload']['psr-4']['Detain\\MyAdminCloudlinux\\']); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Tests that PHPUnit is listed as a dev dependency. |
| 79 | + */ |
| 80 | + public function testPhpunitInRequireDev(): void |
| 81 | + { |
| 82 | + $this->assertArrayHasKey('require-dev', $this->composerConfig); |
| 83 | + $this->assertArrayHasKey('phpunit/phpunit', $this->composerConfig['require-dev']); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Tests that the required runtime dependencies are present. |
| 88 | + */ |
| 89 | + public function testRequiredDependencies(): void |
| 90 | + { |
| 91 | + $this->assertArrayHasKey('require', $this->composerConfig); |
| 92 | + $this->assertArrayHasKey('php', $this->composerConfig['require']); |
| 93 | + $this->assertArrayHasKey('detain/cloudlinux-licensing', $this->composerConfig['require']); |
| 94 | + $this->assertArrayHasKey('symfony/event-dispatcher', $this->composerConfig['require']); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Tests that authors section has at least one entry. |
| 99 | + */ |
| 100 | + public function testAuthorsSection(): void |
| 101 | + { |
| 102 | + $this->assertArrayHasKey('authors', $this->composerConfig); |
| 103 | + $this->assertNotEmpty($this->composerConfig['authors']); |
| 104 | + $this->assertArrayHasKey('name', $this->composerConfig['authors'][0]); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Tests that the package has relevant keywords for discoverability. |
| 109 | + */ |
| 110 | + public function testKeywords(): void |
| 111 | + { |
| 112 | + $this->assertArrayHasKey('keywords', $this->composerConfig); |
| 113 | + $this->assertContains('cloudlinux', $this->composerConfig['keywords']); |
| 114 | + $this->assertContains('license', $this->composerConfig['keywords']); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Tests that a description is provided in composer.json. |
| 119 | + */ |
| 120 | + public function testDescription(): void |
| 121 | + { |
| 122 | + $this->assertArrayHasKey('description', $this->composerConfig); |
| 123 | + $this->assertNotEmpty($this->composerConfig['description']); |
| 124 | + } |
| 125 | +} |
0 commit comments