|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\Test\Composer; |
|
6
|
|
|
|
|
7
|
|
|
use Composer\IO\NullIO; |
|
8
|
|
|
use Composer\Package\BasePackage; |
|
9
|
|
|
use Composer\Package\PackageInterface; |
|
10
|
|
|
use Composer\Config; |
|
11
|
|
|
use Composer\PartialComposer; |
|
12
|
|
|
use Composer\Repository\InstalledArrayRepository; |
|
13
|
|
|
use Composer\Repository\InstalledRepository; |
|
14
|
|
|
use Composer\Repository\PlatformRepository; |
|
15
|
|
|
use Composer\Repository\RepositoryManager; |
|
16
|
|
|
use Composer\Util\HttpDownloader; |
|
17
|
|
|
use InvalidArgumentException; |
|
18
|
|
|
use PHPUnit\Framework\TestCase; |
|
19
|
|
|
use SimpleSAML\Composer\ModuleInstaller; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @covers \SimpleSAML\Composer\ModuleInstaller |
|
23
|
|
|
*/ |
|
24
|
|
|
class ModuleInstallerTest extends TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** @var \SimpleSAML\Composer\ModuleInstaller */ |
|
27
|
|
|
private ModuleInstaller $moduleInstaller; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
*/ |
|
32
|
|
|
public function setUp(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$partialComposer = new PartialComposer(); |
|
35
|
|
|
$partialComposer->setConfig(new Config()); |
|
36
|
|
|
$partialComposer->setRepositoryManager( |
|
37
|
|
|
new RepositoryManager(new NullIO(), new Config(), new HttpDownloader(new NullIO(), new Config())) |
|
38
|
|
|
); |
|
39
|
|
|
$partialComposer->getRepositoryManager()->setLocalRepository(new InstalledArrayRepository()); |
|
40
|
|
|
$this->moduleInstaller = new ModuleInstaller(new NullIO(), $partialComposer); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @dataProvider packageProvider |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testGetInstallPath(bool $shouldPass, PackageInterface $package): void |
|
48
|
|
|
{ |
|
49
|
|
|
try { |
|
50
|
|
|
$this->moduleInstaller->getInstallPath($package); |
|
51
|
|
|
$this->assertTrue($shouldPass); |
|
52
|
|
|
} catch (InvalidArgumentException $e) { |
|
53
|
|
|
$this->assertFalse($shouldPass); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @dataProvider packageTypeProvider |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testSupports(bool $shouldPass, string $packageType): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->assertEquals( |
|
64
|
|
|
$this->moduleInstaller->supports($packageType), |
|
65
|
|
|
$shouldPass |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
public function packageTypeProvider(): array |
|
74
|
|
|
{ |
|
75
|
|
|
return [ |
|
76
|
|
|
'simplesamlphp-module' => [true, 'simplesamlphp-module'], |
|
77
|
|
|
'simplesamlphp-assets' => [true, 'simplesamlphp-assets'], |
|
78
|
|
|
'simplesamlphp-anyother' => [false, 'simplesamlphp-anyother'], |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
|
|
public function packageProvider(): array |
|
87
|
|
|
{ |
|
88
|
|
|
return [ |
|
89
|
|
|
'base' => [ |
|
90
|
|
|
true, |
|
91
|
|
|
$this->getMockForAbstractClass(BasePackage::class, ['simplesamlphp/simplesamlphp-assets']), |
|
92
|
|
|
], |
|
93
|
|
|
'bogus-nonmodule' => [ |
|
94
|
|
|
false, |
|
95
|
|
|
$this->getMockForAbstractClass(BasePackage::class, ['simplesamlphp/simplesamlphp-bogus-nonmodule']), |
|
96
|
|
|
], |
|
97
|
|
|
'consent-assets' => [ |
|
98
|
|
|
true, |
|
99
|
|
|
$this->getMockForAbstractClass(BasePackage::class, ['simplesamlphp/simplesamlphp-assets-consent']), |
|
100
|
|
|
], |
|
101
|
|
|
'ldap' => [ |
|
102
|
|
|
true, |
|
103
|
|
|
$this->getMockForAbstractClass(BasePackage::class, ['simplesamlphp/simplesamlphp-module-ldap']), |
|
104
|
|
|
], |
|
105
|
|
|
'module' => [ |
|
106
|
|
|
false, |
|
107
|
|
|
$this->getMockForAbstractClass(BasePackage::class, ['simplesamlphp/simplesamlphp-module']), |
|
108
|
|
|
], |
|
109
|
|
|
]; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|