1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-06 08:40:09 +01:00

Test most of the remaining CLI commands

* Test set tld command

* Test set loopback command

* Test proxy, unproxy, and proxies commands

* Apply fixes from StyleCI

* Test which command

* Test diagnose command

* Test directory-listing and which-php commands

* Text isolate and unisolate and isolated commands

* Apply fixes from StyleCI

* Test trust command

* Apply fixes from StyleCI

* Test on-latest-version command

* Move uninstall text to a class, and tweak text and presentation

* Apply fixes from StyleCI

* Test use command

* Test stop command

* Test start command

* Test restart command

Co-authored-by: StyleCI Bot <bot@styleci.io>
This commit is contained in:
Matt Stauffer
2023-01-10 23:24:01 -05:00
committed by GitHub
parent 0c57391eed
commit c4faf27525
3 changed files with 674 additions and 92 deletions

View File

@@ -98,4 +98,65 @@ public function composerGlobalUpdate(): void
{
$this->cli->runAsUser('composer global update');
}
public function forceUninstallText(): string
{
return '<fg=red>NOTE:</>
<comment>Valet has attempted to uninstall itself, but there are some steps you need to do manually:</comment>
1. Run <info>php -v</info>, and also <info>which php</info>, to see what PHP version you are now really using.
2. Run <info>composer global update</info> to update your globally-installed Composer packages to work with your default PHP.
NOTE: Composer may have other dependencies for other global apps you have installed, and those may not be compatible with your default PHP.
3. Finish removing any Composer fragments of Valet:
Run <info>composer global remove laravel/valet</info>
and then <info>rm '.BREW_PREFIX.'/bin/valet</info> to remove the Valet bin link if it still exists.
Optional:
- <info>brew list --formula</info> will show any other Homebrew services installed, in case you want to make changes to those as well.
- <info>brew doctor</info> can indicate if there might be any broken things left behind.
- <info>brew cleanup</info> can purge old cached Homebrew downloads.
If you had customized your Mac DNS settings in System Preferences->Network, you will need to remove 127.0.0.1 from that list.
You may also want to open Keychain Access and search for <comment>valet</comment> to remove any leftover trust certificates.';
}
public function uninstallText(): string
{
return '
<info>You did not pass the <fg=red>--force</> parameter, so this will only return instructions on how to uninstall, not ACTUALLY uninstall anything.
A --force removal WILL delete your custom configuration information, so be sure to make backups first.</info>
IF YOU WANT TO UNINSTALL VALET MANUALLY, DO THE FOLLOWING...
<info>1. Valet Keychain Certificates</info>
Before removing Valet configuration files, we recommend that you run <comment>valet unsecure --all</comment> to clean up the certificates that Valet inserted into your Keychain.
Alternatively you can do a search for <comment>@laravel.valet</comment> in Keychain Access and delete those certificates there manually.
<info>2. Valet Configuration Files</info>
You may remove your user-specific Valet config files by running: <comment>rm -rf ~/.config/valet</comment>
<info>3. Remove Valet package</info>
You can run <comment>composer global remove laravel/valet</comment> to uninstall the Valet package.
<info>4. Homebrew Services</info>
You may remove the core services (php, nginx, dnsmasq) by running: <comment>brew uninstall --force php nginx dnsmasq</comment>
You can then remove selected leftover configurations for these services manually in both <comment>'.BREW_PREFIX.'/etc/</comment> and <comment>'.BREW_PREFIX.'/logs/</comment>.
(If you have other PHP versions installed, run <info>brew list --formula | grep php</info> to see which versions you should also uninstall manually.)
<error>BEWARE:</error> Uninstalling PHP via Homebrew will leave your Mac with its original PHP version, which may not be compatible with other Composer dependencies you have installed. As a result, you may get unexpected errors.
If you have customized your Mac DNS settings in System Preferences->Network, you may need to add or remove 127.0.0.1 from the top of that list.
<info>5. GENERAL TROUBLESHOOTING</info>
If your reasons for considering an uninstall are more for troubleshooting purposes, consider running <comment>brew doctor</comment> and/or <comment>brew cleanup</comment> to see if any problems exist there.
Also consider running <comment>sudo nginx -t</comment> to test your nginx configs in case there are failures/errors there preventing nginx from running.
Most of the nginx configs used by Valet are in your <comment>~/.config/valet/Nginx</comment> directory.
You might also want to investigate your global Composer configs. Helpful commands include:
<comment>composer global update</comment> to apply updates to packages
<comment>composer global outdated</comment> to identify outdated packages
<comment>composer global diagnose</comment> to run diagnostics
';
}
}

