Skip to content

Commit

Permalink
Merge pull request #1004 from drbyte/phpunit-polyfill
Browse files Browse the repository at this point in the history
Update test suite to phpunit 9.5
  • Loading branch information
mattstauffer authored Nov 30, 2020
2 parents 3564170 + 0b341a7 commit acb55d3
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 128 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ vendor/
composer.lock
error.log
.idea
.phpunit.result.cache
2 changes: 1 addition & 1 deletion cli/stubs/etc-phpfpm-error_log.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"require-dev": {
"mockery/mockery": "^1.2.3",
"phpunit/phpunit": "~5.7"
"yoast/phpunit-polyfills": "^0.2.0"
},
"bin": [
"valet"
Expand Down
4 changes: 3 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
85 changes: 32 additions & 53 deletions tests/BrewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -66,7 +62,6 @@ public function test_installed_returns_false_when_given_formula_is_not_installed
$this->assertFalse(resolve(Brew::class)->installed('[email protected]'));
}


public function test_has_installed_php_indicates_if_php_is_installed_via_brew()
{
$brew = Mockery::mock(Brew::class.'[installed]', [new CommandLine, new Filesystem]);
Expand Down Expand Up @@ -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);
Expand All @@ -207,7 +201,6 @@ public function test_tap_taps_the_given_homebrew_repository()
resolve(Brew::class)->tap('[email protected]', '[email protected]', '[email protected]');
}


public function test_restart_restarts_the_service_using_homebrew_services()
{
$cli = Mockery::mock(CommandLine::class);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -262,18 +253,15 @@ public function test_linked_php_returns_linked_php_formula_name()
$this->assertSame('[email protected]', $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);
Expand All @@ -285,29 +273,25 @@ 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');
swap(Filesystem::class, $files);
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'));
swap(CommandLine::class, $cli);
resolve(Brew::class)->installOrFail('dnsmasq');
}


public function test_install_or_fail_can_install_taps()
{
$cli = Mockery::mock(CommandLine::class);
Expand All @@ -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');
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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; }\'',
Expand Down Expand Up @@ -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',
Expand Down
14 changes: 3 additions & 11 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]');
Expand All @@ -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]');
Expand Down Expand Up @@ -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]);
Expand All @@ -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]');
Expand All @@ -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]');
Expand All @@ -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]);
Expand All @@ -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]');
Expand Down
Loading

0 comments on commit acb55d3

Please sign in to comment.