1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 08:10:07 +01:00

Merge pull request #1004 from drbyte/phpunit-polyfill

Update test suite to phpunit 9.5
This commit is contained in:
Matt Stauffer
2020-11-29 22:46:21 -05:00
committed by GitHub
12 changed files with 68 additions and 128 deletions

View File

@@ -29,11 +29,6 @@ jobs:
- name: Install dependencies
run: composer install --no-interaction --prefer-dist
if: matrix.php != 8.0
- name: Install dependencies
run: composer install --no-interaction --prefer-dist --ignore-platform-req=php
if: matrix.php == 8.0
- name: Execute tests
env:

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ vendor/
composer.lock
error.log
.idea
.phpunit.result.cache

View File

@@ -1,4 +1,4 @@
# php-fpm error logging directives
; php-fpm error logging directives
error_log="VALET_HOME_PATH/Log/php-fpm.log"
log_errors=on

View File

@@ -33,7 +33,7 @@
},
"require-dev": {
"mockery/mockery": "^1.2.3",
"phpunit/phpunit": "~5.7"
"yoast/phpunit-polyfills": "^0.2.0"
},
"bin": [
"valet"

View File

@@ -7,7 +7,9 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="false"
beStrictAboutTestsThatDoNotTestAnything="false"
>
<testsuites>
<testsuite name="Valet Test Suite">
<directory suffix="Test.php">./tests</directory>

View File

@@ -9,28 +9,25 @@
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);
@@ -45,7 +42,6 @@ public function test_installed_returns_true_when_given_formula_is_installed()
$this->assertTrue(resolve(Brew::class)->installed('php'));
}
public function test_installed_returns_false_when_given_formula_is_not_installed()
{
$cli = Mockery::mock(CommandLine::class);
@@ -66,7 +62,6 @@ public function test_installed_returns_false_when_given_formula_is_not_installed
$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]);
@@ -196,7 +191,6 @@ public function test_has_installed_php_indicates_if_php_is_installed_via_brew()
$this->assertFalse($brew->hasInstalledPhp());
}
public function test_tap_taps_the_given_homebrew_repository()
{
$cli = Mockery::mock(CommandLine::class);
@@ -207,7 +201,6 @@ 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);
@@ -218,7 +211,6 @@ public function test_restart_restarts_the_service_using_homebrew_services()
resolve(Brew::class)->restartService('dnsmasq');
}
public function test_stop_stops_the_service_using_homebrew_services()
{
$cli = Mockery::mock(CommandLine::class);
@@ -228,7 +220,6 @@ public function test_stop_stops_the_service_using_homebrew_services()
resolve(Brew::class)->stopService('dnsmasq');
}
public function test_linked_php_returns_linked_php_formula_name()
{
$getBrewMock = function ($filesystem) {
@@ -262,18 +253,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 +273,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 +284,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 +292,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 +302,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 +314,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 +353,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 +380,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 +464,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()
@@ -87,11 +86,10 @@ public function test_use_version_will_convert_passed_php_version()
$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);

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);
@@ -381,7 +368,6 @@ public function test_add_proxy()
], $site->proxies()->all());
}
public function test_add_proxy_clears_previous_proxy_certificate()
{
$config = Mockery::mock(Configuration::class);
@@ -426,7 +412,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);
@@ -467,7 +452,6 @@ public function test_add_proxy_clears_previous_non_proxy_certificate()
], $site->proxies()->all());
}
public function test_remove_proxy()
{
$config = Mockery::mock(Configuration::class);
@@ -602,7 +586,7 @@ public function assertNginxExists($urlWithTld)
public function assertNginxNotExists($urlWithTld)
{
SiteTest::assertFileNotExists($this->nginxPath($urlWithTld));
SiteTest::assertFileDoesNotExist($this->nginxPath($urlWithTld));
}
public function assertCertificateExists($urlWithTld)
@@ -613,8 +597,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)