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

Yoast / PHPUnit-Polyfills / 8548419439

04 Apr 2024 02:28AM UTC coverage: 96.232% (-1.0%) from 97.254%
8548419439

push

github

jrfnl
Tests: minor tweaks to work round PHP 8.4 deprecation

PHP 8.4 deprecates implicitly nullable parameters, i.e. typed parameter with a `null` default value, which are not explicitly declared as nullable.

The `ValueObject` fixture used in these tests used one such implicitly nullable parameters.

The tests for the `AssertObjectEquals` trait already needed two test classes to allow the method to be fully tests cross-version:
* One set which was run on PHPUnit < 9.4.0.
* One set which runs against PHP 7.0+.

As the nullability operator was introduced in PHP 7.1 and the particular test affected _does_ need to be typed to still test what it is supposed to test, I'm changing the requirements both test sets:
* The requirement for the first set of tests will now be PHPUnit < 9.4.0 AND PHP < 8.4.
* The requirement for the second set of test will now be PHP 7.1+.

This way the tests still covers the trait sufficiently.

_Note: the trait itself is not affected by the deprecation._

664 of 690 relevant lines covered (96.23%)

60.9 hits per line

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

77.78
/src/TestListeners/TestListenerDefaultImplementationPHPUnitLte5.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 4.x and 5.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
 * {@internal While in essence this trait is no different from the PHPUnit 6.x version, this
21
 * version is necessary as the class/interface name type declarations used in the PHPUnit 6.x
22
 * file are based on the namespaced names. As both the namespaced names as well as the
23
 * non-namespaced names exist in PHPUnit 4.8.36+/5.7.21+, we cannot create class aliases to
24
 * get round the signature mismatch and need this trait using the old names instead.}
25
 */
26
trait TestListenerDefaultImplementation {
27

28
        use TestListenerSnakeCaseMethods;
29

30
        /**
31
         * An error occurred.
32
         *
33
         * @param PHPUnit_Framework_Test $test Test object.
34
         * @param Exception              $e    Instance of the error encountered.
35
         * @param float                  $time Execution time of this test.
36
         *
37
         * @return void
38
         */
39
        public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
6✔
40
                $this->add_error( $test, $e, $time );
6✔
41
        }
6✔
42

43
        /**
44
         * A warning occurred.
45
         *
46
         * This method is only functional in PHPUnit 6.0 and above.
47
         *
48
         * @param PHPUnit_Framework_Test    $test Test object.
49
         * @param PHPUnit_Framework_Warning $e    Instance of the warning encountered.
50
         * @param float                     $time Execution time of this test.
51
         *
52
         * @return void
53
         */
54
        public function addWarning( PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time ) {
4✔
55
                $this->add_warning( $test, $e, $time );
4✔
56
        }
4✔
57

58
        /**
59
         * A failure occurred.
60
         *
61
         * @param PHPUnit_Framework_Test                 $test Test object.
62
         * @param PHPUnit_Framework_AssertionFailedError $e    Instance of the assertion failure
63
         *                                                     exception encountered.
64
         * @param float                                  $time Execution time of this test.
65
         *
66
         * @return void
67
         */
68
        public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time ) {
6✔
69
                $this->add_failure( $test, $e, $time );
6✔
70
        }
6✔
71

72
        /**
73
         * Incomplete test.
74
         *
75
         * @param PHPUnit_Framework_Test $test Test object.
76
         * @param Exception              $e    Instance of the incomplete test exception.
77
         * @param float                  $time Execution time of this test.
78
         *
79
         * @return void
80
         */
81
        public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
6✔
82
                $this->add_incomplete_test( $test, $e, $time );
6✔
83
        }
6✔
84

85
        /**
86
         * Risky test.
87
         *
88
         * @param PHPUnit_Framework_Test $test Test object.
89
         * @param Exception              $e    Instance of the risky test exception.
90
         * @param float                  $time Execution time of this test.
91
         *
92
         * @return void
93
         */
94
        public function addRiskyTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
×
95
                $this->add_risky_test( $test, $e, $time );
×
96
        }
97

98
        /**
99
         * Skipped test.
100
         *
101
         * @param PHPUnit_Framework_Test $test Test object.
102
         * @param Exception              $e    Instance of the skipped test exception.
103
         * @param float                  $time Execution time of this test.
104
         *
105
         * @return void
106
         */
107
        public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
6✔
108
                $this->add_skipped_test( $test, $e, $time );
6✔
109
        }
6✔
110

111
        /**
112
         * A test suite started.
113
         *
114
         * @param PHPUnit_Framework_TestSuite $suite Test suite object.
115
         *
116
         * @return void
117
         */
118
        public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
×
119
                $this->start_test_suite( $suite );
×
120
        }
121

122
        /**
123
         * A test suite ended.
124
         *
125
         * @param PHPUnit_Framework_TestSuite $suite Test suite object.
126
         *
127
         * @return void
128
         */
129
        public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
×
130
                $this->end_test_suite( $suite );
×
131
        }
132

133
        /**
134
         * A test started.
135
         *
136
         * @param PHPUnit_Framework_Test $test Test object.
137
         *
138
         * @return void
139
         */
140
        public function startTest( PHPUnit_Framework_Test $test ) {
34✔
141
                $this->start_test( $test );
34✔
142
        }
34✔
143

144
        /**
145
         * A test ended.
146
         *
147
         * @param PHPUnit_Framework_Test $test Test object.
148
         * @param float                  $time Execution time of this test.
149
         *
150
         * @return void
151
         */
152
        public function endTest( PHPUnit_Framework_Test $test, $time ) {
34✔
153
                $this->end_test( $test, $time );
34✔
154
        }
34✔
155
}
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