-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAutoloadPathProviderTest.php
More file actions
107 lines (83 loc) · 2.71 KB
/
Copy pathAutoloadPathProviderTest.php
File metadata and controls
107 lines (83 loc) · 2.71 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
declare(strict_types=1);
namespace Facile\CodingStandardsTest;
use Facile\CodingStandards\AutoloadPathProvider;
use Facile\CodingStandardsTest\Framework\TestCase;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
class AutoloadPathProviderTest extends TestCase
{
/**
* @var string
*/
private $composerFilePath;
/**
* @var string
*/
private $projectRoot;
/**
* @var vfsStreamDirectory
*/
private $vfsRoot;
protected function setUp(): void
{
parent::setUp();
$this->vfsRoot = vfsStream::setup();
$this->projectRoot = $this->vfsRoot->url();
$this->composerFilePath = $this->vfsRoot->url() . '/composer.json';
mkdir($this->vfsRoot->url() . '/src');
mkdir($this->vfsRoot->url() . '/tests');
file_put_contents($this->composerFilePath, Util::getComposerContent());
}
public function testGetPathsWithDevOn(): void
{
$provider = new AutoloadPathProvider(
$this->composerFilePath,
$this->projectRoot,
true,
);
$expected = ['src/', 'tests/'];
$this->assertSame($expected, $provider->getPaths());
}
public function testGetPathsWithDevOff(): void
{
$provider = new AutoloadPathProvider(
$this->composerFilePath,
$this->projectRoot,
false,
);
$expected = ['src/'];
$this->assertSame($expected, $provider->getPaths());
}
public function testGetPathsWithDefault(): void
{
$provider = new AutoloadPathProvider();
$expected = ['src/', 'tests/'];
$this->assertSame($expected, $provider->getPaths());
}
public function testGetPathsWithWrongComposerJsonPath(): void
{
$provider = new AutoloadPathProvider(__DIR__ . '/composer.json');
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Unable to find composer.json');
$provider->getPaths();
}
public function testGetPathsWithInvalidComposerJson(): void
{
$provider = new AutoloadPathProvider(
$this->composerFilePath,
$this->projectRoot,
false,
);
file_put_contents($this->composerFilePath, '');
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Invalid composer.json file');
$provider->getPaths();
}
public function testWrongComposerPathLeadsToBrokenProjectPath(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Unable to get project root');
new AutoloadPathProvider('wrong/composer/path/');
}
}