diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8204f57..8336a0d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -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:
diff --git a/composer.json b/composer.json
index 80bf802..6b5d477 100644
--- a/composer.json
+++ b/composer.json
@@ -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/"}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 688f812..3bea625 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,14 +1,19 @@
-
+
+
./tests/
-
-
- ./src
-
-
-
\ No newline at end of file
+
+
+ ./src/
+
+
+
diff --git a/phpunit.xml.legacy b/phpunit.xml.legacy
new file mode 100644
index 0000000..50d3927
--- /dev/null
+++ b/phpunit.xml.legacy
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+ ./tests/
+
+
+
+
+ ./src/
+
+
+
diff --git a/tests/Command/BuildTest.php b/tests/Command/BuildTest.php
index fa2056e..552f59e 100644
--- a/tests/Command/BuildTest.php
+++ b/tests/Command/BuildTest.php
@@ -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);
@@ -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);
diff --git a/tests/Command/InstallTest.php b/tests/Command/InstallTest.php
index 7cc2560..7b70a81 100644
--- a/tests/Command/InstallTest.php
+++ b/tests/Command/InstallTest.php
@@ -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');
@@ -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');
@@ -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(
@@ -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__);
@@ -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(
@@ -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__);
@@ -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);
diff --git a/tests/Command/SearchTest.php b/tests/Command/SearchTest.php
index 0084738..22543b5 100644
--- a/tests/Command/SearchTest.php
+++ b/tests/Command/SearchTest.php
@@ -22,153 +22,123 @@ public function testCtorCreatesPackagerAndPackagist()
$this->assertInstanceOf('Packagist\Api\Client', $packagist);
}
- /**
- * @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+');
- }
- }
-
- /**
- * @expectedException RuntimeException
- * @expectedExceptionMessage stop1
- * @depends testNotBlockedByLegacyInstallation
- */
public function testExecuteWithoutProjectWillAskForProjectAndRunSearch()
{
- $input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
+ $input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->once())->method('getArgument')->with('project')->willReturn(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('foo');
$helpers = new HelperSet(array(
'question' => $questionHelper
));
- $packager = $this->getMock('Clue\PharComposer\Phar\Packager');
+ $packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
- $packagist = $this->getMock('Packagist\Api\Client');
+ $packagist = $this->getMockBuilder('Packagist\Api\Client')->getMock();
$packagist->expects($this->once())->method('search')->with('foo')->willThrowException(new RuntimeException('stop1'));
$command = new Search($packager, $packagist, false);
$command->setHelperSet($helpers);
+
+ $this->setExpectedException('RuntimeException', 'stop1');
$command->run($input, $output);
}
- /**
- * @expectedException RuntimeException
- * @expectedExceptionMessage stop1
- * @depends testNotBlockedByLegacyInstallation
- */
public function testExecuteWithProjectWillRunSearchWithoutAskingForProject()
{
- $input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
+ $input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->once())->method('getArgument')->with('project')->willReturn('foo');
- $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->never())->method('ask');
$helpers = new HelperSet(array(
'question' => $questionHelper
));
- $packager = $this->getMock('Clue\PharComposer\Phar\Packager');
+ $packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
- $packagist = $this->getMock('Packagist\Api\Client');
+ $packagist = $this->getMockBuilder('Packagist\Api\Client')->getMock();
$packagist->expects($this->once())->method('search')->with('foo')->willThrowException(new RuntimeException('stop1'));
$command = new Search($packager, $packagist, false);
$command->setHelperSet($helpers);
+
+ $this->setExpectedException('RuntimeException', 'stop1');
$command->run($input, $output);
}
- /**
- * @expectedException RuntimeException
- * @expectedExceptionMessage stop1
- * @depends testNotBlockedByLegacyInstallation
- */
public function testExecuteWithProjectAndSearchReturnsNoMatchesWillReportAndAskForOtherProject()
{
- $input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
+ $input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->once())->method('getArgument')->with('project')->willReturn('foo');
- $output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
+ $output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
$output->expects($this->exactly(2))->method('writeln')->withConsecutive(
array('Searching for foo...'),
array('No matching packages found')
);
- $questionHelper = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper');
+ $questionHelper = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')->getMock();
$questionHelper->expects($this->once())->method('ask')->willThrowException(new RuntimeException('stop1'));
$helpers = new HelperSet(array(
'question' => $questionHelper
));
- $packager = $this->getMock('Clue\PharComposer\Phar\Packager');
+ $packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
- $packagist = $this->getMock('Packagist\Api\Client');
+ $packagist = $this->getMockBuilder('Packagist\Api\Client')->getMock();
$packagist->expects($this->once())->method('search')->with('foo')->willReturn(array());
$command = new Search($packager, $packagist, false);
$command->setHelperSet($helpers);
+
+ $this->setExpectedException('RuntimeException', 'stop1');
$command->run($input, $output);
}
- /**
- * @expectedException RuntimeException
- * @expectedExceptionMessage stop1
- * @depends testNotBlockedByLegacyInstallation
- */
public function testExecuteWithProjectAndSearchReturnsOneMatchWillAskForProject()
{
- $input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
+ $input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->once())->method('getArgument')->with('project')->willReturn('foo');
- $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')->willThrowException(new RuntimeException('stop1'));
$helpers = new HelperSet(array(
'question' => $questionHelper
));
- $packager = $this->getMock('Clue\PharComposer\Phar\Packager');
+ $packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
- $result = $this->getMock('Packagist\Api\Result\Result');
+ $result = $this->getMockBuilder('Packagist\Api\Result\Result')->getMock();
- $packagist = $this->getMock('Packagist\Api\Client');
+ $packagist = $this->getMockBuilder('Packagist\Api\Client')->getMock();
$packagist->expects($this->once())->method('search')->with('foo')->willReturn(array($result));
$command = new Search($packager, $packagist, false);
$command->setHelperSet($helpers);
+
+ $this->setExpectedException('RuntimeException', 'stop1');
$command->run($input, $output);
}
- /**
- * @expectedException RuntimeException
- * @expectedExceptionMessage stop1
- * @depends testNotBlockedByLegacyInstallation
- */
public function testExecuteWithProjectSelectedWillSearchVersions()
{
- $input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
+ $input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->once())->method('getArgument')->with('project')->willReturn('foo');
- $output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
+ $output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
$output->expects($this->exactly(2))->method('writeln')->withConsecutive(
array('Searching for foo...'),
array('Selected foo/bar, listing versions...')
);
- $questionHelper = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper');
+ $questionHelper = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')->getMock();
$questionHelper->expects($this->once())->method('ask')->willReturn(
'foo/bar (⤓)'
);
@@ -177,34 +147,29 @@ public function testExecuteWithProjectSelectedWillSearchVersions()
'question' => $questionHelper
));
- $packager = $this->getMock('Clue\PharComposer\Phar\Packager');
+ $packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
- $result = $this->getMock('Packagist\Api\Result\Result');
+ $result = $this->getMockBuilder('Packagist\Api\Result\Result')->getMock();
$result->expects($this->exactly(2))->method('getName')->willReturn('foo/bar');
- $packagist = $this->getMock('Packagist\Api\Client');
+ $packagist = $this->getMockBuilder('Packagist\Api\Client')->getMock();
$packagist->expects($this->once())->method('search')->with('foo')->willReturn(array($result));
$packagist->expects($this->once())->method('get')->with('foo/bar')->willThrowException(new RuntimeException('stop1'));
$command = new Search($packager, $packagist, false);
$command->setHelperSet($helpers);
+
+ $this->setExpectedException('RuntimeException', 'stop1');
$command->run($input, $output);
}
- /**
- * @depends testNotBlockedByLegacyInstallation
- */
public function testExecuteWithProjectAndVersionSelectedWillQuitWhenAskedForActionYieldsQuit()
{
- if (PHP_VERSION_ID >= 70100 && PHP_VERSION_ID < 70200) {
- $this->markTestSkipped('Test broken with PHP 7.1 on legacy PHPUnit');
- }
-
- $input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
+ $input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->once())->method('getArgument')->with('project')->willReturn('foo');
- $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->exactly(3))->method('ask')->willReturnOnConsecutiveCalls(
'foo/bar (⤓)',
'dev-master (no executable bin)',
@@ -215,18 +180,18 @@ public function testExecuteWithProjectAndVersionSelectedWillQuitWhenAskedForActi
'question' => $questionHelper
));
- $packager = $this->getMock('Clue\PharComposer\Phar\Packager');
+ $packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
- $result = $this->getMock('Packagist\Api\Result\Result');
+ $result = $this->getMockBuilder('Packagist\Api\Result\Result')->getMock();
$result->expects($this->exactly(2))->method('getName')->willReturn('foo/bar');
- $version = $this->getMock('Packagist\Api\Result\Package\Version');
+ $version = $this->getMockBuilder('Packagist\Api\Result\Package\Version')->getMock();
$version->expects($this->exactly(2))->method('getVersion')->willReturn('dev-master');
- $package = $this->getMock('Packagist\Api\Result\Package');
+ $package = $this->getMockBuilder('Packagist\Api\Result\Package')->getMock();
$package->expects($this->once())->method('getVersions')->willReturn(array($version));
- $packagist = $this->getMock('Packagist\Api\Client');
+ $packagist = $this->getMockBuilder('Packagist\Api\Client')->getMock();
$packagist->expects($this->once())->method('search')->with('foo')->willReturn(array($result));
$packagist->expects($this->once())->method('get')->with('foo/bar')->willReturn($package);
@@ -235,17 +200,13 @@ public function testExecuteWithProjectAndVersionSelectedWillQuitWhenAskedForActi
$command->run($input, $output);
}
- /**
- * @depends testNotBlockedByLegacyInstallation
- * @depends testExecuteWithProjectAndVersionSelectedWillQuitWhenAskedForActionYieldsQuit
- */
public function testExecuteWithProjectAndVersionSelectedWillBuildWhenAskedForActionYieldsBuild()
{
- $input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
+ $input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->once())->method('getArgument')->with('project')->willReturn('foo');
- $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->exactly(3))->method('ask')->willReturnOnConsecutiveCalls(
'foo/bar (⤓)',
'dev-master (no executable bin)',
@@ -259,19 +220,19 @@ public function testExecuteWithProjectAndVersionSelectedWillBuildWhenAskedForAct
$pharer = $this->getMockBuilder('Clue\PharComposer\Phar\PharComposer')->disableOriginalConstructor()->getMock();
$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('getPharer')->with('foo/bar', 'dev-master')->willReturn($pharer);
- $result = $this->getMock('Packagist\Api\Result\Result');
+ $result = $this->getMockBuilder('Packagist\Api\Result\Result')->getMock();
$result->expects($this->exactly(2))->method('getName')->willReturn('foo/bar');
- $version = $this->getMock('Packagist\Api\Result\Package\Version');
+ $version = $this->getMockBuilder('Packagist\Api\Result\Package\Version')->getMock();
$version->expects($this->exactly(2))->method('getVersion')->willReturn('dev-master');
- $package = $this->getMock('Packagist\Api\Result\Package');
+ $package = $this->getMockBuilder('Packagist\Api\Result\Package')->getMock();
$package->expects($this->once())->method('getVersions')->willReturn(array($version));
- $packagist = $this->getMock('Packagist\Api\Client');
+ $packagist = $this->getMockBuilder('Packagist\Api\Client')->getMock();
$packagist->expects($this->once())->method('search')->with('foo')->willReturn(array($result));
$packagist->expects($this->once())->method('get')->with('foo/bar')->willReturn($package);
@@ -280,17 +241,13 @@ public function testExecuteWithProjectAndVersionSelectedWillBuildWhenAskedForAct
$command->run($input, $output);
}
- /**
- * @depends testNotBlockedByLegacyInstallation
- * @depends testExecuteWithProjectAndVersionSelectedWillQuitWhenAskedForActionYieldsQuit
- */
public function testExecuteWithProjectAndVersionSelectedWillInstallWhenAskedForActionYieldsInstall()
{
- $input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
+ $input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->once())->method('getArgument')->with('project')->willReturn('foo');
- $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->exactly(3))->method('ask')->willReturnOnConsecutiveCalls(
'foo/bar (⤓)',
'dev-master (no executable bin)',
@@ -306,21 +263,21 @@ public function testExecuteWithProjectAndVersionSelectedWillInstallWhenAskedForA
$pharer->expects($this->once())->method('getPackageRoot')->willReturn($package);
$pharer->expects($this->never())->method('build');
- $packager = $this->getMock('Clue\PharComposer\Phar\Packager');
+ $packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
$packager->expects($this->once())->method('getPharer')->with('foo/bar', 'dev-master')->willReturn($pharer);
$packager->expects($this->once())->method('getSystemBin')->with($package)->willReturn('targetPath');
$packager->expects($this->once())->method('install')->with($pharer, 'targetPath');
- $result = $this->getMock('Packagist\Api\Result\Result');
+ $result = $this->getMockBuilder('Packagist\Api\Result\Result')->getMock();
$result->expects($this->exactly(2))->method('getName')->willReturn('foo/bar');
- $version = $this->getMock('Packagist\Api\Result\Package\Version');
+ $version = $this->getMockBuilder('Packagist\Api\Result\Package\Version')->getMock();
$version->expects($this->exactly(2))->method('getVersion')->willReturn('dev-master');
- $package = $this->getMock('Packagist\Api\Result\Package');
+ $package = $this->getMockBuilder('Packagist\Api\Result\Package')->getMock();
$package->expects($this->once())->method('getVersions')->willReturn(array($version));
- $packagist = $this->getMock('Packagist\Api\Client');
+ $packagist = $this->getMockBuilder('Packagist\Api\Client')->getMock();
$packagist->expects($this->once())->method('search')->with('foo')->willReturn(array($result));
$packagist->expects($this->once())->method('get')->with('foo/bar')->willReturn($package);
@@ -329,20 +286,16 @@ public function testExecuteWithProjectAndVersionSelectedWillInstallWhenAskedForA
$command->run($input, $output);
}
- /**
- * @depends testNotBlockedByLegacyInstallation
- * @depends testExecuteWithProjectAndVersionSelectedWillQuitWhenAskedForActionYieldsQuit
- */
public function testExecuteWithProjectAndVersionSelectedOnWindowsWillNotOfferInstallWhenAskedForAction()
{
- $input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
+ $input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$input->expects($this->once())->method('getArgument')->with('project')->willReturn('foo');
- $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->exactly(3))->method('ask')->withConsecutive(
- $this->anything(),
- $this->anything(),
+ array($this->anything()),
+ array($this->anything()),
array(
$input,
$output,
@@ -362,18 +315,18 @@ public function testExecuteWithProjectAndVersionSelectedOnWindowsWillNotOfferIns
$package = $this->getMockBuilder('Clue\PharComposer\Package\Package')->disableOriginalConstructor()->getMock();
- $packager = $this->getMock('Clue\PharComposer\Phar\Packager');
+ $packager = $this->getMockBuilder('Clue\PharComposer\Phar\Packager')->getMock();
- $result = $this->getMock('Packagist\Api\Result\Result');
+ $result = $this->getMockBuilder('Packagist\Api\Result\Result')->getMock();
$result->expects($this->exactly(2))->method('getName')->willReturn('foo/bar');
- $version = $this->getMock('Packagist\Api\Result\Package\Version');
+ $version = $this->getMockBuilder('Packagist\Api\Result\Package\Version')->getMock();
$version->expects($this->exactly(2))->method('getVersion')->willReturn('dev-master');
- $package = $this->getMock('Packagist\Api\Result\Package');
+ $package = $this->getMockBuilder('Packagist\Api\Result\Package')->getMock();
$package->expects($this->once())->method('getVersions')->willReturn(array($version));
- $packagist = $this->getMock('Packagist\Api\Client');
+ $packagist = $this->getMockBuilder('Packagist\Api\Client')->getMock();
$packagist->expects($this->once())->method('search')->with('foo')->willReturn(array($result));
$packagist->expects($this->once())->method('get')->with('foo/bar')->willReturn($package);
diff --git a/tests/LoggerTest.php b/tests/LoggerTest.php
index 76e0b23..512e940 100644
--- a/tests/LoggerTest.php
+++ b/tests/LoggerTest.php
@@ -13,8 +13,10 @@ class LoggerTest extends TestCase
/**
* set up test environment
+ *
+ * @before
*/
- public function setUp()
+ public function setUpLogger()
{
$this->logger = new Logger();
}
diff --git a/tests/Phar/PackagerTest.php b/tests/Phar/PackagerTest.php
index 54e484c..8e2b4dc 100644
--- a/tests/Phar/PackagerTest.php
+++ b/tests/Phar/PackagerTest.php
@@ -7,7 +7,8 @@ class PackagerTest extends TestCase
{
private $packager;
- public function setUp()
+ /** @before */
+ public function setUpPackager()
{
$this->packager = new Packager();
}
@@ -48,30 +49,21 @@ public function provideExecCommands()
);
}
- /**
- * @expectedException RuntimeException
- * @expectedExceptionMessage not installed
- */
public function testEmptyNotInstalled()
{
+ $this->setExpectedException('RuntimeException', 'not installed');
$this->packager->getPharer(__DIR__ . '/../fixtures/01-empty');
}
- /**
- * @expectedException InvalidArgumentException
- * @expectedExceptionMessage not a readable file
- */
public function testNoComposer()
{
+ $this->setExpectedException('InvalidArgumentException', 'not a readable file');
$this->packager->getPharer(__DIR__ . '/../fixtures/02-no-composer');
}
- /**
- * @expectedException InvalidArgumentException
- * @expectedExceptionMessage not a readable file
- */
public function testNoComposerMissing()
{
+ $this->setExpectedException('InvalidArgumentException', 'not a readable file');
$this->packager->getPharer(__DIR__ . '/../fixtures/02-no-composer/composer.json');
}
diff --git a/tests/Phar/PharComposerTest.php b/tests/Phar/PharComposerTest.php
index 4e97544..2045f10 100644
--- a/tests/Phar/PharComposerTest.php
+++ b/tests/Phar/PharComposerTest.php
@@ -19,12 +19,9 @@ public function testConstructor()
return $pharcomposer;
}
- /**
- * @expectedException InvalidArgumentException
- * @expectedExceptionMessage Unable to parse given path
- */
public function testConstructorThrowsWhenPathIsNotFile()
{
+ $this->setExpectedException('InvalidArgumentException', 'Unable to parse given path');
new PharComposer(__DIR__);
}
@@ -43,14 +40,11 @@ public function testSetters(PharComposer $pharcomposer)
return $pharcomposer;
}
- /**
- * @expectedException UnexpectedValueException
- * @expectedExceptionMessage Bin file "bin/invalid" does not exist
- */
public function testGetMainThrowsWhenBinDoesNotExist()
{
$pharer = new PharComposer(__DIR__ . '/../fixtures/05-invalid-bin/composer.json');
+ $this->setExpectedException('UnexpectedValueException', 'Bin file "bin/invalid" does not exist');
$pharer->getMain();
}
@@ -62,22 +56,16 @@ public function testSetTargetWillAppendPackageShortNameWhenTargetIsDirectory()
$this->assertEquals(__DIR__ . '/phar-composer.phar', $pharer->getTarget());
}
- /**
- * @expectedException RuntimeException
- * @expectedExceptionMessage not properly installed
- */
public function testBuildThrowsWhen()
{
$pharer = new PharComposer(__DIR__ . '/../fixtures/01-empty/composer.json');
$pharer->setOutput(false);
$pharer->setTarget('/dev/null');
+
+ $this->setExpectedException('RuntimeException', 'not properly installed');
$pharer->build();
}
- /**
- * @expectedException RuntimeException
- * @expectedException Unable to write phar:
- */
public function testBuildThrowsWhenTargetCanNotBeWritten()
{
if (!Phar::canWrite() || !file_exists('/dev/null')) {
@@ -87,6 +75,8 @@ public function testBuildThrowsWhenTargetCanNotBeWritten()
$pharer = new PharComposer(__DIR__ . '/../fixtures/03-project-with-phars/composer.json');
$pharer->setOutput(false);
$pharer->setTarget('/dev/null');
+
+ $this->setExpectedException('RuntimeException', 'Unable to write phar:');
$pharer->build();
}
diff --git a/tests/Phar/TargetPharTest.php b/tests/Phar/TargetPharTest.php
index a5df41a..69fce43 100644
--- a/tests/Phar/TargetPharTest.php
+++ b/tests/Phar/TargetPharTest.php
@@ -19,25 +19,20 @@ class TargetPharTest extends TestCase
/**
* set up test environment
+ *
+ * @before
*/
- public function setUp()
+ public function setUpPhar()
{
if (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID <= 50600) {
$this->markTestSkipped('Unable to mock \Phar on PHP 5.4/5.5');
}
- $this->mockPhar = $this->createMock('\Phar');
- $this->mockPharComposer = $this->createMock('Clue\PharComposer\Phar\PharComposer');
+ $this->mockPhar = $this->getMockBuilder('\Phar')->disableOriginalConstructor()->getMock();
+ $this->mockPharComposer = $this->getMockBuilder('Clue\PharComposer\Phar\PharComposer')->disableOriginalConstructor()->getMock();
$this->targetPhar = new TargetPhar($this->mockPhar, $this->mockPharComposer);
}
- private function createMock($class)
- {
- return $this->getMockBuilder($class)
- ->disableOriginalConstructor()
- ->getMock();
- }
-
/**
* @test
*/
@@ -59,7 +54,7 @@ public function addFileCalculatesLocalPartForBox()
public function buildFromIteratorProvidesBasePathForBox()
{
$mockPackage = new Package(array(), 'path/to/package');
- $mockTraversable = $this->getMock('\Iterator');
+ $mockTraversable = $this->getMockBuilder('\Iterator')->getMock();
$this->mockPharComposer->expects($this->once())
->method('getPackageRoot')
->willReturn($mockPackage);
@@ -83,7 +78,7 @@ public function addPackageAddsResourcesFromCalculatedBundle()
$this->mockPhar->expects($this->once())
->method('addFile')
->with($this->equalTo('path/to/package/file.php'), $this->equalTo('file.php'));
- $mockFinder = $this->createMock('Symfony\Component\Finder\Finder');
+ $mockFinder = $this->getMockBuilder('Symfony\Component\Finder\Finder')->disableOriginalConstructor()->getMock();
$bundle->addDir($mockFinder);
$mockPackage = new Package(array(), 'path/to/package');
$this->mockPharComposer->expects($this->once())
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index c41ce49..41a0c98 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,8 +1,25 @@
expectException($exception);
+ if ($exceptionMessage !== '') {
+ $this->expectExceptionMessage($exceptionMessage);
+ }
+ if ($exceptionCode !== null) {
+ $this->expectExceptionCode($exceptionCode);
+ }
+ } else {
+ // legacy PHPUnit 4
+ parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
+ }
+ }
}