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

Yoast / PHPUnit-Polyfills / 12737180940

12 Jan 2025 09:19PM UTC coverage: 97.628% (-0.3%) from 97.912%
12737180940

Pull #238

github

jrfnl
Drop support for PHP < 7.1 [3]

Remove the PHP 7.1+ specific test fixtures for the `AssertObjectEquals` and `AssertObjectNotEquals` tests.

As support for PHP < 7.1 has been dropped, these fixture methods no longer need their own class and can be moved into the main test fixture.
Pull Request #238: 4.0 | Drop support for PHP < 7.1

6 of 6 new or added lines in 2 files covered. (100.0%)

4 existing lines in 1 file now uncovered.

782 of 801 relevant lines covered (97.63%)

114.06 hits per line

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

94.44
/src/Polyfills/AssertIsType.php
1
<?php
2

3
namespace Yoast\PHPUnitPolyfills\Polyfills;
4

5
use Traversable;
6

7
/**
8
 * Polyfill the Assert::assertIsBool(), Assert::assertIsNotBool() etc methods, which
9
 * replace the Assert::assertInternalType() and Assert::assertNotInternalType() methods.
10
 *
11
 * Introduced in PHPUnit 7.5.0.
12
 * The Assert::assertInternalType() and Assert::assertNotInternalType() methods were
13
 * deprecated in PHPUnit 7.5.0 and removed in PHPUnit 9.0.0.
14
 *
15
 * @link https://github.com/sebastianbergmann/phpunit/issues/3368
16
 * @link https://github.com/sebastianbergmann/phpunit/issues/3369
17
 *
18
 * @since 0.1.0
19
 */