View File

@@ -151,7 +151,7 @@ function (ConsoleCommandEvent $event) {
Nginx::installServer();
Nginx::restart();
info('Your valet loopback address has been updated to ['.$loopback.']');
info('Your Valet loopback address has been updated to ['.$loopback.']');
})->descriptions('Get or set the loopback address used for Valet sites');
/**
@@ -435,9 +435,11 @@ function (ConsoleCommandEvent $event) {
warning('YOU ARE ABOUT TO UNINSTALL Nginx, PHP, Dnsmasq and all Valet configs and logs.');
$helper = $this->getHelperSet()->get('question');
$question = new ConfirmationQuestion('Are you sure you want to proceed? ', false);
if (false === $helper->ask($input, $output, $question)) {
return warning('Uninstall aborted.');
}
info('Removing certificates for all Secured sites...');
Site::unsecureAll();
info('Removing Nginx and configs...');
@@ -456,61 +458,12 @@ function (ConsoleCommandEvent $event) {
Brew::removeSudoersEntry();
Valet::removeSudoersEntry();
return output('<fg=red>NOTE:</>
<comment>Valet has attempted to uninstall itself, but there are some steps you need to do manually:</comment>
Run <info>php -v</info> to see what PHP version you are now really using.
Run <info>composer global update</info> to update your globally-installed Composer packages to work with your default PHP.
NOTE: Composer may have other dependencies for other global apps you have installed, and those may not be compatible with your default PHP.
Thus, you may need to delete things from your <info>~/.composer/composer.json</info> file before running <info>composer global update</info> successfully.
Then to finish removing any Composer fragments of Valet:
Run <info>composer global remove laravel/valet</info>
and then <info>rm '.BREW_PREFIX.'/bin/valet</info> to remove the Valet bin link if it still exists.
Optional:
- <info>brew list --formula</info> will show any other Homebrew services installed, in case you want to make changes to those as well.
- <info>brew doctor</info> can indicate if there might be any broken things left behind.
- <info>brew cleanup</info> can purge old cached Homebrew downloads.
<fg=red>If you had customized your Mac DNS settings in System Preferences->Network, you will need to remove 127.0.0.1 from that list.</>
Additionally you might also want to open Keychain Access and search for <comment>valet</comment> to remove any leftover trust certificates.
');
return output(Valet::forceUninstallText());
}
output('WAIT! Before you uninstall things, consider cleaning things up in the following order. (Or skip to the bottom for troubleshooting suggestions.):
<info>You did not pass the <fg=red>--force</> parameter so we are NOT ACTUALLY uninstalling anything.</info>
A --force removal WILL delete your custom configuration information, so you will want to make backups first.
output(Valet::uninstallText());
IF YOU WANT TO UNINSTALL VALET MANUALLY, DO THE FOLLOWING...
<info>1. Valet Keychain Certificates</info>
Before removing Valet configuration files, we recommend that you run <comment>valet unsecure --all</comment> to clean up the certificates that Valet inserted into your Keychain.
Alternatively you can do a search for <comment>@laravel.valet</comment> in Keychain Access and delete those certificates there manually.
You may also run <comment>valet parked</comment> to see a list of all sites Valet could serve.
<info>2. Valet Configuration Files</info>
<fg=red>You may remove your user-specific Valet config files by running:</> <comment>rm -rf ~/.config/valet</comment>
<info>3. Remove Valet package</info>
You can run <comment>composer global remove laravel/valet</comment> to uninstall the Valet package.
<info>4. Homebrew Services</info>
<fg=red>You may remove the core services (php, nginx, dnsmasq) by running:</> <comment>brew uninstall --force php nginx dnsmasq</comment>
<fg=red>You can then remove selected leftover configurations for these services manually</> in both <comment>'.BREW_PREFIX.'/etc/</comment> and <comment>'.BREW_PREFIX.'/logs/</comment>.
(If you have other PHP versions installed, run <info>brew list --formula | grep php</info> to see which versions you should also uninstall manually.)
<error>BEWARE:</error> Uninstalling PHP via Homebrew will leave your Mac with its original PHP version, which may not be compatible with other Composer dependencies you have installed. Thus you may get unexpected errors.
<fg=red>If you have customized your Mac DNS settings in System Preferences->Network, you may need to add or remove 127.0.0.1 from the top of that list.</>
<info>5. GENERAL TROUBLESHOOTING</info>
If your reasons for considering an uninstall are more for troubleshooting purposes, consider running <comment>brew doctor</comment> and/or <comment>brew cleanup</comment> to see if any problems exist there.
Also consider running <comment>sudo nginx -t</comment> to test your nginx configs in case there are failures/errors there preventing nginx from running.
Most of the nginx configs used by Valet are in your ~/.config/valet/Nginx directory.
You might also want to investigate your global Composer configs. Helpful commands include:
<comment>composer global update</comment> to apply updates to packages
<comment>composer global outdated</comment> to identify outdated packages
<comment>composer global diagnose</comment> to run diagnostics
');
// Stopping PHP so the ~/.config/valet/valet.sock file is released so the directory can be deleted if desired
// Stop PHP so the ~/.config/valet/valet.sock file is released so the directory can be deleted if desired
PhpFpm::stopRunning();
Nginx::stop();
})->descriptions('Uninstall the Valet services', ['--force' => 'Do a forceful uninstall of Valet and related Homebrew pkgs']);
@@ -574,7 +527,7 @@ function (ConsoleCommandEvent $event) {
PhpFpm::useVersion($phpVersion, $force);
})->descriptions('Change the version of PHP used by Valet', [
'phpVersion' => 'The PHP version you want to use, e.g php@7.3',
'phpVersion' => 'The PHP version you want to use; e.g php@8.2',
]);
/**
@@ -591,7 +544,8 @@ function (ConsoleCommandEvent $event) {
} else {
info(PHP_EOL.'Please provide a version number. E.g.:');
info('valet isolate php@8.2');
exit;
return;
}
}

View File

@@ -2,11 +2,16 @@
use Valet\Brew;
use Valet\CommandLine;
use Valet\Configuration as RealConfiguration;
use Valet\Diagnose;
use Valet\DnsMasq;
use Valet\Filesystem;
use Valet\Nginx;
use Valet\Ngrok;
use Valet\PhpFpm;
use Valet\Site as RealSite;
use function Valet\swap;
use Valet\Valet;
/**
* @requires PHP >= 8.0
@@ -26,14 +31,35 @@ public function test_tld_command_reads_tld()
public function test_tld_command_sets_tld()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
// [$app, $tester] = $this->appAndTester();
$tester->setInputs(['Y']);
// @todo: Mock DnsMasq, Site, PhpFpm, Nginx, Configuration...
// $tester->setInputs(['Y']);
// $tester->run(['command' => 'tld', 'tld' => 'buzz']);
// $tester->assertCommandIsSuccessful();
$dnsmasq = Mockery::mock(DnsMasq::class);
$dnsmasq->shouldReceive('updateTld')->with('old', 'buzz')->once();
$config = Mockery::mock(RealConfiguration::class);
$config->shouldReceive('read')->andReturn(['tld' => 'old'])->once();
$config->shouldReceive('updateKey')->with('tld', 'buzz')->once();
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('resecureForNewConfiguration')->with(['tld' => 'old'], ['tld' => 'buzz'])->once();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('restart')->once();
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('restart')->once();
swap(DnsMasq::class, $dnsmasq);
swap(RealConfiguration::class, $config);
swap(RealSite::class, $site);
swap(PhpFpm::class, $phpfpm);
swap(Nginx::class, $nginx);
$tester->run(['command' => 'tld', 'tld' => 'buzz']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Your Valet TLD has been updated to [buzz]', $tester->getDisplay());
}
public function test_loopback_command_reads_loopback()
@@ -48,13 +74,35 @@ public function test_loopback_command_reads_loopback()
public function test_loopback_command_sets_loopback()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
// @todo: Mock everything...
// [$app, $tester] = $this->appAndTester();
$config = Mockery::mock(RealConfiguration::class);
$config->shouldReceive('read')->andReturn(['loopback' => '127.9.9.9'])->once();
$config->shouldReceive('updateKey')->with('loopback', '127.0.0.1')->once();
// $tester->run(['command' => 'loopback', 'loopback' => '127.0.0.9']);
// $tester->assertCommandIsSuccessful();
$dnsmasq = Mockery::mock(DnsMasq::class);
$dnsmasq->shouldReceive('refreshConfiguration')->once();
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('aliasLoopback')->with('127.9.9.9', '127.0.0.1')->once();
$site->shouldReceive('resecureForNewConfiguration')->with(['loopback' => '127.9.9.9'], ['loopback' => '127.0.0.1'])->once();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('restart')->once();
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('installServer')->once();
$nginx->shouldReceive('restart')->once();
swap(RealConfiguration::class, $config);
swap(DnsMasq::class, $dnsmasq);
swap(RealSite::class, $site);
swap(PhpFpm::class, $phpfpm);
swap(Nginx::class, $nginx);
$tester->run(['command' => 'loopback', 'loopback' => '127.0.0.1']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Your Valet loopback address has been updated to [127.0.0.1]', $tester->getDisplay());
}
public function test_park_command()
@@ -99,7 +147,7 @@ public function test_status_command_succeeding()
$tester->run(['command' => 'status']);
// $tester->assertCommandIsSuccessful();
$tester->assertCommandIsSuccessful();
$this->assertStringNotContainsString('False', $tester->getDisplay());
}
@@ -298,22 +346,63 @@ public function test_secured_command()
public function test_proxy_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('proxyCreate')->with('elasticsearch', 'http://127.0.0.1:9200', false)->once();
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('restart')->once();
swap(Nginx::class, $nginx);
swap(RealSite::class, $site);
$tester->run(['command' => 'proxy', 'domain' => 'elasticsearch', 'host' => 'http://127.0.0.1:9200']);
$tester->assertCommandIsSuccessful();
}
public function test_unproxy_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('proxyDelete')->with('elasticsearch')->once();
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('restart')->once();
swap(Nginx::class, $nginx);
swap(RealSite::class, $site);
$tester->run(['command' => 'unproxy', 'domain' => 'elasticsearch']);
$tester->assertCommandIsSuccessful();
}
public function test_proxies_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('proxies')->andReturn(collect([
['site' => 'elasticsearch', 'secured' => 'X', 'url' => 'https://elasticsearch.test/', 'host' => 'http://127.0.0.1:9200'],
]));
swap(RealSite::class, $site);
$tester->run(['command' => 'proxies']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('elasticsearch', $tester->getDisplay());
}
public function test_which_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$tester->run(['command' => 'which']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('served by [', $tester->getDisplay());
}
public function test_paths_command()
@@ -357,59 +446,511 @@ public function test_set_ngrok_token_command()
$tester->assertCommandIsSuccessful();
}
public function test_start_command()
{
$this->markTestIncomplete();
}
public function test_restart_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$dnsmasq = Mockery::mock(DnsMasq::class);
$dnsmasq->shouldReceive('restart')->once();
swap(DnsMasq::class, $dnsmasq);
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('restart')->once();
swap(PhpFpm::class, $phpfpm);
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('restart')->once();
swap(Nginx::class, $nginx);
$tester->run(['command' => 'restart']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Valet services have been restarted.', $tester->getDisplay());
}
public function test_restart_command_restarts_dnsmasq()
{
[$app, $tester] = $this->appAndTester();
$dnsmasq = Mockery::mock(DnsMasq::class);
$dnsmasq->shouldReceive('restart')->once();
swap(DnsMasq::class, $dnsmasq);
$tester->run(['command' => 'restart', 'service' => 'dnsmasq']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('dnsmasq has been restarted.', $tester->getDisplay());
}
public function test_restart_command_restarts_nginx()
{
[$app, $tester] = $this->appAndTester();
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('restart')->once();
swap(Nginx::class, $nginx);
$tester->run(['command' => 'restart', 'service' => 'nginx']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Nginx has been restarted.', $tester->getDisplay());
}
public function test_restart_command_restarts_php()
{
[$app, $tester] = $this->appAndTester();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('restart')->once();
swap(PhpFpm::class, $phpfpm);
$tester->run(['command' => 'restart', 'service' => 'php']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('PHP has been restarted.', $tester->getDisplay());
}
public function test_start_command()
{
[$app, $tester] = $this->appAndTester();
$dnsmasq = Mockery::mock(DnsMasq::class);
$dnsmasq->shouldReceive('restart')->once();
swap(DnsMasq::class, $dnsmasq);
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('restart')->once();
swap(PhpFpm::class, $phpfpm);
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('restart')->once();
swap(Nginx::class, $nginx);
$tester->run(['command' => 'start']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Valet services have been started.', $tester->getDisplay());
}
public function test_start_command_starts_dnsmasq()
{
[$app, $tester] = $this->appAndTester();
$dnsmasq = Mockery::mock(DnsMasq::class);
$dnsmasq->shouldReceive('restart')->once();
swap(DnsMasq::class, $dnsmasq);
$tester->run(['command' => 'start', 'service' => 'dnsmasq']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('dnsmasq has been started.', $tester->getDisplay());
}
public function test_start_command_starts_nginx()
{
[$app, $tester] = $this->appAndTester();
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('restart')->once();
swap(Nginx::class, $nginx);
$tester->run(['command' => 'start', 'service' => 'nginx']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Nginx has been started.', $tester->getDisplay());
}
public function test_start_command_starts_php()
{
[$app, $tester] = $this->appAndTester();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('restart')->once();
swap(PhpFpm::class, $phpfpm);
$tester->run(['command' => 'start', 'service' => 'php']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('PHP has been started.', $tester->getDisplay());
}
public function test_stop_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('stop');
swap(Nginx::class, $nginx);
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('stopRunning');
swap(PhpFpm::class, $phpfpm);
$tester->run(['command' => 'stop']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Valet services have been stopped.', $tester->getDisplay());
}
public function test_uninstall_command()
public function test_stop_command_stops_nginx()
{
[$app, $tester] = $this->appAndTester();
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('stop');
swap(Nginx::class, $nginx);
$tester->run(['command' => 'stop', 'service' => 'nginx']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Nginx has been stopped', $tester->getDisplay());
}
public function test_stop_command_stops_php()
{
[$app, $tester] = $this->appAndTester();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('stopRunning');
swap(PhpFpm::class, $phpfpm);
$tester->run(['command' => 'stop', 'service' => 'php']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('PHP has been stopped', $tester->getDisplay());
}
public function test_stop_command_handles_bad_services()
{
[$app, $tester] = $this->appAndTester();
$tester->run(['command' => 'stop', 'service' => 'not-real-services']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Invalid valet service', $tester->getDisplay());
}
public function test_non_force_uninstall_command()
{
[$app, $tester] = $this->appAndTester();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('stopRunning');
swap(PhpFpm::class, $phpfpm);
$nginx = Mockery::mock(Nginx::class);
$nginx->shouldReceive('stop');
swap(Nginx::class, $nginx);
$tester->run(['command' => 'uninstall']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('IF YOU WANT TO UNINSTALL VALET MANUALLY', $tester->getDisplay());
}
public function test_force_uninstall_command()
{
$this->markTestIncomplete();
}
public function test_trust_command()
public function test_on_latest_version_command_succeeding()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$valet = Mockery::mock(Valet::class);
$valet->shouldReceive('onLatestVersion')->once()->andReturn(true);
swap(Valet::class, $valet);
$tester->run(['command' => 'on-latest-version']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Yes', $tester->getDisplay());
}
public function test_on_latest_version_command_failing()
{
[$app, $tester] = $this->appAndTester();
$valet = Mockery::mock(Valet::class);
$valet->shouldReceive('onLatestVersion')->once()->andReturn(false);
swap(Valet::class, $valet);
$tester->run(['command' => 'on-latest-version']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('not the latest', $tester->getDisplay());
}
public function test_trust_command_on()
{
[$app, $tester] = $this->appAndTester();
$brew = Mockery::mock(Brew::class);
$brew->shouldReceive('createSudoersEntry')->once();
swap(Brew::class, $brew);
$valet = Mockery::mock(Valet::class);
$valet->shouldReceive('createSudoersEntry')->once();
swap(Valet::class, $valet);
$tester->run(['command' => 'trust']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('have been added', $tester->getDisplay());
}
public function test_trust_command_off()
{
[$app, $tester] = $this->appAndTester();
$brew = Mockery::mock(Brew::class);
$brew->shouldReceive('removeSudoersEntry')->once();
swap(Brew::class, $brew);
$valet = Mockery::mock(Valet::class);
$valet->shouldReceive('removeSudoersEntry')->once();
swap(Valet::class, $valet);
$tester->run(['command' => 'trust', '--off' => true]);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('have been removed', $tester->getDisplay());
}
public function test_use_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('useVersion')->with('8.2', false);
swap(PhpFpm::class, $phpfpm);
$tester->run(['command' => 'use', 'phpVersion' => '8.2']);
$tester->assertCommandIsSuccessful();
}
public function test_use_command_without_specified_version_reads_phprc()
{
[$app, $tester] = $this->appAndTester();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('useVersion')->with('php@8.1', false);
swap(PhpFpm::class, $phpfpm);
$brew = Mockery::mock(Brew::class);
$brew->shouldReceive('linkedPhp')->andReturn('php@8.2');
swap(Brew::class, $brew);
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('phpRcVersion')->andReturn('php@8.1');
swap(RealSite::class, $site);
$tester->run(['command' => 'use']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString(".valetphprc' specifying version: php@8.1", $tester->getDisplay());
}
public function test_use_command_without_specified_version_reads_isolation_list()
{
[$app, $tester] = $this->appAndTester();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('useVersion')->with('php@8.0', false);
$phpfpm->shouldReceive('normalizePhpVersion')->with('php@8.0')->andReturn('php@8.0');
swap(PhpFpm::class, $phpfpm);
$brew = Mockery::mock(Brew::class);
$brew->shouldReceive('linkedPhp')->andReturn('php@8.2');
swap(Brew::class, $brew);
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('phpRcVersion')->andReturn(null);
$site->shouldReceive('customPhpVersion')->andReturn('php@8.0');
swap(RealSite::class, $site);
$tester->run(['command' => 'use']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('isolated site', $tester->getDisplay());
}
public function test_use_command_with_no_specifications()
{
[$app, $tester] = $this->appAndTester();
$brew = Mockery::mock(Brew::class);
$brew->shouldReceive('linkedPhp')->andReturn('php@8.2');
swap(Brew::class, $brew);
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('phpRcVersion')->andReturn(null);
$site->shouldReceive('customPhpVersion')->andReturn(null);
swap(RealSite::class, $site);
$tester->run(['command' => 'use']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Valet is using php@8.2', $tester->getDisplay());
}
public function test_isolate_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
// The site this command should assume we're in if we don't pass in --site
$getcwd = 'valet';
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('isolateDirectory')->with($getcwd, '8.1');
swap(PhpFpm::class, $phpfpm);
$tester->run(['command' => 'isolate', 'phpVersion' => '8.1']);
$tester->assertCommandIsSuccessful();
}
public function test_isolate_command_with_phprc()
{
[$app, $tester] = $this->appAndTester();
// The site this command should assume we're in if we don't pass in --site
$getcwd = 'valet';
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('isolateDirectory')->with($getcwd, '8.2');
swap(PhpFpm::class, $phpfpm);
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('phpRcVersion')->once()->andReturn('8.2');
swap(RealSite::class, $site);
$tester->run(['command' => 'isolate']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('specifying version', $tester->getDisplay());
}
public function test_unisolate_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
// The site this command should assume we're in if we don't pass in --site
$getcwd = 'valet';
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('unisolateDirectory')->with($getcwd)->once();
swap(PhpFpm::class, $phpfpm);
$tester->run(['command' => 'unisolate']);
$tester->assertCommandIsSuccessful();
}
public function test_unisolate_command_with_custom_site()
{
[$app, $tester] = $this->appAndTester();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('unisolateDirectory')->with('my-best-site');
swap(PhpFpm::class, $phpfpm);
$tester->run(['command' => 'unisolate', '--site' => 'my-best-site']);
$tester->assertCommandIsSuccessful();
}
public function test_isolated_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$phpfpm = Mockery::mock(PhpFpm::class);
$phpfpm->shouldReceive('isolatedDirectories')->andReturn(collect([['best-directory', '8.1']]));
swap(PhpFpm::class, $phpfpm);
$tester->run(['command' => 'isolated']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('best-directory', $tester->getDisplay());
}
public function test_which_php_command()
public function test_which_php_command_reads_nginx()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('host')->once()->andReturn('whatever');
$site->shouldReceive('customPhpVersion')->once()->andReturn('8.2');
swap(RealSite::class, $site);
$brew = Mockery::mock(Brew::class);
$brew->shouldReceive('getPhpExecutablePath')->with('8.2')->once()->andReturn('testOutput');
swap(Brew::class, $brew);
$tester->run(['command' => 'which-php']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('testOutput', $tester->getDisplay());
}
public function test_composer_command()
public function test_which_php_command_reads_phprc()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$site = Mockery::mock(RealSite::class);
$site->shouldReceive('host')->once()->andReturn('whatever');
$site->shouldReceive('customPhpVersion')->once()->andReturn(null);
$site->shouldReceive('phpRcVersion')->once()->andReturn('8.1');
swap(RealSite::class, $site);
$brew = Mockery::mock(Brew::class);
$brew->shouldReceive('getPhpExecutablePath')->with('8.1')->once()->andReturn('testOutput');
swap(Brew::class, $brew);
$tester->run(['command' => 'which-php']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('testOutput', $tester->getDisplay());
}
public function test_log_command()
@@ -417,13 +958,39 @@ public function test_log_command()
$this->markTestIncomplete();
}
public function test_directory_listing_command()
public function test_directory_listing_command_reads()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
Configuration::updateKey('directory-listing', 'off');
$tester->run(['command' => 'directory-listing']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Directory listing is off', $tester->getDisplay());
}
public function test_directory_listing_command_sets()
{
[$app, $tester] = $this->appAndTester();
Configuration::updateKey('directory-listing', 'off');
$tester->run(['command' => 'directory-listing', 'status' => 'on']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Directory listing setting is now: on', $tester->getDisplay());
}
public function test_diagnose_command()
{
$this->markTestIncomplete();
[$app, $tester] = $this->appAndTester();
$diagnose = Mockery::mock(Diagnose::class);
$diagnose->shouldReceive('run')->with(false, false);
swap(Diagnose::class, $diagnose);
$tester->run(['command' => 'diagnose']);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('Diagnostics output', $tester->getDisplay());
}
}