File: RootAliasPackageTest.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 (126 lines) | stat: -rw-r--r-- 4,194 bytes parent folder | download | duplicates (2)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?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\Package;

use Composer\Package\Link;
use Composer\Package\RootAliasPackage;
use Composer\Package\RootPackage;
use Composer\Semver\Constraint\MatchAllConstraint;
use Composer\Test\TestCase;
use PHPUnit\Framework\MockObject\MockObject;

class RootAliasPackageTest extends TestCase
{
    public function testUpdateRequires(): void
    {
        $links = [new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_REQUIRE, 'self.version')];

        $root = $this->getMockRootPackage();
        $root->expects($this->once())
            ->method('setRequires')
            ->with($this->equalTo($links));

        $alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
        self::assertEmpty($alias->getRequires());
        $alias->setRequires($links);
        self::assertNotEmpty($alias->getRequires());
    }

    public function testUpdateDevRequires(): void
    {
        $links = [new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_DEV_REQUIRE, 'self.version')];

        $root = $this->getMockRootPackage();
        $root->expects($this->once())
            ->method('setDevRequires')
            ->with($this->equalTo($links));

        $alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
        self::assertEmpty($alias->getDevRequires());
        $alias->setDevRequires($links);
        self::assertNotEmpty($alias->getDevRequires());
    }

    public function testUpdateConflicts(): void
    {
        $links = [new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_CONFLICT, 'self.version')];

        $root = $this->getMockRootPackage();
        $root->expects($this->once())
            ->method('setConflicts')
            ->with($this->equalTo($links));

        $alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
        self::assertEmpty($alias->getConflicts());
        $alias->setConflicts($links);
        self::assertNotEmpty($alias->getConflicts());
    }

    public function testUpdateProvides(): void
    {
        $links = [new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_PROVIDE, 'self.version')];

        $root = $this->getMockRootPackage();
        $root->expects($this->once())
            ->method('setProvides')
            ->with($this->equalTo($links));

        $alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
        self::assertEmpty($alias->getProvides());
        $alias->setProvides($links);
        self::assertNotEmpty($alias->getProvides());
    }

    public function testUpdateReplaces(): void
    {
        $links = [new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_REPLACE, 'self.version')];

        $root = $this->getMockRootPackage();
        $root->expects($this->once())
            ->method('setReplaces')
            ->with($this->equalTo($links));

        $alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
        self::assertEmpty($alias->getReplaces());
        $alias->setReplaces($links);
        self::assertNotEmpty($alias->getReplaces());
    }

    /**
     * @return RootPackage&MockObject
     */
    protected function getMockRootPackage()
    {
        $root = $this->getMockBuilder(RootPackage::class)->disableOriginalConstructor()->getMock();
        $root->expects($this->atLeastOnce())
            ->method('getName')
            ->willReturn('something/something');
        $root->expects($this->atLeastOnce())
            ->method('getRequires')
            ->willReturn([]);
        $root->expects($this->atLeastOnce())
            ->method('getDevRequires')
            ->willReturn([]);
        $root->expects($this->atLeastOnce())
            ->method('getConflicts')
            ->willReturn([]);
        $root->expects($this->atLeastOnce())
            ->method('getProvides')
            ->willReturn([]);
        $root->expects($this->atLeastOnce())
            ->method('getReplaces')
            ->willReturn([]);

        return $root;
    }
}