20
trait AssertIsType {
21

22
        /**
23
         * Asserts that a variable is of type array.
24
         *
25
         * @param mixed  $actual  The value to test.
26
         * @param string $message Optional failure message to display.
27
         *
28
         * @return void
29
         */
30
        final public static function assertIsArray( $actual, $message = '' ) {
4✔
31
                static::assertInternalType( 'array', $actual, $message );
4✔
32
        }
4✔
33

34
        /**
35
         * Asserts that a variable is of type bool.
36
         *
37
         * @param mixed  $actual  The value to test.
38
         * @param string $message Optional failure message to display.
39
         *
40
         * @return void
41
         */
42
        final public static function assertIsBool( $actual, $message = '' ) {
4✔
43
                static::assertInternalType( 'bool', $actual, $message );
4✔
44
        }
4✔
45

46
        /**
47
         * Asserts that a variable is of type float.
48
         *
49
         * @param mixed  $actual  The value to test.
50
         * @param string $message Optional failure message to display.
51
         *
52
         * @return void
53
         */
54
        final public static function assertIsFloat( $actual, $message = '' ) {
4✔
55
                static::assertInternalType( 'float', $actual, $message );
4✔
56
        }
4✔
57

58
        /**
59
         * Asserts that a variable is of type int.
60
         *
61
         * @param mixed  $actual  The value to test.
62
         * @param string $message Optional failure message to display.
63
         *
64
         * @return void
65
         */
66
        final public static function assertIsInt( $actual, $message = '' ) {
4✔
67
                static::assertInternalType( 'int', $actual, $message );
4✔
68
        }
4✔
69

70
        /**
71
         * Asserts that a variable is of type numeric.
72
         *
73
         * @param mixed  $actual  The value to test.
74
         * @param string $message Optional failure message to display.
75
         *
76
         * @return void
77
         */
78
        final public static function assertIsNumeric( $actual, $message = '' ) {
4✔
79
                static::assertInternalType( 'numeric', $actual, $message );
4✔
80
        }
4✔
81

82
        /**
83
         * Asserts that a variable is of type object.
84
         *
85
         * @param mixed  $actual  The value to test.
86
         * @param string $message Optional failure message to display.
87
         *
88
         * @return void
89
         */
90
        final public static function assertIsObject( $actual, $message = '' ) {
4✔
91
                static::assertInternalType( 'object', $actual, $message );
4✔
92
        }
4✔
93

94
        /**
95
         * Asserts that a variable is of type resource.
96
         *
97
         * @param mixed  $actual  The value to test.
98
         * @param string $message Optional failure message to display.
99
         *
100
         * @return void
101
         */
102
        final public static function assertIsResource( $actual, $message = '' ) {
8✔
103
                static::assertInternalType( 'resource', $actual, $message );
8✔
104
        }
8✔
105

106
        /**
107
         * Asserts that a variable is of type string.
108
         *
109
         * @param mixed  $actual  The value to test.
110
         * @param string $message Optional failure message to display.
111
         *
112
         * @return void
113
         */
114
        final public static function assertIsString( $actual, $message = '' ) {
4✔
115
                static::assertInternalType( 'string', $actual, $message );
4✔
116
        }
4✔
117

118
        /**
119
         * Asserts that a variable is of type scalar.
120
         *
121
         * @param mixed  $actual  The value to test.
122
         * @param string $message Optional failure message to display.
123
         *
124
         * @return void
125
         */
126
        final public static function assertIsScalar( $actual, $message = '' ) {
4✔
127
                static::assertInternalType( 'scalar', $actual, $message );
4✔
128
        }
4✔
129

130
        /**
131
         * Asserts that a variable is of type callable.
132
         *
133
         * @param mixed  $actual  The value to test.
134
         * @param string $message Optional failure message to display.
135
         *
136
         * @return void
137
         */
138
        final public static function assertIsCallable( $actual, $message = '' ) {
4✔
139
                static::assertInternalType( 'callable', $actual, $message );
4✔
140
        }
4✔
141

142
        /**
143
         * Asserts that a variable is of type iterable.
144
         *
145
         * {@internal Support for `iterable` was only added to the `Assert::assertInternalType()` method
146
         * in PHPUnit 7.1.0, so this polyfill can't use a direct fall-through to that functionality
147
         * until the minimum supported PHPUnit version of this library would be PHPUnit 7.1.0.}
148
         *
149
         * @link https://github.com/sebastianbergmann/phpunit/pull/3035 PR which added support for `is_iterable`
150
         *                                                              to `Assert::assertInternalType()`.
151
         *
152
         * @param mixed  $actual  The value to test.
153
         * @param string $message Optional failure message to display.
154
         *
155
         * @return void
156
         */
157
        final public static function assertIsIterable( $actual, $message = '' ) {
4✔
158
                if ( \function_exists( 'is_iterable' ) === true ) {
4✔
159
                        // PHP >= 7.1.
160
                        // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.is_iterableFound
161
                        static::assertTrue( \is_iterable( $actual ), $message );
4✔
162
                }
163
                else {
164
                        // PHP < 7.1.
UNCOV
165
                        $result = ( \is_array( $actual ) || $actual instanceof Traversable );
×
UNCOV
166
                        static::assertTrue( $result, $message );
×
167
                }
168
        }
4✔
169

170
        /**
171
         * Asserts that a variable is not of type array.
172
         *
173
         * @param mixed  $actual  The value to test.
174
         * @param string $message Optional failure message to display.
175
         *
176
         * @return void
177
         */
178
        final public static function assertIsNotArray( $actual, $message = '' ) {
4✔
179
                static::assertNotInternalType( 'array', $actual, $message );
4✔
180
        }
4✔
181

182
        /**
183
         * Asserts that a variable is not of type bool.
184
         *
185
         * @param mixed  $actual  The value to test.
186
         * @param string $message Optional failure message to display.
187
         *
188
         * @return void
189
         */
190
        final public static function assertIsNotBool( $actual, $message = '' ) {
4✔
191
                static::assertNotInternalType( 'bool', $actual, $message );
4✔
192
        }
4✔
193

194
        /**
195
         * Asserts that a variable is not of type float.
196
         *
197
         * @param mixed  $actual  The value to test.
198
         * @param string $message Optional failure message to display.
199
         *
200
         * @return void
201
         */
202
        final public static function assertIsNotFloat( $actual, $message = '' ) {
4✔
203
                static::assertNotInternalType( 'float', $actual, $message );
4✔
204
        }
4✔
205

206
        /**
207
         * Asserts that a variable is not of type int.
208
         *
209
         * @param mixed  $actual  The value to test.
210
         * @param string $message Optional failure message to display.
211
         *
212
         * @return void
213
         */
214
        final public static function assertIsNotInt( $actual, $message = '' ) {
4✔
215
                static::assertNotInternalType( 'int', $actual, $message );
4✔
216
        }
4✔
217

218
        /**
219
         * Asserts that a variable is not of type numeric.
220
         *
221
         * @param mixed  $actual  The value to test.
222
         * @param string $message Optional failure message to display.
223
         *
224
         * @return void
225
         */
226
        final public static function assertIsNotNumeric( $actual, $message = '' ) {
4✔
227
                static::assertNotInternalType( 'numeric', $actual, $message );
4✔
228
        }
4✔
229

230
        /**
231
         * Asserts that a variable is not of type object.
232
         *
233
         * @param mixed  $actual  The value to test.
234
         * @param string $message Optional failure message to display.
235
         *
236
         * @return void
237
         */
238
        final public static function assertIsNotObject( $actual, $message = '' ) {
4✔
239
                static::assertNotInternalType( 'object', $actual, $message );
4✔
240
        }
4✔
241

242
        /**
243
         * Asserts that a variable is not of type resource.
244
         *
245
         * @param mixed  $actual  The value to test.
246
         * @param string $message Optional failure message to display.
247
         *
248
         * @return void
249
         */
250
        final public static function assertIsNotResource( $actual, $message = '' ) {
4✔
251
                static::assertNotInternalType( 'resource', $actual, $message );
4✔
252
        }
4✔
253

254
        /**
255
         * Asserts that a variable is not of type string.
256
         *
257
         * @param mixed  $actual  The value to test.
258
         * @param string $message Optional failure message to display.
259
         *
260
         * @return void
261
         */
262
        final public static function assertIsNotString( $actual, $message = '' ) {
4✔
263
                static::assertNotInternalType( 'string', $actual, $message );
4✔
264
        }
4✔
265

266
        /**
267
         * Asserts that a variable is not of type scalar.
268
         *
269
         * @param mixed  $actual  The value to test.
270
         * @param string $message Optional failure message to display.
271
         *
272
         * @return void
273
         */
274
        final public static function assertIsNotScalar( $actual, $message = '' ) {
4✔
275
                static::assertNotInternalType( 'scalar', $actual, $message );
4✔
276
        }
4✔
277

278
        /**
279
         * Asserts that a variable is not of type callable.
280
         *
281
         * @param mixed  $actual  The value to test.
282
         * @param string $message Optional failure message to display.
283
         *
284
         * @return void
285
         */
286
        final public static function assertIsNotCallable( $actual, $message = '' ) {
4✔
287
                static::assertNotInternalType( 'callable', $actual, $message );
4✔
288
        }
4✔
289

290
        /**
291
         * Asserts that a variable is not of type iterable.
292
         *
293
         * {@internal Support for `iterable` was only added to the `Assert::assertNotInternalType()` method
294
         * in PHPUnit 7.1.0, so this polyfill can't use a direct fall-through to that functionality
295
         * until the minimum supported PHPUnit version of this library would be PHPUnit 7.1.0.}
296
         *
297
         * @link https://github.com/sebastianbergmann/phpunit/pull/3035 PR which added support for `is_iterable`
298
         *                                                              to `Assert::assertNotInternalType()`.
299
         *
300
         * @param mixed  $actual  The value to test.
301
         * @param string $message Optional failure message to display.
302
         *
303
         * @return void
304
         */
305
        final public static function assertIsNotIterable( $actual, $message = '' ) {
4✔
306
                if ( \function_exists( 'is_iterable' ) === true ) {
4✔
307
                        // PHP >= 7.1.
308
                        // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.is_iterableFound
309
                        static::assertFalse( \is_iterable( $actual ), $message );
4✔
310
                }
311
                else {
312
                        // PHP < 7.1.
UNCOV
313
                        $result = ( \is_array( $actual ) || $actual instanceof Traversable );
×
UNCOV
314
                        static::assertFalse( $result, $message );
×
315
                }
316
        }
4✔
317
}
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

© 2026 Coveralls, Inc