Skip to content

Commit d957430

Browse files
authored
bug #1449 [tests] fix broken assignment operator - addExtraDependencies()
1 parent 415332d commit d957430

File tree

2 files changed

+99
-6
lines changed

2 files changed

+99
-6
lines changed

src/Test/MakerTestDetails.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function changeRootNamespace(string $rootNamespace): self
7272

7373
public function addExtraDependencies(string ...$packages): self
7474
{
75-
$this->extraDependencies += $packages;
75+
$this->extraDependencies = [...$this->extraDependencies, ...$packages];
7676

7777
return $this;
7878
}
@@ -125,11 +125,11 @@ public function getDependencies(): array
125125
{
126126
$depBuilder = $this->getDependencyBuilder();
127127

128-
return array_merge(
129-
$depBuilder->getAllRequiredDependencies(),
130-
$depBuilder->getAllRequiredDevDependencies(),
131-
$this->extraDependencies
132-
);
128+
return [
129+
...$depBuilder->getAllRequiredDependencies(),
130+
...$depBuilder->getAllRequiredDevDependencies(),
131+
...$this->extraDependencies,
132+
];
133133
}
134134

135135
public function getExtraDependencies(): array

tests/Test/MakerTestDetailsTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony MakerBundle package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MakerBundle\Tests\Test;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\MakerBundle\ConsoleStyle;
16+
use Symfony\Bundle\MakerBundle\DependencyBuilder;
17+
use Symfony\Bundle\MakerBundle\Generator;
18+
use Symfony\Bundle\MakerBundle\InputConfiguration;
19+
use Symfony\Bundle\MakerBundle\MakerInterface;
20+
use Symfony\Bundle\MakerBundle\Test\MakerTestDetails;
21+
use Symfony\Component\Console\Command\Command;
22+
use Symfony\Component\Console\Input\InputInterface;
23+
use Symfony\Component\Routing\Route;
24+
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
25+
26+
class MakerTestDetailsTest extends TestCase
27+
{
28+
public function testAddExtraDependencies(): void
29+
{
30+
$details = new MakerTestDetails($this->createMock(MakerInterface::class));
31+
32+
$details->addExtraDependencies('twig');
33+
34+
self::assertSame(['twig'], $details->getExtraDependencies());
35+
36+
$details->addExtraDependencies('ux', 'mercure');
37+
38+
self::assertSame(['twig', 'ux', 'mercure'], $details->getExtraDependencies());
39+
}
40+
41+
public function testAddRequiredPackageVersions(): void
42+
{
43+
$details = new MakerTestDetails($this->createMock(MakerInterface::class));
44+
45+
$details->addRequiredPackageVersion('twig', '4.x');
46+
47+
self::assertSame([['name' => 'twig', 'version_constraint' => '4.x']], $details->getRequiredPackageVersions());
48+
49+
$details->addRequiredPackageVersion('maker', '1.x');
50+
self::assertSame([
51+
['name' => 'twig', 'version_constraint' => '4.x'],
52+
['name' => 'maker', 'version_constraint' => '1.x'],
53+
], $details->getRequiredPackageVersions());
54+
}
55+
56+
public function testGetDependencies(): void
57+
{
58+
$details = new MakerTestDetails(new TestMakerFixture());
59+
60+
$details->addExtraDependencies('twig');
61+
62+
self::assertSame(['security', 'router', 'twig'], $details->getDependencies());
63+
}
64+
}
65+
66+
/**
67+
* @method string getCommandDescription()
68+
*/
69+
class TestMakerFixture implements MakerInterface
70+
{
71+
public function configureDependencies(DependencyBuilder $dependencies): void
72+
{
73+
$dependencies->addClassDependency(Voter::class, 'security');
74+
$dependencies->addClassDependency(Route::class, 'router', devDependency: true);
75+
}
76+
77+
public static function getCommandName(): string
78+
{
79+
return 'test';
80+
}
81+
82+
public function configureCommand(Command $command, InputConfiguration $inputConfig)
83+
{
84+
}
85+
86+
public function interact(InputInterface $input, ConsoleStyle $io, Command $command)
87+
{
88+
}
89+
90+
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
91+
{
92+
}
93+
}

0 commit comments

Comments
 (0)