forked from symfony/flex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateRecipesCommandTest.php
More file actions
130 lines (112 loc) · 4.69 KB
/
UpdateRecipesCommandTest.php
File metadata and controls
130 lines (112 loc) · 4.69 KB
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
127
128
129
130
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Flex\Tests\Command;
use Composer\Console\Application;
use Composer\Factory;
use Composer\IO\BufferIO;
use Composer\Plugin\PluginInterface;
use Composer\Util\Platform;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
use Symfony\Flex\Command\UpdateRecipesCommand;
use Symfony\Flex\Configurator;
use Symfony\Flex\Downloader;
use Symfony\Flex\Flex;
use Symfony\Flex\Options;
use Symfony\Flex\ParallelDownloader;
class UpdateRecipesCommandTest extends TestCase
{
private $io;
protected function setUp(): void
{
if (method_exists(Platform::class, 'putEnv')) {
Platform::putEnv('COMPOSER', FLEX_TEST_DIR.'/composer.json');
} else {
putenv('COMPOSER='.FLEX_TEST_DIR.'/composer.json');
}
}
protected function tearDown(): void
{
if (method_exists(Platform::class, 'clearEnv')) {
Platform::clearEnv('COMPOSER');
} else {
putenv('COMPOSER');
}
$filesystem = new Filesystem();
$filesystem->remove(FLEX_TEST_DIR);
}
/**
* Skip 7.1, simply because there isn't a newer recipe version available
* that we can easily use to assert.
*
* @requires PHP >= 7.2
*
* @dataProvider provideCommandInput
*/
public function testCommandUpdatesRecipe(array $input)
{
@mkdir(FLEX_TEST_DIR);
(new Process(['git', 'init'], FLEX_TEST_DIR))->mustRun();
(new Process(['git', 'config', 'user.name', 'Unit test'], FLEX_TEST_DIR))->mustRun();
(new Process(['git', 'config', 'user.email', ''], FLEX_TEST_DIR))->mustRun();
@mkdir(FLEX_TEST_DIR.'/bin');
// copy in outdated bin/console and symfony.lock set at the recipe it came from
file_put_contents(FLEX_TEST_DIR.'/bin/console', file_get_contents(__DIR__.'/../Fixtures/update_recipes/console'));
file_put_contents(FLEX_TEST_DIR.'/symfony.lock', file_get_contents(__DIR__.'/../Fixtures/update_recipes/symfony.lock'));
file_put_contents(FLEX_TEST_DIR.'/composer.json', file_get_contents(__DIR__.'/../Fixtures/update_recipes/composer.json'));
(new Process(['git', 'add', '-A'], FLEX_TEST_DIR))->mustRun();
(new Process(['git', 'commit', '-m', 'setup of original console files'], FLEX_TEST_DIR))->mustRun();
(new Process([__DIR__.'/../../vendor/bin/composer', 'install', '--no-plugins'], FLEX_TEST_DIR))->mustRun();
$command = $this->createCommandUpdateRecipes();
$command->execute($input);
$this->assertSame(0, $command->getStatusCode());
$this->assertStringContainsString('Recipe updated', $this->io->getOutput());
// assert bin/console has changed
$this->assertStringNotContainsString('vendor/autoload.php', file_get_contents(FLEX_TEST_DIR.'/bin/console'));
// assert the recipe was updated
$this->assertStringNotContainsString('c6d02bdfba9da13c22157520e32a602dbee8a75c', file_get_contents(FLEX_TEST_DIR.'/symfony.lock'));
}
public function provideCommandInput()
{
return [
[['package' => 'symfony/console']],
[['--next' => true]],
];
}
private function createCommandUpdateRecipes(): CommandTester
{
$this->io = new BufferIO();
$composer = (new Factory())->createComposer($this->io, null, false, FLEX_TEST_DIR);
$flex = new Flex();
$flex->activate($composer, $this->io);
if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '<=')) {
$rfs = Factory::createHttpDownloader($this->io, $composer->getConfig());
} else {
$rfs = Factory::createRemoteFilesystem($this->io, $composer->getConfig());
$rfs = new ParallelDownloader($this->io, $composer->getConfig(), $rfs->getOptions(), $rfs->isTlsDisabled());
}
$options = new Options(['root-dir' => FLEX_TEST_DIR, 'bin-dir' => 'bin/']);
$command = new UpdateRecipesCommand(
$flex,
new Downloader($composer, $this->io, $rfs),
$rfs,
new Configurator($composer, $this->io, $options),
FLEX_TEST_DIR
);
$command->setIO($this->io);
$command->setComposer($composer);
$application = new Application();
$application->add($command);
$command = $application->find('recipes:update');
return new CommandTester($command);
}
}