|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace RoaveTest\ApiCompare\LocateDependencies; |
|
6
|
|
|
|
|
7
|
|
|
use Composer\Installer; |
|
8
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use Roave\ApiCompare\LocateDependencies\LocateDependenciesViaComposer; |
|
11
|
|
|
use Roave\ApiCompare\SourceLocator\StaticClassMapSourceLocator; |
|
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 Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @covers \Roave\ApiCompare\LocateDependencies\LocateDependenciesViaComposer |
|
20
|
|
|
*/ |
|
21
|
|
|
final class LocateDependenciesViaComposerTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
private $originalCwd; |
|
25
|
|
|
|
|
26
|
|
|
/** @var Installer|MockObject */ |
|
27
|
|
|
private $composerInstaller; |
|
28
|
|
|
|
|
29
|
|
|
/** @var Locator */ |
|
30
|
|
|
private $astLocator; |
|
31
|
|
|
|
|
32
|
|
|
/** @var LocateDependenciesViaComposer */ |
|
33
|
|
|
private $locateDependencies; |
|
34
|
|
|
|
|
35
|
|
|
protected function setUp() : void |
|
36
|
|
|
{ |
|
37
|
|
|
parent::setUp(); |
|
38
|
|
|
|
|
39
|
|
|
$this->originalCwd = getcwd(); |
|
40
|
|
|
$this->composerInstaller = $this->createMock(Installer::class); |
|
41
|
|
|
$this->astLocator = (new BetterReflection())->astLocator(); |
|
42
|
|
|
|
|
43
|
|
|
$this |
|
44
|
|
|
->composerInstaller |
|
45
|
|
|
->expects(self::atLeastOnce()) |
|
46
|
|
|
->method('setDevMode') |
|
47
|
|
|
->with(false); |
|
48
|
|
|
$this |
|
49
|
|
|
->composerInstaller |
|
50
|
|
|
->expects(self::atLeastOnce()) |
|
51
|
|
|
->method('setDumpAutoloader') |
|
52
|
|
|
->with(true); |
|
53
|
|
|
$this |
|
54
|
|
|
->composerInstaller |
|
55
|
|
|
->expects(self::atLeastOnce()) |
|
56
|
|
|
->method('setRunScripts') |
|
57
|
|
|
->with(false); |
|
58
|
|
|
$this |
|
59
|
|
|
->composerInstaller |
|
60
|
|
|
->expects(self::atLeastOnce()) |
|
61
|
|
|
->method('setOptimizeAutoloader') |
|
62
|
|
|
->with(true); |
|
63
|
|
|
$this |
|
64
|
|
|
->composerInstaller |
|
65
|
|
|
->expects(self::atLeastOnce()) |
|
66
|
|
|
->method('setClassMapAuthoritative') |
|
67
|
|
|
->with(true); |
|
68
|
|
|
$this |
|
69
|
|
|
->composerInstaller |
|
70
|
|
|
->expects(self::atLeastOnce()) |
|
71
|
|
|
->method('setIgnorePlatformRequirements') |
|
72
|
|
|
->with(true); |
|
73
|
|
|
|
|
74
|
|
|
$this->locateDependencies = new LocateDependenciesViaComposer($this->composerInstaller, $this->astLocator); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
protected function tearDown() : void |
|
78
|
|
|
{ |
|
79
|
|
|
self::assertSame($this->originalCwd, getcwd()); |
|
80
|
|
|
|
|
81
|
|
|
parent::tearDown(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testWillLocateDependencies() : void |
|
85
|
|
|
{ |
|
86
|
|
|
$composerInstallationStructure = realpath(__DIR__ . '/../../asset/composer-installation-structure'); |
|
87
|
|
|
|
|
88
|
|
|
$this |
|
89
|
|
|
->composerInstaller |
|
90
|
|
|
->expects(self::once()) |
|
|
|
|
|
|
91
|
|
|
->method('run') |
|
92
|
|
|
->willReturnCallback(function () use ($composerInstallationStructure) : void { |
|
93
|
|
|
self::assertSame($composerInstallationStructure, getcwd()); |
|
94
|
|
|
}); |
|
95
|
|
|
|
|
96
|
|
|
$locator = $this |
|
97
|
|
|
->locateDependencies |
|
98
|
|
|
->__invoke($composerInstallationStructure); |
|
99
|
|
|
|
|
100
|
|
|
self::assertInstanceOf(AggregateSourceLocator::class, $locator); |
|
101
|
|
|
|
|
102
|
|
|
$reflectionLocators = new \ReflectionProperty(AggregateSourceLocator::class, 'sourceLocators'); |
|
103
|
|
|
|
|
104
|
|
|
$reflectionLocators->setAccessible(true); |
|
105
|
|
|
|
|
106
|
|
|
$locators = $reflectionLocators->getValue($locator); |
|
107
|
|
|
|
|
108
|
|
|
self::assertCount(3, $locators); |
|
109
|
|
|
self::assertEquals( |
|
110
|
|
|
new StaticClassMapSourceLocator( |
|
111
|
|
|
[ |
|
112
|
|
|
'A\\ClassName' => realpath(__DIR__ . '/../../asset/composer-installation-structure/AClassName.php'), |
|
113
|
|
|
'B\\ClassName' => realpath(__DIR__ . '/../../asset/composer-installation-structure/BClassName.php'), |
|
114
|
|
|
], |
|
115
|
|
|
$this->astLocator |
|
116
|
|
|
), |
|
117
|
|
|
$locators[0] |
|
118
|
|
|
); |
|
119
|
|
|
self::assertEquals( |
|
120
|
|
|
new AggregateSourceLocator([ |
|
121
|
|
|
new SingleFileSourceLocator( |
|
122
|
|
|
realpath(__DIR__ . '/../../asset/composer-installation-structure/included-file-1.php'), |
|
123
|
|
|
$this->astLocator |
|
124
|
|
|
), |
|
125
|
|
|
new SingleFileSourceLocator( |
|
126
|
|
|
realpath(__DIR__ . '/../../asset/composer-installation-structure/included-file-2.php'), |
|
127
|
|
|
$this->astLocator |
|
128
|
|
|
), |
|
129
|
|
|
]), |
|
130
|
|
|
$locators[1] |
|
131
|
|
|
); |
|
132
|
|
|
self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[2]); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.