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