-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathAppIntegrationTest.php
217 lines (177 loc) · 7.8 KB
/
AppIntegrationTest.php
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
declare(strict_types=1);
/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>,
* Pádraic Brady <padraic.brady@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Humbug\PhpScoper\Console\Command;
use Composer\InstalledVersions;
use Fidry\Console\Bridge\Application\SymfonyApplication;
use Fidry\Console\Bridge\Command\SymfonyCommand;
use Humbug\PhpScoper\Configuration\ConfigurationFactory;
use Humbug\PhpScoper\Configuration\RegexChecker;
use Humbug\PhpScoper\Configuration\SymbolsConfigurationFactory;
use Humbug\PhpScoper\Console\Application;
use Humbug\PhpScoper\Console\AppTesterAbilities;
use Humbug\PhpScoper\Console\AppTesterTestCase;
use Humbug\PhpScoper\Container;
use Humbug\PhpScoper\FileSystemTestCase;
use Humbug\PhpScoper\Scoper\Factory\DummyScoperFactory;
use Humbug\PhpScoper\Scoper\Scoper;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Group;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\Filesystem\Filesystem;
use function version_compare;
/**
* @internal
*/
#[Group('integration')]
#[CoversNothing]
class AppIntegrationTest extends FileSystemTestCase implements AppTesterTestCase
{
use AppTesterAbilities;
use ProphecyTrait;
/**
* @var ObjectProphecy<Filesystem>
*/
private ObjectProphecy $fileSystemProphecy;
/**
* @var ObjectProphecy<Scoper>
*/
private ObjectProphecy $scoperProphecy;
protected function setUp(): void
{
parent::setUp();
$this->fileSystemProphecy = $this->prophesize(Filesystem::class);
$this->scoperProphecy = $this->prophesize(Scoper::class);
$this->appTester = $this->createAppTester();
}
public function test_get_help_menu(): void
{
$input = [];
$this->scoperProphecy->scope(Argument::cetera())->shouldNotBeCalled();
$this->appTester->run($input);
$expected = self::isSymfony72OrHigher()
? <<<'EOF'
____ __ ______ _____
/ __ \/ / / / __ \ / ___/_________ ____ ___ _____
/ /_/ / /_/ / /_/ / \__ \/ ___/ __ \/ __ \/ _ \/ ___/
/ ____/ __ / ____/ ___/ / /__/ /_/ / /_/ / __/ /
/_/ /_/ /_/_/ /____/\___/\____/ .___/\___/_/
/_/
PhpScoper version TestVersion 28/01/2020
Usage:
command [options] [arguments]
Options:
-h, --help Display help for the given command. When no command is given display help for the list command
--silent Do not output any message
-q, --quiet Only errors are displayed. All other output is suppressed
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
add-prefix Goes through all the PHP files found in the given paths to apply the given prefix to namespaces & FQNs.
completion Dump the shell completion script
help Display help for a command
init Generates a configuration file.
inspect Outputs the processed file content based on the configuration.
inspect-symbol Checks the given symbol for a given configuration. Helpful to have an insight on how PHP-Scoper will interpret this symbol
list List commands
EOF
: <<<'EOF'
____ __ ______ _____
/ __ \/ / / / __ \ / ___/_________ ____ ___ _____
/ /_/ / /_/ / /_/ / \__ \/ ___/ __ \/ __ \/ _ \/ ___/
/ ____/ __ / ____/ ___/ / /__/ /_/ / /_/ / __/ /
/_/ /_/ /_/_/ /____/\___/\____/ .___/\___/_/
/_/
PhpScoper version TestVersion 28/01/2020
Usage:
command [options] [arguments]
Options:
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
add-prefix Goes through all the PHP files found in the given paths to apply the given prefix to namespaces & FQNs.
completion Dump the shell completion script
help Display help for a command
init Generates a configuration file.
inspect Outputs the processed file content based on the configuration.
inspect-symbol Checks the given symbol for a given configuration. Helpful to have an insight on how PHP-Scoper will interpret this symbol
list List commands
EOF;
$this->assertExpectedOutput($expected, 0);
$this->fileSystemProphecy
->isAbsolutePath(Argument::cetera())
->shouldNotHaveBeenCalled();
}
public function test_get_version_menu(): void
{
$input = [
'--version',
];
$this->scoperProphecy->scope(Argument::cetera())->shouldNotBeCalled();
$this->appTester->run($input);
$expected = <<<'EOF'
PhpScoper version TestVersion 28/01/2020
EOF;
$this->assertExpectedOutput($expected, 0);
$this->fileSystemProphecy
->isAbsolutePath(Argument::cetera())
->shouldNotHaveBeenCalled();
}
private function createAppTester(): ApplicationTester
{
/** @var Filesystem $fileSystem */
$fileSystem = $this->fileSystemProphecy->reveal();
/** @var Scoper $scoper */
$scoper = $this->scoperProphecy->reveal();
$application = new SymfonyApplication(
$innerApp = new Application(
new Container(),
'TestVersion',
'28/01/2020',
false,
false,
),
);
$application->add(
new SymfonyCommand(
new AddPrefixCommand(
$fileSystem,
new DummyScoperFactory($scoper),
$innerApp,
new ConfigurationFactory(
$fileSystem,
new SymbolsConfigurationFactory(
new RegexChecker(),
),
),
),
),
);
return new ApplicationTester($application);
}
private static function isSymfony72OrHigher(): bool
{
return version_compare(
(string) InstalledVersions::getPrettyVersion('symfony/console'),
'v7.2',
'>=',
);
}
}