File: StatusCommandTest.php

package info (click to toggle)
composer 2.8.8-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 10,716 kB
  • sloc: php: 77,384; makefile: 59; xml: 39
file content (111 lines) | stat: -rw-r--r-- 3,782 bytes parent folder | download
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
108
109
110
111
<?php declare(strict_types=1);

/*
 * This file is part of Composer.
 *
 * (c) Nils Adermann <naderman@naderman.de>
 *     Jordi Boggiano <j.boggiano@seld.be>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\Test\Command;

use Composer\Test\TestCase;
use Generator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

class StatusCommandTest extends TestCase
{
    public function testNoLocalChanges(): void
    {
        $this->initTempComposer(['require' => ['root/req' => '1.*']]);

        $package = self::getPackage('root/req');
        $package->setType('metapackage');

        $this->createComposerLock([$package], []);
        $this->createInstalledJson([$package], []);

        $appTester = $this->getApplicationTester();
        $appTester->run(['command' => 'status']);

        self::assertSame('No local changes', trim($appTester->getDisplay(true)));
    }

    /**
     * @param array<mixed> $composerJson
     * @param array<mixed> $commandFlags
     * @param array<mixed> $packageData
     */
    #[DataProvider('locallyModifiedPackagesUseCaseProvider')]
    #[Group('remote')]
    public function testLocallyModifiedPackages(
        array $composerJson,
        array $commandFlags,
        array $packageData
    ): void {
        $this->initTempComposer($composerJson);

        $package = self::getPackage($packageData['name'], $packageData['version']);
        $package->setInstallationSource($packageData['installation_source']);

        if ($packageData['installation_source'] === 'source') {
            $package->setSourceType($packageData['type']);
            $package->setSourceUrl($packageData['url']);
            $package->setSourceReference($packageData['reference']);
        }

        if ($packageData['installation_source'] === 'dist') {
            $package->setDistType($packageData['type']);
            $package->setDistUrl($packageData['url']);
            $package->setDistReference($packageData['reference']);
        }

        $this->createComposerLock([$package], []);

        $appTester = $this->getApplicationTester();
        $appTester->run(['command' => 'install']);

        file_put_contents(getcwd() . '/vendor/' . $packageData['name'] . '/composer.json', '{}');

        $appTester->run(array_merge(['command' => 'status'], $commandFlags));

        $expected = 'You have changes in the following dependencies:';
        $actual = trim($appTester->getDisplay(true));

        self::assertStringContainsString($expected, $actual);
        self::assertStringContainsString($packageData['name'], $actual);
    }

    public static function locallyModifiedPackagesUseCaseProvider(): Generator
    {
        yield 'locally modified package from source' => [
            ['require' => ['composer/class-map-generator' => '^1.0']],
            [],
            [
                'name' => 'composer/class-map-generator' ,
                'version' => '1.1',
                'installation_source' => 'source',
                'type' => 'git',
                'url' => 'https://github.com/composer/class-map-generator.git',
                'reference' => '953cc4ea32e0c31f2185549c7d216d7921f03da9'
            ]
        ];

        yield 'locally modified package from dist' => [
            ['require' => ['smarty/smarty' => '^3.1']],
            ['--verbose' => true],
            [
                'name' => 'smarty/smarty',
                'version' => '3.1.7',
                'installation_source' => 'dist',
                'type' => 'zip',
                'url' => 'https://www.smarty.net/files/Smarty-3.1.7.zip',
                'reference' => null
            ]
        ];
    }
}