Skip to content

Support Phpunit 6 without impacting app runtime#10257

Merged
lorenzo merged 5 commits intomasterfrom
phpunit
Feb 21, 2017
Merged

Support Phpunit 6 without impacting app runtime#10257
lorenzo merged 5 commits intomasterfrom
phpunit

Conversation

@antograssiot
Copy link
Copy Markdown
Contributor

@antograssiot antograssiot commented Feb 20, 2017

Another attempt to support PHPUnit without forcing file loading for every request.

I tested it with composer installation and .phar for PHPUnit 5.7 and 6 but I would appreciate if one can quickly check one of is app using this branch to confirm it does work properly before it (cc @dereuromark )

I added a "conflict" definition in the composer.json to alert composer users.

Finally, what fo you think of adding the following code inside the ifs:

if (version_compare(\PHPUnit_Runner_Version::id(), '5.7', '<')) {
        trigger_error(sprintf('Your PHPUnit Version must be at least 5.7.0 to use CakePHP Testsuite, found %s', \PHPUnit_Runner_Version::id()), E_USER_ERROR);
    }

I think it can help people to better understand what's going on than getting an standard error that could looks like

.../cakephp/src/TestSuite/Fixture/FixtureInjector.php on line 38

@antograssiot antograssiot added this to the 3.4.2 milestone Feb 20, 2017
@codecov-io
Copy link
Copy Markdown

codecov-io commented Feb 20, 2017

Codecov Report

Merging #10257 into master will increase coverage by 0.03%.
The diff coverage is 50%.

@@             Coverage Diff              @@
##             master   #10257      +/-   ##
============================================
+ Coverage     94.88%   94.92%   +0.03%     
- Complexity    12067    12100      +33     
============================================
  Files           422      421       -1     
  Lines         29959    30040      +81     
============================================
+ Hits          28427    28514      +87     
+ Misses         1532     1526       -6
Impacted Files Coverage Δ Complexity Δ
src/TestSuite/IntegrationTestCase.php 87.76% <ø> (ø) 108 <ø> (ø)
src/TestSuite/Fixture/FixtureInjector.php 0% <ø> (ø) 16 <ø> (ø)
src/TestSuite/TestSuite.php 100% <ø> (ø) 6 <ø> (ø)
src/TestSuite/Constraint/EventFired.php 81.81% <50%> (-18.19%) 3 <ø> (ø)
src/TestSuite/Constraint/EventFiredWith.php 90.32% <50%> (-5.98%) 8 <ø> (ø)
src/I18n/RelativeTimeFormatter.php 95.02% <ø> (-0.5%) 72% <ø> (ø)
src/ORM/Behavior/CounterCacheBehavior.php 100% <ø> (ø) 51% <ø> (+19%)
src/ORM/EagerLoader.php 98.1% <ø> (+0.26%) 111% <ø> (+14%)
src/Cache/Engine/FileEngine.php 86.66% <ø> (+1.11%) 73% <ø> (ø)
src/Cache/CacheEngine.php 93.47% <ø> (+2.17%) 19% <ø> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aed66fa...53a575b. Read the comment docs.

@markstory
Copy link
Copy Markdown
Member

I think the proposed warning makes sense 👍

trigger_error(sprintf('Your PHPUnit Version must be at least 5.7.0 to use CakePHP Testsuite, found %s', \PHPUnit_Runner_Version::id()), E_USER_ERROR);
}
class_alias('PHPUnit_Framework_TestSuite', 'PHPUnit\Framework\TestSuite');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line found at end of control structure

@antograssiot
Copy link
Copy Markdown
Contributor Author

Ok I've added the warning and hopefully fix the issue users have.

@markstory Please don't merge this just yet, I'll try to get feedback from #10260

trigger_error(sprintf('Your PHPUnit Version must be at least 5.7.0 to use CakePHP Testsuite, found %s', \PHPUnit_Runner_Version::id()), E_USER_ERROR);
}
class_alias('PHPUnit_Framework_Test', 'PHPUnit\Framework\Test');
class_alias('PHPUnit_Framework_Warning', 'PHPUnit\Framework\Warning');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't these have class_exists() calls?

Copy link
Copy Markdown
Contributor Author

@antograssiot antograssiot Feb 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markstory my reasoning was the following:
If a old PHPUNIT version class is found, I need to define aliases
If I need to define the same aliases in several places, I check if it was not done already.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the PHPUnit_Framework_Version class also determines if PHPUnit <6 is present at all and only defines those aliases in this case

if (!class_exists('PHPUnit\Framework\TestSuite')) {
class_alias('PHPUnit_Framework_TestSuite', 'PHPUnit\Framework\TestSuite');
}
if (class_exists('PHPUnit_Runner_Version') && !class_exists('PHPUnit\Framework\AssertionFailedError')) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does one depend on the other?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove the first check it is already nested in

@lorenzo
Copy link
Copy Markdown
Member

lorenzo commented Feb 21, 2017

Great job @antograssiot

@lorenzo lorenzo merged commit 9c5f57f into master Feb 21, 2017
@lorenzo lorenzo deleted the phpunit branch February 21, 2017 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants