Skip to content

Commit 40fd06a

Browse files
committed
692: suppress warning about INI setup if --skip-enable-extension was supplied
1 parent e09b381 commit 40fd06a

4 files changed

Lines changed: 141 additions & 8 deletions

File tree

src/Installing/SetupIniFile.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ public function __invoke(
3939
$downloadedPackage->package->prettyNameAndVersion(),
4040
$targetPlatform->phpBinaryPath->phpBinaryPath,
4141
));
42+
} elseif (! $attemptToSetupIniFile) {
43+
$io->write('Automatic extension enabling was skipped.', verbosity: IOInterface::VERBOSE);
4244
} else {
43-
if (! $attemptToSetupIniFile) {
44-
$io->write('Automatic extension enabling was skipped.', verbosity: IOInterface::VERY_VERBOSE);
45-
}
46-
4745
$io->write(sprintf('<comment>%s Extension has NOT been automatically enabled.</comment>', Emoji::WARNING));
4846
$io->write(sprintf(
4947
'<comment>You must now add "%s=%s" to your php.ini</comment>',

test/behaviour/CliContext.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public function iRunACommandToForcefullyInstallAnExtension(): void
250250
public function iRunACommandToInstallAnExtensionWithoutEnabling(): void
251251
{
252252
$this->interactions[] = ['extension' => 'example_pie_extension', 'package' => 'asgrim/example-pie-extension'];
253-
$this->runPieCommand(['install', 'asgrim/example-pie-extension', '--skip-enable-extension']);
253+
$this->runPieCommand(['install', 'asgrim/example-pie-extension', '--skip-enable-extension', '-v']);
254254
}
255255

256256
#[When('I run a command to uninstall an extension')]
@@ -297,7 +297,9 @@ public function theExtensionShouldHaveBeenInstalled(): void
297297
{
298298
$this->assertCommandSuccessful();
299299

300-
Assert::contains($this->output, 'Extension has NOT been automatically enabled.');
300+
Assert::contains($this->output, 'Automatic extension enabling was skipped.');
301+
Assert::notContains($this->output, 'Extension has NOT been automatically enabled.');
302+
Assert::notContains($this->output, 'You must now add');
301303

302304
foreach ($this->interactions as $install) {
303305
if (Platform::isWindows()) {

test/integration/Command/InstallCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function testInstallCommandWillInstallCompatibleExtensionNonWindows(strin
111111
}
112112

113113
self::assertStringContainsString('Install complete: ', $outputString);
114-
self::assertStringContainsString('You must now add "extension=example_pie_extension" to your php.ini', $outputString);
114+
self::assertStringNotContainsString('You must now add "extension=example_pie_extension" to your php.ini', $outputString);
115115
}
116116

117117
#[RequiresOperatingSystemFamily('Windows')]
@@ -135,6 +135,6 @@ public function testInstallCommandWillInstallCompatibleExtensionWindows(): void
135135
}
136136

137137
self::assertStringContainsString('Copied DLL to: ', $outputString);
138-
self::assertStringContainsString('You must now add "extension=example_pie_extension" to your php.ini', $outputString);
138+
self::assertStringNotContainsString('You must now add "extension=example_pie_extension" to your php.ini', $outputString);
139139
}
140140
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Php\PieUnitTest\Installing;
6+
7+
use Composer\IO\BufferIO;
8+
use Composer\Package\CompletePackageInterface;
9+
use Php\Pie\DependencyResolver\Package;
10+
use Php\Pie\Downloading\DownloadedPackage;
11+
use Php\Pie\ExtensionName;
12+
use Php\Pie\ExtensionType;
13+
use Php\Pie\File\BinaryFile;
14+
use Php\Pie\Installing\Ini\SetupIniApproach;
15+
use Php\Pie\Installing\SetupIniFile;
16+
use Php\Pie\Platform\Architecture;
17+
use Php\Pie\Platform\OperatingSystem;
18+
use Php\Pie\Platform\OperatingSystemFamily;
19+
use Php\Pie\Platform\TargetPhp\PhpBinaryPath;
20+
use Php\Pie\Platform\TargetPlatform;
21+
use Php\Pie\Platform\ThreadSafetyMode;
22+
use PHPUnit\Framework\Attributes\CoversClass;
23+
use PHPUnit\Framework\TestCase;
24+
use Symfony\Component\Console\Output\StreamOutput;
25+
26+
#[CoversClass(SetupIniFile::class)]
27+
final class SetupIniFileTest extends TestCase
28+
{
29+
private DownloadedPackage $downloadedPackage;
30+
private BinaryFile $binaryFile;
31+
private TargetPlatform $targetPlatform;
32+
33+
protected function setUp(): void
34+
{
35+
parent::setUp();
36+
37+
$package = new Package(
38+
$this->createMock(CompletePackageInterface::class),
39+
ExtensionType::PhpModule,
40+
ExtensionName::normaliseFromString('xdebug'),
41+
'foo/bar',
42+
'1.2.3',
43+
null,
44+
);
45+
46+
$this->downloadedPackage = DownloadedPackage::fromPackageAndExtractedPath($package, __DIR__);
47+
$this->binaryFile = new BinaryFile(__FILE__, 'abc123');
48+
49+
$phpBinaryPath = $this->createMock(PhpBinaryPath::class);
50+
/** @phpstan-ignore property.notFound */
51+
(fn () => $this->phpBinaryPath = '/usr/bin/php')
52+
->bindTo($phpBinaryPath, PhpBinaryPath::class)();
53+
54+
$this->targetPlatform = new TargetPlatform(
55+
OperatingSystem::NonWindows,
56+
OperatingSystemFamily::Linux,
57+
$phpBinaryPath,
58+
Architecture::x86_64,
59+
ThreadSafetyMode::NonThreadSafe,
60+
1,
61+
null,
62+
null,
63+
);
64+
}
65+
66+
public function testSuccessfulSetupPrintsEnabledMessage(): void
67+
{
68+
$setupIniApproach = $this->createMock(SetupIniApproach::class);
69+
$setupIniApproach->method('canBeUsed')->willReturn(true);
70+
$setupIniApproach->method('setup')->willReturn(true);
71+
72+
$io = new BufferIO();
73+
74+
(new SetupIniFile($setupIniApproach))(
75+
$this->targetPlatform,
76+
$this->downloadedPackage,
77+
$this->binaryFile,
78+
$io,
79+
true,
80+
);
81+
82+
$output = $io->getOutput();
83+
84+
self::assertStringContainsString('is enabled and loaded in', $output);
85+
self::assertStringNotContainsString('Extension has NOT been automatically enabled.', $output);
86+
self::assertStringNotContainsString('Automatic extension enabling was skipped.', $output);
87+
}
88+
89+
public function testDeliberateSkipDoesNotPrintWarning(): void
90+
{
91+
$setupIniApproach = $this->createMock(SetupIniApproach::class);
92+
$setupIniApproach->expects(self::never())->method('canBeUsed');
93+
$setupIniApproach->expects(self::never())->method('setup');
94+
95+
$io = new BufferIO('', StreamOutput::VERBOSITY_VERBOSE);
96+
97+
(new SetupIniFile($setupIniApproach))(
98+
$this->targetPlatform,
99+
$this->downloadedPackage,
100+
$this->binaryFile,
101+
$io,
102+
false,
103+
);
104+
105+
$output = $io->getOutput();
106+
107+
self::assertStringContainsString('Automatic extension enabling was skipped.', $output);
108+
self::assertStringNotContainsString('Extension has NOT been automatically enabled.', $output);
109+
self::assertStringNotContainsString('You must now add', $output);
110+
}
111+
112+
public function testAttemptedButFailedSetupPrintsWarning(): void
113+
{
114+
$setupIniApproach = $this->createMock(SetupIniApproach::class);
115+
$setupIniApproach->method('canBeUsed')->willReturn(false);
116+
117+
$io = new BufferIO();
118+
119+
(new SetupIniFile($setupIniApproach))(
120+
$this->targetPlatform,
121+
$this->downloadedPackage,
122+
$this->binaryFile,
123+
$io,
124+
true,
125+
);
126+
127+
$output = $io->getOutput();
128+
129+
self::assertStringContainsString('Extension has NOT been automatically enabled.', $output);
130+
self::assertStringContainsString('You must now add "extension=xdebug" to your php.ini', $output);
131+
self::assertStringNotContainsString('Automatic extension enabling was skipped.', $output);
132+
}
133+
}

0 commit comments

Comments
 (0)