Skip to content

Commit

Permalink
Merge pull request #1428 from mcaskill/improve-link-subcommands
Browse files Browse the repository at this point in the history
Fix link command's `--isolate` argument with custom name
  • Loading branch information
mattstauffer authored Sep 25, 2023
2 parents 2288348 + f9ee253 commit eb0bc01
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cli/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ function (ConsoleCommandEvent $event) {
info('A ['.$name.'] symbolic link has been created in ['.$linkPath.'].');

if ($secure) {
$this->runCommand('secure');
$this->runCommand('secure '.$name);
}

if ($isolate) {
if (Site::phpRcVersion($name)) {
$this->runCommand('isolate');
if (Site::phpRcVersion($name, getcwd())) {
$this->runCommand('isolate --site='.$name);
} else {
warning('Valet could not determine which PHP version to use for this site.');
}
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@
"tests/Drivers/BaseDriverTestCase.php"
]
},
"conflict": {
"mnapoli/silly": ">=1.8.1 <1.8.3"
},
"require": {
"php": "^7.1|^8.0",
"illuminate/collections": "^8.0|^9.0|^10.0",
"illuminate/container": "~5.1|^6.0|^7.0|^8.0|^9.0|^10.0",
"mnapoli/silly": "^1.0",
"mnapoli/silly": "^1.5",
"symfony/console": "^3.0|^4.0|^5.0|^6.0",
"symfony/process": "^3.0|^4.0|^5.0|^6.0",
"guzzlehttp/guzzle": "^6.0|^7.4",
Expand Down
65 changes: 65 additions & 0 deletions tests/CliTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Valet\Nginx;
use Valet\Ngrok;
use Valet\PhpFpm;
use function Valet\resolve;
use Valet\Site as RealSite;
use Valet\Valet;

Expand Down Expand Up @@ -254,6 +255,70 @@ public function test_link_command_with_secure_flag_secures()
$this->assertStringContainsString('site has been secured', $tester->getDisplay());
}

public function test_link_command_with_isolate_flag_isolates()
{
[$app, $tester] = $this->appAndTester();

$cwd = getcwd();
$name = 'tighten';
$host = $name.'.test';

$customPhpVersion = '82';
$phpRcVersion = '8.2';
$fullPhpVersion = '[email protected]';

$brewMock = Mockery::mock(Brew::class);
$nginxMock = Mockery::mock(Nginx::class);
$siteMock = Mockery::mock(RealSite::class);

$phpFpmMock = Mockery::mock(PhpFpm::class, [
$brewMock,
resolve(CommandLine::class),
resolve(Filesystem::class),
resolve(RealConfiguration::class),
$siteMock,
$nginxMock,
])->makePartial();

swap(Brew::class, $brewMock);
swap(Nginx::class, $nginxMock);
swap(PhpFpm::class, $phpFpmMock);
swap(RealSite::class, $siteMock);

$brewMock->shouldReceive('supportedPhpVersions')->andReturn(collect([
'[email protected]',
'[email protected]',
]));

$brewMock->shouldReceive('ensureInstalled')->with($fullPhpVersion, [], $phpFpmMock->taps);
$brewMock->shouldReceive('installed')->with($fullPhpVersion);
$brewMock->shouldReceive('determineAliasedVersion')->with($fullPhpVersion)->andReturn($fullPhpVersion);

$siteMock->shouldReceive('link')->with($cwd, $name)->once();
$siteMock->shouldReceive('getSiteUrl')->with($name)->andReturn($host);
$siteMock->shouldReceive('phpRcVersion')->with($name, $cwd)->andReturn($phpRcVersion);
$siteMock->shouldReceive('customPhpVersion')->with($host)->andReturn($customPhpVersion);
$siteMock->shouldReceive('isolate')->with($host, $fullPhpVersion);

$phpFpmMock->shouldReceive('stopIfUnused')->with($customPhpVersion)->once();
$phpFpmMock->shouldReceive('createConfigurationFiles')->with($fullPhpVersion)->once();
$phpFpmMock->shouldReceive('restart')->with($fullPhpVersion)->once();

$nginxMock->shouldReceive('restart')->once();

// These should only run when doing global PHP switches
$brewMock->shouldNotReceive('stopService');
$brewMock->shouldNotReceive('link');
$brewMock->shouldNotReceive('unlink');
$phpFpmMock->shouldNotReceive('stopRunning');
$phpFpmMock->shouldNotReceive('install');

$tester->run(['command' => 'link', 'name' => 'tighten', '--isolate' => true]);
$tester->assertCommandIsSuccessful();

$this->assertStringContainsString('is now using '.$fullPhpVersion, $tester->getDisplay());
}

public function test_links_command()
{
[$app, $tester] = $this->appAndTester();
Expand Down

0 comments on commit eb0bc01

Please sign in to comment.