• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / PHPUnit-Polyfills / 10681740284

03 Sep 2024 11:06AM UTC coverage: 97.152% (+0.004%) from 97.148%
10681740284

push

github

jrfnl
PHPUnit 11.3.1 | AssertIsList: sync error message with upstream

PHPUnit 11.3.1 improved the type information in select assertion failure messages.

For the polyfills, this only affects the `AssertIsList` polyfill.

Now the choice was between the following:
* Just update the test(s) to have a different message expectation for PHPUnit 11.3.1+.
* Update the polyfills to mirror the improvement made in PHPUnit upstream.

I've chosen to implement the latter as it makes the message significantly more informative.

This means that on PHPUnit 6.x to 9.x and 11.3.1+, the new, improved message is shown. While on PHPUnit 10.0 - 11.3.0, the "old" message is shown as, in that case, the PHPUnit native `assertIsList()` method is used without the message improvements.

Includes:
* Renaming the `assertIsListFailureDescription()` method parameter from `$other` to `$value` to be more descriptive.
* Updating the tests, including adding an extra test with an anonymous class as that has separate handling for the error message in the polyfill.

Refs:
* https://github.com/sebastianbergmann/phpunit/commit/5e8b79e52
* https://github.com/sebastianbergmann/phpunit/commit/42cfc7d59

14 of 14 new or added lines in 1 file covered. (100.0%)

2 existing lines in 1 file now uncovered.

580 of 597 relevant lines covered (97.15%)

124.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/TestListeners/TestListenerDefaultImplementationPHPUnit6.php
1
<?php
2

3
namespace Yoast\PHPUnitPolyfills\TestListeners;
4

5
use Exception;
6
use PHPUnit\Framework\AssertionFailedError;
7
use PHPUnit\Framework\Test;
8
use PHPUnit\Framework\TestSuite;
9
use PHPUnit\Framework\Warning;
10

11
/**
12
 * Basic TestListener implementation for use with PHPUnit 6.x.
13
 *
14
 * This TestListener trait uses renamed (snakecase) methods for all standard methods in
15
 * a TestListener to get round the method signature changes in various PHPUnit versions.
16
 *
17
 * When using this TestListener trait, the snake_case method names need to be used to implement
18
 * the listener functionality.
19
 */
20
trait TestListenerDefaultImplementation {
21

22
        use TestListenerSnakeCaseMethods;
23

24
        /**
25
         * An error occurred.
26
         *
27
         * @param Test      $test Test object.
28
         * @param Exception $e    Instance of the error encountered.
29
         * @param float     $time Execution time of this test.
30
         *
31
         * @return void
32
         */
33
        public function addError( Test $test, Exception $e, $time ) {
4✔
34
                $this->add_error( $test, $e, $time );
4✔
35
        }
4✔
36

37
        /**
38
         * A warning occurred.
39
         *
40
         * This method is only functional in PHPUnit 6.0 and above.
41
         *
42
         * @param Test    $test Test object.
43
         * @param Warning $e    Instance of the warning encountered.
44
         * @param float   $time Execution time of this test.
45
         *
46
         * @return void
47
         */
48
        public function addWarning( Test $test, Warning $e, $time ) {
4✔
49
                $this->add_warning( $test, $e, $time );
4✔
50
        }
4✔
51

52
        /**
53
         * A failure occurred.
54
         *
55
         * @param Test                 $test Test object.
56
         * @param AssertionFailedError $e    Instance of the assertion failure exception encountered.
57
         * @param float                $time Execution time of this test.
58
         *
59
         * @return void
60
         */
61
        public function addFailure( Test $test, AssertionFailedError $e, $time ) {
4✔
62
                $this->add_failure( $test, $e, $time );
4✔
63
        }
4✔
64

65
        /**
66
         * Incomplete test.
67
         *
68
         * @param Test      $test Test object.
69
         * @param Exception $e    Instance of the incomplete test exception.
70
         * @param float     $time Execution time of this test.
71
         *
72
         * @return void
73
         */
74
        public function addIncompleteTest( Test $test, Exception $e, $time ) {
4✔
75
                $this->add_incomplete_test( $test, $e, $time );
4✔
76
        }
4✔
77

78
        /**
79
         * Risky test.
80
         *
81
         * @param Test      $test Test object.
82
         * @param Exception $e    Instance of the risky test exception.
83
         * @param float     $time Execution time of this test.
84
         *
85
         * @return void
86
         */
87
        public function addRiskyTest( Test $test, Exception $e, $time ) {
4✔
88
                $this->add_risky_test( $test, $e, $time );
4✔
89
        }
4✔
90

91
        /**
92
         * Skipped test.
93
         *
94
         * @param Test      $test Test object.
95
         * @param Exception $e    Instance of the skipped test exception.
96
         * @param float     $time Execution time of this test.
97
         *
98
         * @return void
99
         */
100
        public function addSkippedTest( Test $test, Exception $e, $time ) {
4✔
101
                $this->add_skipped_test( $test, $e, $time );
4✔
102
        }
4✔
103

104
        /**
105
         * A test suite started.
106
         *
107
         * @param TestSuite $suite Test suite object.
108
         *
109
         * @return void
110
         */
111
        public function startTestSuite( TestSuite $suite ) {
×
112
                $this->start_test_suite( $suite );
×
113
        }
114

115
        /**
116
         * A test suite ended.
117
         *
118
         * @param TestSuite $suite Test suite object.
119
         *
120
         * @return void
121
         */
122
        public function endTestSuite( TestSuite $suite ) {
×
123
                $this->end_test_suite( $suite );
×
124
        }
125

126
        /**
127
         * A test started.
128
         *
129
         * @param Test $test Test object.
130
         *
131
         * @return void
132
         */
133
        public function startTest( Test $test ) {
28✔
134
                $this->start_test( $test );
28✔
135
        }
28✔
136

137
        /**
138
         * A test ended.
139
         *
140
         * @param Test  $test Test object.
141
         * @param float $time Execution time of this test.
142
         *
143
         * @return void
144
         */
145
        public function endTest( Test $test, $time ) {
28✔
146
                $this->end_test( $test, $time );
28✔
147
        }
28✔
148
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc