Fixed missing the assert diff message of phpt in a teamcity output
Hi!
- I've added missed diff output in case of failure phpt test in
--teamcityconfiguration, when phpt scenario contains--EXPECT--section. - I've put the diff output in case of failure phpt test with section
--EXPECTF--into the same style as--EXPECT--.
Background
PHPUnit 9.5, failed test scenarious in *.phpt files, output in --teamcity
Note: --teamcity output is also used by PHPStorm, so all screenshot examples are taken from it.

As you can see:
--EXPECT--and--EXPECTF--output is different.<Click to see difference>tool is absent
First attempt
In the first attempt https://github.com/sebastianbergmann/phpunit/commit/1086fedd4ea3df6ba6320a7d93cd33afecff4b2b I connected missed --EXPECT-- diff to the message, in the same style, as it had been done for --EXPECTF--
Pros:
- That were small code changes
Cons:
- Diff was printed as plained text, i.e. the tool
<Click to see difference>still hadn't work
First attempt result, the <Click to see difference> was absent:

Second attempt (current version)
I founded, that PHPStorm can work with diff in prettier way (you can see how common PHPUnit\Framework\TestCase works on top of screenshots), and I started to investigate.
I've discovered the following:
PHPTAssertionFailedErroris not consistent withExpectationFailedException, which works perfect inPHPUnit\Framework\TestCasetest cases.PHPTAssertionFailedErrordisplayed information in message for--EXPECTF--, because of https://github.com/sebastianbergmann/phpunit/pull/3659- Difference in
--EXPECT--and--EXPECTF--exists because phpunit uses different constraints:StringMatchesFormatDescriptionandIsEqual. The first one used it's ownattach diff in messageimplementation.
So, I fixed all of them together, because they are coupled. What has been done:
- Now
StringMatchesFormatDescriptionworks with expected diff as other classes: manipulates withComparisonFailureobject. I used the same idea of implementation as inJsonMatchesconstraint. - Interface
ComparisonFailureContainshas been created, to have possibility to acceptComparisonFailureobject from both classes:PHPTAssertionFailedErrorandExpectationFailedException - Added two end-to-end logger tests for both
--EXPECT--and--EXPECTF--cases.
In comparison with First attempt fix:
Pros:
- both phpt scenarios
--EXPECT--and--EXPECTF--have<Click to see difference> - framework class
src/Framework/TestFailure.phpbecame independed fromPHPTAssertionFailedError StringMatchesFormatDescriptionworks withComparisonFailureas all others.
Cons:
- More changes
Second attempt result:

Questions to maintainers:
- Please, let me know which solution is okay for PHPUnit, the First or the Second.
- Please, let me know whether I should do additional patches? And for which branches? This is 9.5 branch. Are patches in 8.5 enough? Or master also is required? Sorry, it is my very first PR in this repo, so I can't figure out whether this pr is a bugfix or a new feature
Thanks!
@sebastianbergmann Hi! May I wonder, do I violated some contribution guidelines or everything is ok from my side, and I just need wait some time? Thanks!
I did not have time to look into this yet, sorry.
Codecov Report
Merging #4831 (44313bf) into 9.5 (6bcc8e6) will increase coverage by
0.17%. The diff coverage is100.00%.
@@ Coverage Diff @@
## 9.5 #4831 +/- ##
============================================
+ Coverage 83.84% 84.02% +0.17%
+ Complexity 4633 4632 -1
============================================
Files 274 274
Lines 11972 11972
============================================
+ Hits 10038 10059 +21
+ Misses 1934 1913 -21
| Impacted Files | Coverage Δ | |
|---|---|---|
| ...Framework/Exception/ExpectationFailedException.php | 100.00% <ø> (ø) |
|
| src/Runner/PhptTestCase.php | 68.82% <ø> (+1.08%) |
:arrow_up: |
| ...nstraint/String/StringMatchesFormatDescription.php | 100.00% <100.00%> (ø) |
|
| ...c/Framework/Exception/PHPTAssertionFailedError.php | 100.00% <100.00%> (ø) |
|
| src/Framework/TestFailure.php | 100.00% <100.00%> (ø) |
|
| src/Util/Log/TeamCity.php | 71.73% <100.00%> (+13.04%) |
:arrow_up: |
| src/Framework/Constraint/Constraint.php | 97.36% <0.00%> (-2.64%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 6bcc8e6...44313bf. Read the comment docs.
@sebastianbergmann sorry for ping, I talked with you about this PR on Symfony conf in Disney :) It would be very kind if you found time to answer two questions
- Please, let me know which solution is okay for PHPUnit, the First or the Second.
- Please, let me know whether I should do additional patches? And for which branches? This is 9.5 branch. Are patches in 8.5 enough? Or master also is required? Sorry, it is my very first PR in this repo, so I can't figure out whether this pr is a bugfix or a new feature
Then, if this PR is actual, I help with refactoring for master and release it in Phpunit 10 Thanks!