-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathInstallCommandTest.php
More file actions
140 lines (115 loc) · 4.55 KB
/
Copy pathInstallCommandTest.php
File metadata and controls
140 lines (115 loc) · 4.55 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
131
132
133
134
135
136
137
138
139
140
<?php
declare(strict_types=1);
namespace Php\PieIntegrationTest\Command;
use Composer\Util\Platform;
use Php\Pie\Command\InstallCommand;
use Php\Pie\Container;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Process\Process;
use function array_combine;
use function array_filter;
use function array_key_exists;
use function array_map;
use function array_unshift;
use function file_exists;
use function is_executable;
use function is_writable;
use function Safe\preg_match;
#[CoversClass(InstallCommand::class)]
class InstallCommandTest extends IsolatedWorkingDirectoryTestCase
{
private const TEST_PACKAGE = 'asgrim/example-pie-extension';
private CommandTester $commandTester;
private string|null $lastInstalledBinary = null;
public function setUp(): void
{
parent::setUp();
$this->commandTester = new CommandTester(Container::testFactory()->get(InstallCommand::class));
}
protected function tearDown(): void
{
if ($this->lastInstalledBinary !== null && file_exists($this->lastInstalledBinary)) {
$rmCommand = ['rm', $this->lastInstalledBinary];
if (! is_writable($this->lastInstalledBinary)) {
array_unshift($rmCommand, 'sudo');
}
(new Process($rmCommand))->run();
}
parent::tearDown();
}
/** @return array<string, array{0: string}> */
public static function phpPathProvider(): array
{
// data providers cannot return empty, even if the test is skipped
if (Platform::isWindows()) {
return ['skip' => ['skip']];
}
$possiblePhpConfigPaths = array_filter(
[
'/usr/bin/php-config',
'/usr/bin/php-config8.5',
'/usr/bin/php-config8.4',
'/usr/bin/php-config8.3',
'/usr/bin/php-config8.2',
'/usr/bin/php-config8.1',
'/usr/bin/php-config8.0',
'/usr/bin/php-config7.4',
'/usr/local/bin/php-config',
],
static fn (string $phpConfigPath) => file_exists($phpConfigPath)
&& is_executable($phpConfigPath),
);
return array_combine(
$possiblePhpConfigPaths,
array_map(static fn (string $phpConfigPath) => [$phpConfigPath], $possiblePhpConfigPaths),
);
}
#[DataProvider('phpPathProvider')]
public function testInstallCommandWillInstallCompatibleExtensionNonWindows(string $phpConfigPath): void
{
if (Platform::isWindows()) {
self::markTestSkipped('This test can only run on non-Windows systems');
}
$this->commandTester->execute(
[
'requested-package-and-version' => [self::TEST_PACKAGE],
'--with-php-config' => $phpConfigPath,
'--skip-enable-extension' => true,
],
['verbosity' => BufferedOutput::VERBOSITY_VERY_VERBOSE],
);
$this->commandTester->assertCommandIsSuccessful();
$outputString = $this->commandTester->getDisplay();
if (
preg_match('#^Install complete: (.*)$#m', $outputString, $matches)
&& array_key_exists(1, $matches)
&& $matches[1] !== ''
) {
$this->lastInstalledBinary = $matches[1];
}
self::assertStringContainsString('Install complete: ', $outputString);
self::assertStringContainsString('You must now add "extension=example_pie_extension" to your php.ini', $outputString);
}
#[RequiresOperatingSystemFamily('Windows')]
public function testInstallCommandWillInstallCompatibleExtensionWindows(): void
{
$this->commandTester->execute([
'requested-package-and-version' => [self::TEST_PACKAGE],
'--skip-enable-extension' => true,
]);
$this->commandTester->assertCommandIsSuccessful();
$outputString = $this->commandTester->getDisplay();
if (
preg_match('#^Copied DLL to: (.*)$#m', $outputString, $matches)
&& array_key_exists(1, $matches)
&& $matches[1] !== ''
) {
$this->lastInstalledBinary = $matches[1];
}
self::assertStringContainsString('Copied DLL to: ', $outputString);
self::assertStringContainsString('You must now add "extension=example_pie_extension" to your php.ini', $outputString);
}
}