Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test suite to support PHPUnit 9 #121

Merged
merged 3 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
php-version: ${{ matrix.php }}
- run: composer install
- run: vendor/bin/phpunit --coverage-text
if: ${{ matrix.php >= 7.3 }}
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
if: ${{ matrix.php < 7.3 }}
- run: composer build

PHPUnit-hhvm:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"symfony/process": "^5.0 || ^4.0 || ^3.0 || ^2.5"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
"phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.36"
},
"autoload": {
"psr-0": {"Clue": "src/"}
Expand Down
19 changes: 12 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./tests/bootstrap.php" colors="true">
<!-- PHPUnit configuration file with new format for PHPUnit 9.5+ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheResult="false"
colors="true">
<testsuites>
<testsuite name="PharComposer Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
<coverage>
<include>
<directory>./src/</directory>
</include>
</coverage>
</phpunit>
18 changes: 18 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- PHPUnit configuration file with old format before PHPUnit 9 -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true">
<testsuites>
<testsuite name="PharComposer Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
12 changes: 6 additions & 6 deletions tests/Command/BuildTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public function testCtorCreatesPackager()

public function testExecuteBuildWillBuildPharer()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->exactly(2))->method('getArgument')->withConsecutive(
array('project'),
array('target')
)->willReturnOnConsecutiveCalls('dir', null);
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();

$pharer = $this->getMockBuilder('Clue\PharComposer\Phar\PharComposer')->disableOriginalConstructor()->getMock();
$pharer->expects($this->never())->method('setTarget');
$pharer->expects($this->once())->method('build');

$packager = $this->getMock('Clue\PharComposer\Phar\Packager');
$packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
$packager->expects($this->once())->method('setOutput')->with($output);
$packager->expects($this->once())->method('getPharer')->with('dir')->willReturn($pharer);

Expand All @@ -38,18 +38,18 @@ public function testExecuteBuildWillBuildPharer()

public function testExecuteBuildWillBuildPharerWithExplicitTarget()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->exactly(2))->method('getArgument')->withConsecutive(
array('project'),
array('target')
)->willReturnOnConsecutiveCalls('dir', 'targetDir');
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();

$pharer = $this->getMockBuilder('Clue\PharComposer\Phar\PharComposer')->disableOriginalConstructor()->getMock();
$pharer->expects($this->once())->method('setTarget')->with('targetDir');
$pharer->expects($this->once())->method('build');

$packager = $this->getMock('Clue\PharComposer\Phar\Packager');
$packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
$packager->expects($this->once())->method('setOutput')->with($output);
$packager->expects($this->once())->method('getPharer')->with('dir')->willReturn($pharer);

Expand Down
51 changes: 16 additions & 35 deletions tests/Command/InstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ public function testCtorCreatesPackager()

public function testExecuteInstallWillInstallPackager()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->exactly(2))->method('getArgument')->withConsecutive(
array('project'),
array('target')
)->willReturnOnConsecutiveCalls('dir', null);
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();

$package = $this->getMockBuilder('Clue\PharComposer\Package\Package')->disableOriginalConstructor()->getMock();
$pharer = $this->getMockBuilder('Clue\PharComposer\Phar\PharComposer')->disableOriginalConstructor()->getMock();
$pharer->expects($this->once())->method('getPackageRoot')->willReturn($package);

$packager = $this->getMock('Clue\PharComposer\Phar\Packager');
$packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
$packager->expects($this->once())->method('setOutput')->with($output);
$packager->expects($this->once())->method('getPharer')->with('dir')->willReturn($pharer);
$packager->expects($this->once())->method('getSystemBin')->with($package, null)->willReturn('targetPath');
Expand All @@ -41,18 +41,18 @@ public function testExecuteInstallWillInstallPackager()

public function testExecuteInstallWillInstallPackagerWithExplicitTarget()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->exactly(2))->method('getArgument')->withConsecutive(
array('project'),
array('target')
)->willReturnOnConsecutiveCalls('dir', 'targetDir');
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();

$package = $this->getMockBuilder('Clue\PharComposer\Package\Package')->disableOriginalConstructor()->getMock();
$pharer = $this->getMockBuilder('Clue\PharComposer\Phar\PharComposer')->disableOriginalConstructor()->getMock();
$pharer->expects($this->once())->method('getPackageRoot')->willReturn($package);

