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

Merging master.

This commit is contained in:
Mikaël Popowicz
2020-11-30 09:45:11 +01:00
17 changed files with 245 additions and 306 deletions

View File

@@ -9,193 +9,99 @@
use Illuminate\Support\Collection;
use Illuminate\Container\Container;
class BrewTest extends PHPUnit_Framework_TestCase
class BrewTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
public function setUp()
public function set_up()
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
public function tearDown()
public function tear_down()
{
Mockery::close();
}
public function test_brew_can_be_resolved_from_container()
{
$this->assertInstanceOf(Brew::class, resolve(Brew::class));
}
public function test_installed_returns_true_when_given_formula_is_installed()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->with('brew list --formula | grep php@7.4')->andReturn('php@7.4');
$cli->shouldReceive('runAsUser')->once()->with('brew info php@7.4 --json')
->andReturn('[{"name":"php@7.4","full_name":"php@7.4","aliases":[],"versioned_formulae":[],"versions":{"stable":"7.4.5"},"installed":[{"version":"7.4.5"}]}]');
swap(CommandLine::class, $cli);
$this->assertTrue(resolve(Brew::class)->installed('php@7.4'));
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->with('brew list --formula | grep php')->andReturn('php
php@7.4');
$cli->shouldReceive('runAsUser')->once()->with('brew info php --json')
->andReturn('[{"name":"php","full_name":"php","aliases":["php@8.0"],"versioned_formulae":[],"versions":{"stable":"8.0.0"},"installed":[{"version":"8.0.0"}]}]');
swap(CommandLine::class, $cli);
$this->assertTrue(resolve(Brew::class)->installed('php'));
}
public function test_installed_returns_false_when_given_formula_is_not_installed()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->with('brew list --formula | grep php@7.4')->andReturn('');
$cli->shouldReceive('runAsUser')->once()->with('brew info php@7.4 --json')->andReturn('');
swap(CommandLine::class, $cli);
$this->assertFalse(resolve(Brew::class)->installed('php@7.4'));
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->with('brew list --formula | grep php@7.4')->andReturn('php');
swap(CommandLine::class, $cli);
$this->assertFalse(resolve(Brew::class)->installed('php@7.4'));
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->with('brew list --formula | grep php@7.4')->andReturn('php
something-else-php@7.4
php7');
$cli->shouldReceive('runAsUser')->once()->with('brew info php@7.4 --json')->andReturn('Error: No formula found');
swap(CommandLine::class, $cli);
$this->assertFalse(resolve(Brew::class)->installed('php@7.4'));
}
public function test_has_installed_php_indicates_if_php_is_installed_via_brew()
{
$brew = Mockery::mock(Brew::class.'[installed]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installed')->with('php')->andReturn(true);
$brew->shouldReceive('installed')->with('php@8.1')->andReturn(true);
$brew->shouldReceive('installed')->with('php@8.0')->andReturn(true);
$brew->shouldReceive('installed')->with('php@7.4')->andReturn(true);
$brew->shouldReceive('installed')->with('php@7.3')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.2')->andReturn(true);
$brew->shouldReceive('installed')->with('php@7.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@5.6')->andReturn(false);
$brew->shouldReceive('installed')->with('php74')->andReturn(true);
$brew->shouldReceive('installed')->with('php73')->andReturn(false);
$brew->shouldReceive('installed')->with('php72')->andReturn(false);
$brew->shouldReceive('installed')->with('php71')->andReturn(false);
$brew->shouldReceive('installed')->with('php70')->andReturn(false);
$brew->shouldReceive('installed')->with('php56')->andReturn(false);
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installed]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installed')->with('php')->andReturn(true);
$brew->shouldReceive('installed')->with('php@8.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@8.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.4')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.3')->andReturn(true);
$brew->shouldReceive('installed')->with('php@7.2')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@5.6')->andReturn(false);
$brew->shouldReceive('installed')->with('php74')->andReturn(false);
$brew->shouldReceive('installed')->with('php73')->andReturn(true);
$brew->shouldReceive('installed')->with('php72')->andReturn(false);
$brew->shouldReceive('installed')->with('php71')->andReturn(false);
$brew->shouldReceive('installed')->with('php70')->andReturn(false);
$brew->shouldReceive('installed')->with('php56')->andReturn(false);
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installed]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installed')->with('php')->andReturn(true);
$brew->shouldReceive('installed')->with('php@8.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@8.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.4')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.3')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.2')->andReturn(true);
$brew->shouldReceive('installed')->with('php@7.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@5.6')->andReturn(false);
$brew->shouldReceive('installed')->with('php74')->andReturn(false);
$brew->shouldReceive('installed')->with('php73')->andReturn(false);
$brew->shouldReceive('installed')->with('php72')->andReturn(true);
$brew->shouldReceive('installed')->with('php71')->andReturn(false);
$brew->shouldReceive('installed')->with('php70')->andReturn(false);
$brew->shouldReceive('installed')->with('php56')->andReturn(false);
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installed]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installed')->with('php')->andReturn(false);
$brew->shouldReceive('installed')->with('php@8.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@8.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.4')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.3')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.2')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.1')->andReturn(true);
$brew->shouldReceive('installed')->with('php@7.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@5.6')->andReturn(false);
$brew->shouldReceive('installed')->with('php74')->andReturn(false);
$brew->shouldReceive('installed')->with('php73')->andReturn(false);
$brew->shouldReceive('installed')->with('php72')->andReturn(false);
$brew->shouldReceive('installed')->with('php71')->andReturn(true);
$brew->shouldReceive('installed')->with('php70')->andReturn(false);
$brew->shouldReceive('installed')->with('php56')->andReturn(false);
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installed]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installed')->with('php')->andReturn(false);
$brew->shouldReceive('installed')->with('php@8.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@8.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.4')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.3')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.2')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.0')->andReturn(true);
$brew->shouldReceive('installed')->with('php@5.6')->andReturn(false);
$brew->shouldReceive('installed')->with('php74')->andReturn(false);
$brew->shouldReceive('installed')->with('php73')->andReturn(false);
$brew->shouldReceive('installed')->with('php72')->andReturn(false);
$brew->shouldReceive('installed')->with('php71')->andReturn(false);
$brew->shouldReceive('installed')->with('php70')->andReturn(true);
$brew->shouldReceive('installed')->with('php56')->andReturn(false);
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installed]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installed')->with('php')->andReturn(false);
$brew->shouldReceive('installed')->with('php@8.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@8.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.4')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.3')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.2')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@5.6')->andReturn(true);
$brew->shouldReceive('installed')->with('php74')->andReturn(false);
$brew->shouldReceive('installed')->with('php73')->andReturn(false);
$brew->shouldReceive('installed')->with('php72')->andReturn(false);
$brew->shouldReceive('installed')->with('php71')->andReturn(false);
$brew->shouldReceive('installed')->with('php70')->andReturn(false);
$brew->shouldReceive('installed')->with('php56')->andReturn(true);
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installed]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installed')->with('php')->andReturn(false);
$brew->shouldReceive('installed')->with('php@8.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@8.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.4')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.3')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.2')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.1')->andReturn(false);
$brew->shouldReceive('installed')->with('php@7.0')->andReturn(false);
$brew->shouldReceive('installed')->with('php@5.6')->andReturn(false);
$brew->shouldReceive('installed')->with('php74')->andReturn(false);
$brew->shouldReceive('installed')->with('php73')->andReturn(false);
$brew->shouldReceive('installed')->with('php72')->andReturn(false);
$brew->shouldReceive('installed')->with('php71')->andReturn(false);
$brew->shouldReceive('installed')->with('php70')->andReturn(false);
$brew->shouldReceive('installed')->with('php56')->andReturn(false);
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@5.5']));
$this->assertFalse($brew->hasInstalledPhp());
}
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@8.1']));
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@8.0']));
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@7.4']));
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@7.3']));
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php73']));
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@7.2', 'php72']));
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php71', 'php@7.1']));
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@7.0']));
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@5.6']));
$this->assertTrue($brew->hasInstalledPhp());
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php56']));
$this->assertTrue($brew->hasInstalledPhp());
}
public function test_tap_taps_the_given_homebrew_repository()
{
@@ -207,28 +113,25 @@ public function test_tap_taps_the_given_homebrew_repository()
resolve(Brew::class)->tap('php@7.1', 'php@7.0', 'php@5.6');
}
public function test_restart_restarts_the_service_using_homebrew_services()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->with('brew list --formula | grep dnsmasq')->andReturn('dnsmasq');
$cli->shouldReceive('runAsUser')->once()->with('brew info dnsmasq --json')->andReturn('[{"name":"dnsmasq","full_name":"dnsmasq","aliases":[],"versioned_formulae":[],"versions":{"stable":"1"},"installed":[{"version":"1"}]}]');
$cli->shouldReceive('quietly')->once()->with('sudo brew services stop dnsmasq');
$cli->shouldReceive('quietly')->once()->with('sudo brew services start dnsmasq');
swap(CommandLine::class, $cli);
resolve(Brew::class)->restartService('dnsmasq');
}
public function test_stop_stops_the_service_using_homebrew_services()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->with('brew list --formula | grep dnsmasq')->andReturn('dnsmasq');
$cli->shouldReceive('runAsUser')->once()->with('brew info dnsmasq --json')->andReturn('[{"name":"dnsmasq","full_name":"dnsmasq","aliases":[],"versioned_formulae":[],"versions":{"stable":"1"},"installed":[{"version":"1"}]}]');
$cli->shouldReceive('quietly')->once()->with('sudo brew services stop dnsmasq');
swap(CommandLine::class, $cli);
resolve(Brew::class)->stopService('dnsmasq');
}
public function test_linked_php_returns_linked_php_formula_name()
{
$getBrewMock = function ($filesystem) {
@@ -262,18 +165,15 @@ public function test_linked_php_returns_linked_php_formula_name()
$this->assertSame('php@5.6', $getBrewMock($files)->linkedPhp());
}
/**
* @expectedException DomainException
*/
public function test_linked_php_throws_exception_if_no_php_link()
{
$this->expectException(DomainException::class);
$brewMock = Mockery::mock(Brew::class)->makePartial();
$brewMock->shouldReceive('hasLinkedPhp')->once()->andReturn(false);
$brewMock->linkedPhp();
}
public function test_has_linked_php_returns_true_if_php_link_exists()
{
$files = Mockery::mock(Filesystem::class);
@@ -285,12 +185,10 @@ public function test_has_linked_php_returns_true_if_php_link_exists()
$this->assertTrue($brew->hasLinkedPhp());
}
/**
* @expectedException DomainException
*/
public function test_linked_php_throws_exception_if_unsupported_php_version_is_linked()
{
$this->expectException(DomainException::class);
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('isLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn(true);
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/5.4.14/test');
@@ -298,8 +196,7 @@ public function test_linked_php_throws_exception_if_unsupported_php_version_is_l
resolve(Brew::class)->linkedPhp();
}
public function test_install_or_fail_will_install_brew_formulas()
public function test_install_or_fail_will_install_brew_formulae()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->with('brew install dnsmasq', Mockery::type('Closure'));
@@ -307,7 +204,6 @@ public function test_install_or_fail_will_install_brew_formulas()
resolve(Brew::class)->installOrFail('dnsmasq');
}
public function test_install_or_fail_can_install_taps()
{
$cli = Mockery::mock(CommandLine::class);
@@ -318,12 +214,10 @@ public function test_install_or_fail_can_install_taps()
$brew->installOrFail('dnsmasq', [], ['test/tap']);
}
/**
* @expectedException DomainException
*/
public function test_install_or_fail_throws_exception_on_failure()
{
$this->expectException(DomainException::class);
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->andReturnUsing(function ($command, $onError) {
$onError(1, 'test error ouput');
@@ -332,11 +226,10 @@ public function test_install_or_fail_throws_exception_on_failure()
resolve(Brew::class)->installOrFail('dnsmasq');
}
/**
* @expectedException DomainException
*/
public function test_link_will_throw_exception_on_failure()
{
$this->expectException(DomainException::class);
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->withArgs([
'brew link aformula',
@@ -372,11 +265,10 @@ public function test_link_will_pass_formula_and_force_to_run_as_user_if_set()
$this->assertSame('Some output forced', resolve(Brew::class)->link('aformula', true));
}
/**
* @expectedException DomainException
*/
public function test_unlink_will_throw_exception_on_failure()
{
$this->expectException(DomainException::class);
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->withArgs([
'brew unlink aformula',
@@ -400,11 +292,10 @@ public function test_unlink_will_pass_formula_to_run_as_user()
$this->assertSame('Some output', resolve(Brew::class)->unlink('aformula'));
}
/**
* @expectedException DomainException
*/
public function test_getRunningServices_will_throw_exception_on_failure()
{
$this->expectException(DomainException::class);
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('runAsUser')->once()->withArgs([
'brew services list | grep started | awk \'{ print $1; }\'',
@@ -485,48 +376,48 @@ public function supportedPhpLinkPathProvider()
{
return [
[
'/test/path/php/7.3.0/test', // linked path
'/test/path/php/7.4.0/test', // linked path
[ // matches
'path/php/7.3.0/test',
'path/php/7.4.0/test',
'php',
'',
'7.3',
'7.4',
'.0',
],
'php', // expected link formula
],
[
'/test/path/php@7.2/7.2.13/test',
'/test/path/php@7.4/7.4.13/test',
[
'path/php@7.2/7.2.13/test',
'path/php@7.4/7.4.13/test',
'php',
'@7.2',
'7.2',
'@7.4',
'7.4',
'.13',
],
'php@7.2'
'php@7.4'
],
[
'/test/path/php/7.2.9_2/test',
'/test/path/php/7.4.9_2/test',
[
'path/php/7.2.9_2/test',
'path/php/7.4.9_2/test',
'php',
'',
'7.2',
'7.4',
'.9_2',
],
'php',
],
[
'/test/path/php72/7.2.9_2/test',
'/test/path/php74/7.4.9_2/test',
[
'path/php72/7.2.9_2/test',
'path/php74/7.4.9_2/test',
'php',
'72',
'7.2',
'74',
'7.4',
'.9_2',
],
'php72',
'php74',
],
[
'/test/path/php56/test',

View File

@@ -9,22 +9,20 @@
use function Valet\swap;
use Illuminate\Container\Container;
class ConfigurationTest extends PHPUnit_Framework_TestCase
class ConfigurationTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
public function setUp()
public function set_up()
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
public function tearDown()
public function tear_down()
{
Mockery::close();
}
public function test_configuration_directory_is_created_if_it_doesnt_exist()
{
$files = Mockery::mock(Filesystem::class.'[ensureDirExists,isDir]');
@@ -35,7 +33,6 @@ public function test_configuration_directory_is_created_if_it_doesnt_exist()
resolve(Configuration::class)->createConfigurationDirectory();
}
public function test_drivers_directory_is_created_with_sample_driver_if_it_doesnt_exist()
{
$files = Mockery::mock(Filesystem::class.'[isDir,mkdirAsUser,putAsUser]');
@@ -76,7 +73,6 @@ public function test_add_path_adds_a_path_to_the_paths_array_and_removes_duplica
$config->addPath('path-3');
}
public function test_paths_may_be_removed_from_the_configuration()
{
$config = Mockery::mock(Configuration::class.'[read,write]', [new Filesystem]);
@@ -89,7 +85,6 @@ public function test_paths_may_be_removed_from_the_configuration()
$config->removePath('path-2');
}
public function test_prune_removes_directories_from_paths_that_no_longer_exist()
{
$files = Mockery::mock(Filesystem::class.'[exists,isDir]');
@@ -107,7 +102,6 @@ public function test_prune_removes_directories_from_paths_that_no_longer_exist()
$config->prune();
}
public function test_prune_doesnt_execute_if_configuration_directory_doesnt_exist()
{
$files = Mockery::mock(Filesystem::class.'[exists]');
@@ -119,7 +113,6 @@ public function test_prune_doesnt_execute_if_configuration_directory_doesnt_exis
$config->prune();
}
public function test_update_key_updates_the_specified_configuration_key()
{
$config = Mockery::mock(Configuration::class.'[read,write]', [new Filesystem]);
@@ -128,7 +121,6 @@ public function test_update_key_updates_the_specified_configuration_key()
$config->updateKey('bar', 'baz');
}
public function test_trust_adds_the_sudoer_files()
{
$files = Mockery::mock(Filesystem::class.'[ensureDirExists,put]');

View File

@@ -10,17 +10,16 @@
use function Valet\swap;
use Illuminate\Container\Container;
class DnsMasqTest extends PHPUnit_Framework_TestCase
class DnsMasqTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
public function setUp()
public function set_up()
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
public function tearDown()
public function tear_down()
{
exec('rm -rf '.__DIR__.'/output');
mkdir(__DIR__.'/output');
@@ -29,7 +28,6 @@ public function tearDown()
Mockery::close();
}
public function test_install_installs_and_places_configuration_files_in_proper_locations()
{
$brew = Mockery::mock(Brew::class);
@@ -56,7 +54,6 @@ public function test_install_installs_and_places_configuration_files_in_proper_l
);
}
public function test_update_tld_removes_old_resolver_and_reinstalls()
{
$cli = Mockery::mock(CommandLine::class);
@@ -68,7 +65,6 @@ public function test_update_tld_removes_old_resolver_and_reinstalls()
}
}
class StubForCreatingCustomDnsMasqConfigFiles extends DnsMasq
{
public function dnsmasqUserConfigDir()

View File

@@ -2,16 +2,15 @@
use Valet\Filesystem;
class FilesystemTest extends PHPUnit_Framework_TestCase
class FilesystemTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
public function tearDown()
public function tear_down()
{
exec('rm -rf '.__DIR__.'/output');
mkdir(__DIR__.'/output');
touch(__DIR__.'/output/.gitkeep');
}
public function test_remove_broken_links_removes_broken_symlinks()
{
$files = new Filesystem;
@@ -20,6 +19,6 @@ public function test_remove_broken_links_removes_broken_symlinks()
$this->assertFileExists(__DIR__.'/output/file.link');
unlink(__DIR__.'/output/file.out');
$files->removeBrokenLinksAt(__DIR__.'/output');
$this->assertFileNotExists(__DIR__.'/output/file.link');
$this->assertFileDoesNotExist(__DIR__.'/output/file.link');
}
}

View File

@@ -9,29 +9,27 @@
use function Valet\swap;
use Illuminate\Container\Container;
class NginxTest extends PHPUnit_Framework_TestCase
class NginxTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
public function setUp()
public function set_up()
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
public function tearDown()
public function tear_down()
{
Mockery::close();
}
public function test_install_nginx_configuration_places_nginx_base_configuration_in_proper_location()
{
$files = Mockery::mock(Filesystem::class.'[putAsUser]');
$files->shouldReceive('putAsUser')->andReturnUsing(function ($path, $contents) {
$this->assertSame(BREW_PREFIX.'/etc/nginx/nginx.conf', $path);
$this->assertContains('include "'.VALET_HOME_PATH.'/Nginx/*"', $contents);
$this->assertStringContainsString('include "'.VALET_HOME_PATH.'/Nginx/*"', $contents);
})->once();
swap(Filesystem::class, $files);
@@ -40,7 +38,6 @@ public function test_install_nginx_configuration_places_nginx_base_configuration
$nginx->installConfiguration();
}
public function test_install_nginx_directories_creates_location_for_site_specific_configuration()
{
$files = Mockery::mock(Filesystem::class);
@@ -56,7 +53,6 @@ public function test_install_nginx_directories_creates_location_for_site_specifi
$nginx->installNginxDirectory();
}
public function test_nginx_directory_is_never_created_if_it_already_exists()
{
$files = Mockery::mock(Filesystem::class);
@@ -72,7 +68,6 @@ public function test_nginx_directory_is_never_created_if_it_already_exists()
$nginx->installNginxDirectory();
}
public function test_install_nginx_directories_rewrites_secure_nginx_files()
{
$files = Mockery::mock(Filesystem::class);
@@ -89,5 +84,4 @@ public function test_install_nginx_directories_rewrites_secure_nginx_files()
$site->shouldHaveReceived('resecureForNewTld', ['test', 'test']);
}
}

View File

@@ -9,17 +9,16 @@
use function Valet\resolve;
use Illuminate\Container\Container;
class PhpFpmTest extends PHPUnit_Framework_TestCase
class PhpFpmTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
public function setUp()
public function set_up()
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
public function tearDown()
public function tear_down()
{
exec('rm -rf '.__DIR__.'/output');
mkdir(__DIR__.'/output');
@@ -35,9 +34,9 @@ public function test_fpm_is_configured_with_the_correct_user_group_and_port()
copy(__DIR__.'/files/php-memory-limits.ini', __DIR__.'/output/conf.d/php-memory-limits.ini');
resolve(StubForUpdatingFpmConfigFiles::class)->updateConfiguration();
$contents = file_get_contents(__DIR__.'/output/fpm.conf');
$this->assertContains(sprintf("\nuser = %s", user()), $contents);
$this->assertContains("\ngroup = staff", $contents);
$this->assertContains("\nlisten = ".VALET_HOME_PATH."/valet.sock", $contents);
$this->assertStringContainsString(sprintf("\nuser = %s", user()), $contents);
$this->assertStringContainsString("\ngroup = staff", $contents);
$this->assertStringContainsString("\nlisten = ".VALET_HOME_PATH."/valet.sock", $contents);
}
public function test_stopRunning_will_pass_filtered_result_of_getRunningServices_to_stopService()
@@ -79,19 +78,23 @@ public function test_use_version_will_convert_passed_php_version()
'php@5.6',
]));
$brewMock->shouldReceive('hasLinkedPhp')->andReturn(false);
$brewMock->shouldReceive('ensureInstalled')->with('php@7.2');
$brewMock->shouldReceive('ensureInstalled')->with('php@7.2', [], $phpFpmMock->taps);
$brewMock->shouldReceive('determineAliasedVersion')->with('php@7.2')->andReturn('php@7.2');
$brewMock->shouldReceive('link')->withArgs(['php@7.2', true]);
$brewMock->shouldReceive('linkedPhp');
$brewMock->shouldReceive('installed');
$brewMock->shouldReceive('getRunningServices')->andReturn(collect());
$brewMock->shouldReceive('stopService');
// Test both non prefixed and prefixed
$this->assertSame('php@7.2', $phpFpmMock->useVersion('php7.2'));
$this->assertSame('php@7.2', $phpFpmMock->useVersion('php72'));
}
/**
* @expectedException DomainException
*/
public function test_use_version_will_throw_if_version_not_supported()
{
$this->expectException(DomainException::class);
$brewMock = Mockery::mock(Brew::class);
swap(Brew::class, $brewMock);
@@ -120,8 +123,13 @@ public function test_use_version_if_already_linked_php_will_unlink_before_instal
$brewMock->shouldReceive('hasLinkedPhp')->andReturn(true);
$brewMock->shouldReceive('getLinkedPhpFormula')->andReturn('php@7.1');
$brewMock->shouldReceive('unlink')->with('php@7.1');
$brewMock->shouldReceive('ensureInstalled')->with('php@7.2');
$brewMock->shouldReceive('ensureInstalled')->with('php@7.2', [], $phpFpmMock->taps);
$brewMock->shouldReceive('determineAliasedVersion')->with('php@7.2')->andReturn('php@7.2');
$brewMock->shouldReceive('link')->withArgs(['php@7.2', true]);
$brewMock->shouldReceive('linkedPhp');
$brewMock->shouldReceive('installed');
$brewMock->shouldReceive('getRunningServices')->andReturn(collect());
$brewMock->shouldReceive('stopService');
// Test both non prefixed and prefixed
$this->assertSame('php@7.2', $phpFpmMock->useVersion('php@7.2'));

View File

@@ -9,17 +9,16 @@
use function Valet\swap;
use Illuminate\Container\Container;
class SiteTest extends PHPUnit_Framework_TestCase
class SiteTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
public function setUp()
public function set_up()
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
public function tearDown()
public function tear_down()
{
exec('rm -rf '.__DIR__.'/output');
mkdir(__DIR__.'/output');
@@ -28,7 +27,6 @@ public function tearDown()
Mockery::close();
}
public function test_get_certificates_will_return_with_multi_segment_tld()
{
$files = Mockery::mock(Filesystem::class);
@@ -53,7 +51,6 @@ public function test_get_certificates_will_return_with_multi_segment_tld()
$this->assertSame(['helloworld' => 0], $certs->all());
}
public function test_get_sites_will_return_if_secured()
{
$files = Mockery::mock(Filesystem::class);
@@ -108,7 +105,6 @@ public function test_get_sites_will_return_if_secured()
], $sites->last());
}
public function test_get_sites_will_work_with_non_symlinked_path()
{
$files = Mockery::mock(Filesystem::class);
@@ -151,7 +147,6 @@ public function test_get_sites_will_work_with_non_symlinked_path()
], $sites->first());
}
public function test_get_sites_will_not_return_if_path_is_not_directory()
{
$files = Mockery::mock(Filesystem::class);
@@ -189,7 +184,6 @@ public function test_get_sites_will_not_return_if_path_is_not_directory()
], $sites->first());
}
public function test_get_sites_will_work_with_symlinked_path()
{
$files = Mockery::mock(Filesystem::class);
@@ -232,7 +226,6 @@ public function test_get_sites_will_work_with_symlinked_path()
], $sites->first());
}
public function test_symlink_creates_symlink_to_given_path()
{
$files = Mockery::mock(Filesystem::class);
@@ -248,21 +241,19 @@ public function test_symlink_creates_symlink_to_given_path()
$this->assertSame(VALET_HOME_PATH.'/Sites/link', $linkPath);
}
public function test_unlink_removes_existing_symlink()
{
file_put_contents(__DIR__.'/output/file.out', 'test');
symlink(__DIR__.'/output/file.out', __DIR__.'/output/link');
$site = resolve(StubForRemovingLinks::class);
$site->unlink('link');
$this->assertFileNotExists(__DIR__.'/output/link');
$this->assertFileDoesNotExist(__DIR__.'/output/link');
$site = resolve(StubForRemovingLinks::class);
$site->unlink('link');
$this->assertFileNotExists(__DIR__.'/output/link');
$this->assertFileDoesNotExist(__DIR__.'/output/link');
}
public function test_prune_links_removes_broken_symlinks_in_sites_path()
{
file_put_contents(__DIR__.'/output/file.out', 'test');
@@ -270,10 +261,9 @@ public function test_prune_links_removes_broken_symlinks_in_sites_path()
unlink(__DIR__.'/output/file.out');
$site = resolve(StubForRemovingLinks::class);
$site->pruneLinks();
$this->assertFileNotExists(__DIR__.'/output/link');
$this->assertFileDoesNotExist(__DIR__.'/output/link');
}
public function test_certificates_trim_tld_for_custom_tlds()
{
$files = Mockery::mock(Filesystem::class);
@@ -300,7 +290,6 @@ public function test_certificates_trim_tld_for_custom_tlds()
$this->assertEquals('fiveletters', $certs->last());
}
public function test_no_proxies()
{
$config = Mockery::mock(Configuration::class);
@@ -317,7 +306,6 @@ public function test_no_proxies()
$this->assertEquals([], $site->proxies()->all());
}
public function test_lists_proxies()
{
$config = Mockery::mock(Configuration::class);
@@ -347,7 +335,6 @@ public function test_lists_proxies()
], $site->proxies()->all());
}
public function test_add_proxy()
{
$config = Mockery::mock(Configuration::class);
@@ -460,7 +447,6 @@ public function test_add_proxy_clears_previous_proxy_certificate()
], $site->proxies()->all());
}
public function test_add_proxy_clears_previous_non_proxy_certificate()
{
$config = Mockery::mock(Configuration::class);
@@ -501,7 +487,6 @@ public function test_add_proxy_clears_previous_non_proxy_certificate()
], $site->proxies()->all());
}
public function test_remove_proxy()
{
$config = Mockery::mock(Configuration::class);
@@ -636,7 +621,7 @@ public function assertNginxExists($urlWithTld)
public function assertNginxNotExists($urlWithTld)
{
SiteTest::assertFileNotExists($this->nginxPath($urlWithTld));
SiteTest::assertFileDoesNotExist($this->nginxPath($urlWithTld));
}
public function assertCertificateExists($urlWithTld)
@@ -647,8 +632,8 @@ public function assertCertificateExists($urlWithTld)
public function assertCertificateNotExists($urlWithTld)
{
SiteTest::assertFileNotExists($this->certificatesPath($urlWithTld, 'crt'));
SiteTest::assertFileNotExists($this->certificatesPath($urlWithTld, 'key'));
SiteTest::assertFileDoesNotExist($this->certificatesPath($urlWithTld, 'crt'));
SiteTest::assertFileDoesNotExist($this->certificatesPath($urlWithTld, 'key'));
}
public function assertCertificateExistsWithCounterValue($urlWithTld, $counter)