• 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

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 ) {
2✔
34
                $this->add_error( $test, $e, $time );
2✔
35
        }
2✔
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 ) {
2✔
49
                $this->add_warning( $test, $e, $time );
2✔
50
        }
2✔
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 ) {
2✔
62
                $this->add_failure( $test, $e, $time );
2✔
63
        }
2✔
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 ) {
2✔
75
                $this->add_incomplete_test( $test, $e, $time );
2✔
76
        }
2✔
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 ) {
2✔
88
                $this->add_risky_test( $test, $e, $time );
2✔
89
        }
2✔
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 ) {
2✔
101
                $this->add_skipped_test( $test, $e, $time );
2✔
102
        }
2✔
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 ) {
14✔
134
                $this->start_test( $test );
14✔
135
        }
14✔
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 ) {
14✔
146
                $this->end_test( $test, $time );
14✔
147
        }
14✔
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