Skip to content

Commit

Permalink
Fix renamed file loader in phpunit (#127)
Browse files Browse the repository at this point in the history
* Use latest file loader from phpunit 7.0.
It was renamed from `Fileloader` to `FileLoader`

* Move check for the file loader class before actually calling it.
Some case sensitive issues is not allowing to add class alias.
Added phpunit ^7.0 tests om php version 7.2
Another run with `-x` on travis, as there was a problem with autoloading `\PHPUnit\Util\FileLoader` only if through phpunit.xml file

* Different handling on autloading for different cases in file loader for phpunit 7.0
ProcessorCounter now has new class for getting the OS so we can mock it. Tests were failing on MacOS
  • Loading branch information
lsimeonov authored and DonCallisto committed Mar 4, 2018
1 parent 1719190 commit f61c3b0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ cache:
before_script:
- composer selfupdate
- if [[ $TRAVIS_PHP_VERSION == 7.2 ]]; then
composer require "phpunit/phpunit:^6.1" --no-update;
composer require "phpunit/phpunit:^7.0" --no-update;
elif [[ $TRAVIS_PHP_VERSION == 7.1 ]]; then
composer require "phpunit/phpunit:^6.1" --no-update;
else
composer require "phpunit/phpunit:^5.7" --no-update;
composer require "phpunit/phpunit:^5.7" --no-update;
fi
- composer update $PREFER_LOWEST

script:
- find tests/ -name "*Test.php" | php fastest -v
- ./fastest -x phpunit.xml.dist -v "vendor/phpunit/phpunit/phpunit {};"
- bin/behat --config=adapters/Behat/behat.yml
12 changes: 10 additions & 2 deletions src/Process/ProcessorCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public function execute()

private function readFromProcCPUInfo()
{
if (PHP_OS === 'Darwin') {
if ($this->getOS() === 'Darwin') {
$processors = system('/usr/sbin/sysctl -n hw.physicalcpu');

if (false !== $processors && $processors) {
return $processors;
}
} elseif (PHP_OS === 'Linux') {
} elseif ($this->getOS() === 'Linux') {
$file = $this->procCPUInfo;
if (is_file($file) && is_readable($file)) {
try {
Expand All @@ -60,4 +60,12 @@ private function readFromProcCPUInfo()

return self::PROC_DEFAULT_NUMBER;
}

/**
* @return string
*/
public function getOS()
{
return PHP_OS;
}
}
15 changes: 12 additions & 3 deletions src/Queue/CreateTestsQueueFromPhpUnitXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class_alias('\PHPUnit_Util_TestSuiteIterator', '\PHPUnit\Framework\TestSuiteIter
class_alias('\PHPUnit_Util_Fileloader', '\PHPUnit\Util\Fileloader');
}

/*
* Trigger autoload for possible file loader versions.
* This fixes the problem with PHP classes being case insensitive versus composer case sensitive autoloader.
*/
class_exists('\PHPUnit\Util\Fileloader');
class_exists('\PHPUnit\Util\FileLoader');

class CreateTestsQueueFromPhpUnitXML
{
public static function execute($xmlFile)
Expand All @@ -32,8 +39,10 @@ public static function execute($xmlFile)
return $testSuites;
}

private static function processTestSuite(TestsQueue $testSuites, \PHPUnit\Framework\TestSuiteIterator $testSuiteIterator)
{
private static function processTestSuite(
TestsQueue $testSuites,
\PHPUnit\Framework\TestSuiteIterator $testSuiteIterator
) {
foreach ($testSuiteIterator as $testSuite) {
self::addTestFile($testSuites, $testSuite);

Expand Down Expand Up @@ -61,6 +70,6 @@ private static function handleBootstrap(array $config)
{
$filename = isset($config['bootstrap']) ? $config['bootstrap'] : 'vendor/autoload.php';

\PHPUnit\Util\Fileloader::checkAndLoad($filename);
\PHPUnit\Util\FileLoader::checkAndLoad($filename);
}
}
11 changes: 9 additions & 2 deletions tests/Process/ProcessorCounterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ class ProcessorCounterTest extends \PHPUnit\Framework\TestCase
*/
public function shouldCountTheNumberOfProcessorInLinux()
{
$processorCount = new ProcessorCounter(__DIR__.'/Fixture/proc_cpuinfo');
$processorCountMock = $this->getMockBuilder(ProcessorCounter::class)
->setMethods(['getOS'])
->setConstructorArgs([__DIR__.'/Fixture/proc_cpuinfo'])
->getMock();

$this->assertEquals(4, $processorCount->execute());
$processorCountMock->expects($this->any())
->method('getOS')
->will($this->returnValue('Linux'));

$this->assertEquals(4, $processorCountMock->execute());
}
}

0 comments on commit f61c3b0

Please sign in to comment.