1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\LocateDependencies; |
6
|
|
|
|
7
|
|
|
use Composer\Installer; |
8
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use ReflectionProperty; |
11
|
|
|
use Roave\BackwardCompatibility\LocateDependencies\LocateDependenciesViaComposer; |
12
|
|
|
use Roave\BetterReflection\BetterReflection; |
13
|
|
|
use Roave\BetterReflection\SourceLocator\Ast\Locator; |
14
|
|
|
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator; |
15
|
|
|
use Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator; |
16
|
|
|
use function Safe\getcwd; |
17
|
|
|
use function Safe\realpath; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @covers \Roave\BackwardCompatibility\LocateDependencies\LocateDependenciesViaComposer |
21
|
|
|
*/ |
22
|
|
|
final class LocateDependenciesViaComposerTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
/** @var string */ |
25
|
|
|
private $originalCwd; |
26
|
|
|
|
27
|
|
|
/** @var callable */ |
28
|
|
|
private $makeInstaller; |
29
|
|
|
|
30
|
|
|
/** @var Installer|MockObject */ |
31
|
|
|
private $composerInstaller; |
32
|
|
|
|
33
|
|
|
/** @var string|null */ |
34
|
|
|
private $expectedInstallatonPath; |
35
|
|
|
|
36
|
|
|
/** @var Locator */ |
37
|
|
|
private $astLocator; |
38
|
|
|
|
39
|
|
|
/** @var LocateDependenciesViaComposer */ |
40
|
|
|
private $locateDependencies; |
41
|
|
|
|
42
|
|
|
protected function setUp() : void |
43
|
|
|
{ |
44
|
|
|
parent::setUp(); |
45
|
|
|
|
46
|
|
|
$originalCwd = getcwd(); |
47
|
|
|
|
48
|
|
|
self::assertInternalType('string', $originalCwd); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$this->originalCwd = $originalCwd; |
51
|
|
|
$this->composerInstaller = $this->createMock(Installer::class); |
52
|
|
|
$this->astLocator = (new BetterReflection())->astLocator(); |
53
|
|
|
$this->makeInstaller = function (string $installationPath) : Installer { |
54
|
|
|
self::assertSame($this->expectedInstallatonPath, $installationPath); |
55
|
|
|
|
56
|
|
|
return $this->composerInstaller; |
|
|
|
|
57
|
|
|
}; |
58
|
|
|
|
59
|
|
|
$this |
60
|
|
|
->composerInstaller |
61
|
|
|
->expects(self::atLeastOnce()) |
62
|
|
|
->method('setDevMode') |
63
|
|
|
->with(false); |
64
|
|
|
$this |
65
|
|
|
->composerInstaller |
66
|
|
|
->expects(self::atLeastOnce()) |
67
|
|
|
->method('setDumpAutoloader') |
68
|
|
|
->with(false); |
69
|
|
|
$this |
70
|
|
|
->composerInstaller |
71
|
|
|
->expects(self::atLeastOnce()) |
72
|
|
|
->method('setRunScripts') |
73
|
|
|
->with(false); |
74
|
|
|
$this |
75
|
|
|
->composerInstaller |
76
|
|
|
->expects(self::atLeastOnce()) |
77
|
|
|
->method('setIgnorePlatformRequirements') |
78
|
|
|
->with(true); |
79
|
|
|
|
80
|
|
|
$this->locateDependencies = new LocateDependenciesViaComposer($this->makeInstaller, $this->astLocator); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function tearDown() : void |
84
|
|
|
{ |
85
|
|
|
self::assertSame($this->originalCwd, getcwd()); |
86
|
|
|
|
87
|
|
|
parent::tearDown(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testWillLocateDependencies() : void |
91
|
|
|
{ |
92
|
|
|
$this->expectedInstallatonPath = $this->realpath(__DIR__ . '/../../asset/composer-installation-structure'); |
93
|
|
|
|
94
|
|
|
$this |
95
|
|
|
->composerInstaller |
96
|
|
|
->expects(self::once()) |
|
|
|
|
97
|
|
|
->method('run') |
98
|
|
|
->willReturnCallback(function () : void { |
99
|
|
|
self::assertSame($this->expectedInstallatonPath, getcwd()); |
100
|
|
|
}); |
101
|
|
|
|
102
|
|
|
$locator = $this |
103
|
|
|
->locateDependencies |
104
|
|
|
->__invoke($this->expectedInstallatonPath); |
105
|
|
|
|
106
|
|
|
self::assertInstanceOf(AggregateSourceLocator::class, $locator); |
107
|
|
|
|
108
|
|
|
$reflectionLocators = new ReflectionProperty(AggregateSourceLocator::class, 'sourceLocators'); |
109
|
|
|
|
110
|
|
|
$reflectionLocators->setAccessible(true); |
111
|
|
|
|
112
|
|
|
$locators = $reflectionLocators->getValue($locator); |
113
|
|
|
|
114
|
|
|
self::assertCount(2, $locators); |
115
|
|
|
self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[1]); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
private function realpath(string $path) : string |
119
|
|
|
{ |
120
|
|
|
$realPath = realpath($path); |
121
|
|
|
|
122
|
|
|
self::assertInternalType('string', $realPath); |
|
|
|
|
123
|
|
|
|
124
|
|
|
return $realPath; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.