$packager = $this->getMock('Clue\PharComposer\Phar\Packager');
$packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
$packager->expects($this->once())->method('setOutput')->with($output);
$packager->expects($this->once())->method('getPharer')->with('dir')->willReturn($pharer);
$packager->expects($this->once())->method('getSystemBin')->with($package, 'targetDir')->willReturn('targetPath');
Expand All @@ -62,32 +62,16 @@ public function testExecuteInstallWillInstallPackagerWithExplicitTarget()
$command->run($input, $output);
}

/**
* @doesNotPerformAssertions
*/
public function testNotBlockedByLegacyInstallation()
{
// Symfony 5+ added parameter type declarations, so we can use this to check which version is installed
$ref = new ReflectionMethod('Symfony\Component\Console\Command\Command', 'setName');
$params = $ref->getParameters();
if (PHP_VERSION_ID >= 70000 && isset($params[0]) && $params[0]->hasType()) {
$this->markTestSkipped('Unable to run this test (mocked QuestionHelper) with legacy PHPUnit against Symfony v5+');
}
}

/**
* @depends testNotBlockedByLegacyInstallation
*/
public function testExecuteInstallWillInstallPackagerWhenTargetPathAlreadyExistsAndDialogQuestionYieldsYes()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->exactly(2))->method('getArgument')->withConsecutive(
array('project'),
array('target')
)->willReturnOnConsecutiveCalls('dir', null);
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();

$questionHelper = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper');
$questionHelper = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')->getMock();
$questionHelper->expects($this->once())->method('ask')->willReturn(true);

$helpers = new HelperSet(array(
Expand All @@ -98,7 +82,7 @@ public function testExecuteInstallWillInstallPackagerWhenTargetPathAlreadyExists
$pharer = $this->getMockBuilder('Clue\PharComposer\Phar\PharComposer')->disableOriginalConstructor()->getMock();
$pharer->expects($this->once())->method('getPackageRoot')->willReturn($package);

$packager = $this->getMock('Clue\PharComposer\Phar\Packager');
$packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
$packager->expects($this->once())->method('setOutput')->with($output);
$packager->expects($this->once())->method('getPharer')->with('dir')->willReturn($pharer);
$packager->expects($this->once())->method('getSystemBin')->with($package, null)->willReturn(__FILE__);
Expand All @@ -109,20 +93,17 @@ public function testExecuteInstallWillInstallPackagerWhenTargetPathAlreadyExists
$command->run($input, $output);
}

/**
* @depends testNotBlockedByLegacyInstallation
*/
public function testExecuteInstallWillNotInstallPackagerWhenTargetPathAlreadyExistsAndDialogQuestionShouldNotOverwrite()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->exactly(2))->method('getArgument')->withConsecutive(
array('project'),
array('target')
)->willReturnOnConsecutiveCalls('dir', null);
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
$output->expects($this->once())->method('writeln')->with('Aborting');

$questionHelper = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper');
$questionHelper = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')->getMock();
$questionHelper->expects($this->once())->method('ask')->willReturn(false);

$helpers = new HelperSet(array(
Expand All @@ -133,7 +114,7 @@ public function testExecuteInstallWillNotInstallPackagerWhenTargetPathAlreadyExi
$pharer = $this->getMockBuilder('Clue\PharComposer\Phar\PharComposer')->disableOriginalConstructor()->getMock();
$pharer->expects($this->once())->method('getPackageRoot')->willReturn($package);

$packager = $this->getMock('Clue\PharComposer\Phar\Packager');
$packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
$packager->expects($this->once())->method('setOutput')->with($output);
$packager->expects($this->once())->method('getPharer')->with('dir')->willReturn($pharer);
$packager->expects($this->once())->method('getSystemBin')->with($package, null)->willReturn(__FILE__);
Expand All @@ -146,8 +127,8 @@ public function testExecuteInstallWillNotInstallPackagerWhenTargetPathAlreadyExi

public function testExecuteInstallWillReportErrorOnWindows()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
$output->expects($this->once())->method('writeln')->with($this->stringContains('platform'));

$command = new Install(null, true);
Expand Down
Loading