|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace LaminasTest\ComponentInstaller\ConfigDiscovery; |
| 6 | + |
| 7 | +use Laminas\ComponentInstaller\ConfigDiscovery\DiscoveryInterface; |
| 8 | +use org\bovigo\vfs\vfsStream; |
| 9 | +use org\bovigo\vfs\vfsStreamDirectory; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +abstract class AbstractConfigAggregatorTestCase extends TestCase |
| 13 | +{ |
| 14 | + private vfsStreamDirectory $configDir; |
| 15 | + |
| 16 | + private DiscoveryInterface $locator; |
| 17 | + |
| 18 | + /** @var class-string<DiscoveryInterface> */ |
| 19 | + protected string $discoveryClass; |
| 20 | + |
| 21 | + protected string $configFile; |
| 22 | + |
| 23 | + protected function setUp(): void |
| 24 | + { |
| 25 | + $this->configDir = vfsStream::setup('project'); |
| 26 | + $this->locator = new $this->discoveryClass( |
| 27 | + vfsStream::url('project') |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + public function testAbsenceOfFileReturnsFalseOnLocate(): void |
| 32 | + { |
| 33 | + $this->assertFalse($this->locator->locate()); |
| 34 | + } |
| 35 | + |
| 36 | + public function testLocateReturnsFalseWhenFileDoesNotHaveExpectedContents(): void |
| 37 | + { |
| 38 | + vfsStream::newFile($this->configFile) |
| 39 | + ->at($this->configDir) |
| 40 | + ->setContent('<' . "?php\nreturn [];"); |
| 41 | + $this->assertFalse($this->locator->locate()); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @psalm-return array<string, array{ |
| 46 | + * 0: string |
| 47 | + * }> |
| 48 | + */ |
| 49 | + public function validMezzioConfigContents(): array |
| 50 | + { |
| 51 | + // @codingStandardsIgnoreStart |
| 52 | + return [ |
| 53 | + 'fqcn-short-array' => ['<' . "?php\n\$aggregator = new Laminas\ConfigAggregator\ConfigAggregator([\n]);"], |
| 54 | + 'globally-qualified-short-array' => ['<' . "?php\n\$aggregator = new \Laminas\ConfigAggregator\ConfigAggregator([\n]);"], |
| 55 | + 'imported-short-array' => ['<' . "?php\n\$aggregator = new ConfigAggregator([\n]);"], |
| 56 | + 'fqcn-long-array' => ['<' . "?php\n\$aggregator = new Laminas\ConfigAggregator\ConfigAggregator(array(\n));"], |
| 57 | + 'globally-qualified-long-array' => ['<' . "?php\n\$aggregator = new \Laminas\ConfigAggregator\ConfigAggregator(array(\n));"], |
| 58 | + 'imported-long-array' => ['<' . "?php\n\$aggregator = new ConfigAggregator(array(\n));"], |
| 59 | + ]; |
| 60 | + // @codingStandardsIgnoreEnd |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @dataProvider validMezzioConfigContents |
| 65 | + */ |
| 66 | + public function testLocateReturnsTrueWhenFileExistsAndHasExpectedContent(string $contents): void |
| 67 | + { |
| 68 | + vfsStream::newFile($this->configFile) |
| 69 | + ->at($this->configDir) |
| 70 | + ->setContent($contents); |
| 71 | + |
| 72 | + $this->assertTrue($this->locator->locate()); |
| 73 | + } |
| 74 | +} |
0 commit comments