Passed
Branch master (edb215)
by Tim
03:23
created

ModuleInstallerTest::testGetInstallPath()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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