Skip to content

Commit

Permalink
Merge pull request #191 from brianium/php7
Browse files Browse the repository at this point in the history
PHP 7 & PHPUnit 5
  • Loading branch information
julianseeger committed Jan 15, 2016
2 parents 15caf61 + 0aa3e7d commit abf2f46
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ matrix:
fast_finish: true
allow_failures:
- env: PHPUNIT_VERSION='*@dev'
- php: 7.0
exclude:
- php: 5.5
env: PHPUNIT_VERSION='5.*@stable'

env:
- PHPUNIT_VERSION='3.7.*@stable'
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"brianium/habitat": "1.0.0",
"ext-reflection": "*",
"ext-simplexml": "*",
"ext-pcre": "*"
"ext-pcre": "*",
"composer/semver": "~1.2.0"
},
"type": "library",
"description": "Parallel testing for PHP",
Expand Down
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@
<directory>./test/functional/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
13 changes: 13 additions & 0 deletions src/ParaTest/Console/Commands/ParaTestCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace ParaTest\Console\Commands;

use Composer\Semver\Comparator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -20,6 +21,14 @@ public function __construct(Tester $tester)
$this->tester->configure($this);
}

/**
* @return bool
*/
public static function isWhitelistSupported()
{
return Comparator::greaterThanOrEqualTo(\PHPUnit_Runner_Version::id(), '5.0.0');
}

/**
* Ubiquitous configuration options for ParaTest
*/
Expand All @@ -35,6 +44,10 @@ protected function configure()
->addOption('coverage-php', null, InputOption::VALUE_REQUIRED, 'Serialize PHP_CodeCoverage object to file.')
->addOption('max-batch-size', 'm', InputOption::VALUE_REQUIRED, 'Max batch size (only for functional mode).', 0)
->addOption('filter', null, InputOption::VALUE_REQUIRED, 'Filter (only for functional mode).');

if (self::isWhitelistSupported()) {
$this->addOption('whitelist', null, InputOption::VALUE_REQUIRED, 'Directory to add to the coverage whitelist.');
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions test/functional/PHPUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ public function testRunWithFatalParseErrorsHasExitCode255()

public function testRunWithFatalRuntimeErrorsHasExitCode1()
{
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('fatals are handled like normal exceptions with php7');
}
$proc = $this->invokeParatest('fatal-tests/UnitTestWithFatalFunctionErrorTest.php', array(
'bootstrap' => BOOTSTRAP
));
Expand All @@ -221,6 +224,9 @@ public function testRunWithFatalRuntimeErrorsHasExitCode1()

public function testRunWithFatalRuntimeErrorOutputsError()
{
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('fatals are handled like normal exceptions with php7');
}
$proc = $this->invokeParatest('fatal-tests/UnitTestWithFatalFunctionErrorTest.php', array(
'bootstrap' => BOOTSTRAP
));
Expand All @@ -229,6 +235,9 @@ public function testRunWithFatalRuntimeErrorOutputsError()

public function testRunWithFatalRuntimeErrorWithTheWrapperRunnerOutputsError()
{
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('fatals are handled like normal exceptions with php7');
}
$proc = $this->invokeParatest('fatal-tests/UnitTestWithFatalFunctionErrorTest.php', array(
'bootstrap' => BOOTSTRAP,
'runner' => 'WrapperRunner'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php namespace ParaTest\Runners\PHPUnit;

use ParaTest\Console\Commands\ParaTestCommand;

class RunnerIntegrationTest extends \TestBase
{
/** @var Runner $runner */
protected $runner;
protected $options;

Expand All @@ -19,6 +22,9 @@ public function setUp()
'coverage-php' => sys_get_temp_dir() . DS . 'testcoverage.php',
'bootstrap' => BOOTSTRAP
);
if (ParaTestCommand::isWhitelistSupported()) {
$this->options['whitelist'] = FIXTURES . DS . 'failing-tests';
}
$this->runner = new Runner($this->options);
}

Expand Down
3 changes: 3 additions & 0 deletions test/functional/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public function testRunningFewerTestsThanTheWorkersIsPossible()

public function testFatalErrorsAreReported()
{
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('fatals are handled like normal exceptions with php7');
}
$proc = $this->invokeParatest('fatal-tests/UnitTestWithFatalFunctionErrorTest.php', array(
'runner' => 'WrapperRunner',
'processes' => 1,
Expand Down
8 changes: 6 additions & 2 deletions test/unit/ParaTest/Console/Commands/ParaTestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testConstructor()
*/
public function testConfiguredDefinitionWithPHPUnitTester()
{
$expected = new InputDefinition(array(
$options = array(
new InputOption('processes', 'p', InputOption::VALUE_REQUIRED, 'The number of test processes to run.', 5),
new InputOption('functional', 'f', InputOption::VALUE_NONE, 'Run methods instead of suites in separate processes.'),
new InputOption('help', 'h', InputOption::VALUE_NONE, 'Display this help message.'),
Expand All @@ -50,7 +50,11 @@ public function testConfiguredDefinitionWithPHPUnitTester()
new InputOption('testsuite', null, InputOption::VALUE_OPTIONAL, 'Filter which testsuite to run'),
new InputOption('max-batch-size', 'm', InputOption::VALUE_REQUIRED, 'Max batch size (only for functional mode).', 0),
new InputOption('filter', null, InputOption::VALUE_REQUIRED, 'Filter (only for functional mode).'),
));
);
if (ParaTestCommand::isWhitelistSupported()) {
$options[] = new InputOption('whitelist', null, InputOption::VALUE_REQUIRED, 'Directory to add to the coverage whitelist.');
}
$expected = new InputDefinition($options);
$definition = $this->command->getDefinition();
$this->assertEquals($expected, $definition);
}
Expand Down
6 changes: 4 additions & 2 deletions test/unit/ParaTest/Coverage/CoverageMergerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ public function testSimpleMerge()
$firstFile = PARATEST_ROOT . '/src/ParaTest/Logging/LogInterpreter.php';
$secondFile = PARATEST_ROOT . '/src/ParaTest/Logging/MetaProvider.php';

$coverage1 = new \PHP_CodeCoverage();
$filter = new \PHP_CodeCoverage_Filter();
$filter->addFilesToWhitelist([$firstFile, $secondFile]);
$coverage1 = new \PHP_CodeCoverage(null, $filter);
$coverage1->append(
array(
$firstFile => array(35 => 1),
$secondFile => array(34 => 1)
),
'Test1'
);
$coverage2 = new \PHP_CodeCoverage();
$coverage2 = new \PHP_CodeCoverage(null, $filter);
$coverage2->append(
array(
$firstFile => array(35 => 1, 36 => 1)
Expand Down

0 comments on commit abf2f46

Please sign in to comment.