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

JBZoo / PHPUnit / 18063972714

27 Sep 2025 07:26PM UTC coverage: 3.077% (-62.3%) from 65.385%
18063972714

push

github

web-flow
build(phpunit): Bump PHPUnit to v11 (#36)

- Upgrades `phpunit/phpunit` from `^9.6.29` to `^11.5.41`.
- Adjusts `CovCatcher::start` to match the updated `php-code-coverage`
API, now requiring `null` for the second argument.
- Adds a check in `CovCatcher::getCoverageFilter` to prevent attempting
to include files from an empty directory path.

8 of 260 relevant lines covered (3.08%)

0.37 hits per line

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

0.0
/src/functions/aliases.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - PHPUnit.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/PHPUnit
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\PHPUnit;
18

19
use PHPUnit\Framework\Assert;
20

21
// Controls
22

23
/**
24
 * Skip current test.
25
 */
26
function skip(string $message): void
27
{
28
    Assert::markTestSkipped($message);
×
29
}
30

31
/**
32
 * Incomplete current test.
33
 */
34
function incomplete(string $message): void
35
{
36
    Assert::markTestIncomplete($message);
×
37
}
38

39
/**
40
 * Fail current test.
41
 */
42
function fail(string $message = ''): void
43
{
44
    Assert::fail($message);
×
45
}
46

47
/**
48
 * Success current test.
49
 */
50
function success(string $message = ''): void
51
{
52
    isTrue(true, $message);
×
53
}
54

55
// Asserts aliases
56

57
/**
58
 * @SuppressWarnings(PHPMD.ShortMethodName)
59
 */
60
function is(mixed $expected, mixed $actual, string $message = ''): void
61
{
62
    Assert::assertEquals($expected, $actual, $message);
×
63
}
64

65
function isNot(mixed $expected, mixed $actual, string $message = ''): void
66
{
67
    Assert::assertNotEquals($expected, $actual, $message);
×
68
}
69

70
function isTrue(mixed $value, string $message = ''): void
71
{
72
    Assert::assertTrue($value, $message);
×
73
}
74

75
function isFalse(mixed $value, string $message = ''): void
76
{
77
    Assert::assertFalse($value, $message);
×
78
}
79

80
/**
81
 * @param string $expected
82
 * @param mixed  $className
83
 *
84
 * @psalm-template ExpectedType of object
85
 * @psalm-param    class-string<ExpectedType> $expected
86
 * @phan-suppress  PhanPluginCanUseParamType
87
 */
88
function isClass($expected, $className, string $message = ''): void
89
{
90
    Assert::assertInstanceOf($expected, $className, $message);
×
91
}
92

93
function isCount(int $expected, mixed $actual, string $message = ''): void
94
{
95
    Assert::assertCount($expected, $actual, $message);
×
96
}
97

98
function isLike(string $pattern, string $value, string $message = ''): void
99
{
100
    Assert::assertMatchesRegularExpression($pattern, $value, $message);
×
101
}
102

103
function isNotLike(string $pattern, string $value, string $message = ''): void
104
{
105
    Assert::assertDoesNotMatchRegularExpression($pattern, $value, $message);
×
106
}
107

108
function isFileEq(string $filepathExpecte, string $filepathActual, string $message = ''): void
109
{
110
    Assert::assertFileEquals($filepathExpecte, $filepathActual, $message);
×
111
}
112

113
function isSame(mixed $expected, mixed $actual, string $message = ''): void
114
{
115
    Assert::assertSame($expected, $actual, $message);
×
116
}
117

118
function isNotSame(mixed $expected, mixed $actual, string $message = ''): void
119
{
120
    Assert::assertNotSame($expected, $actual, $message);
×
121
}
122

123
function isNull(mixed $expected): void
124
{
125
    Assert::assertNull($expected);
×
126
}
127

128
function isNotNull(mixed $expected): void
129
{
130
    Assert::assertNotNull($expected);
×
131
}
132

133
function isEmpty(mixed $expected, string $message = ''): void
134
{
135
    Assert::assertEmpty($expected, $message);
×
136
}
137

138
function isNotEmpty(mixed $expected, string $message = ''): void
139
{
140
    Assert::assertNotEmpty($expected, $message);
×
141
}
142

143
function isKey(int|string $key, array $array, string $message = ''): void
144
{
145
    Assert::assertArrayHasKey($key, $array, $message);
×
146
}
147

148
function isNotKey(int|string $key, array $array, string $message = ''): void
149
{
150
    Assert::assertArrayNotHasKey($key, $array, $message);
×
151
}
152

153
/**
154
 * Assert object has an attribute.
155
 */
156
function isAttr(string $attrName, mixed $object, string $message = ''): void
157
{
158
    Assert::assertNotNull($object, 'object ' . $object::class . " is not empty. {$message}");
×
159
    isTrue(\property_exists($object, $attrName));
×
160
}
161

162
/**
163
 * Assert object has an attribute.
164
 */
165
function isNotAttr(string $attrName, mixed $object, string $message = ''): void
166
{
167
    Assert::assertNotNull($object, 'object ' . $object::class . " is not empty. {$message}");
×
168
    isFalse(\property_exists($object, $attrName));
×
169
}
170

171
function isDir(string $directoryPath, string $message = ''): void
172
{
173
    Assert::assertFileExists($directoryPath, $message);
×
174
    Assert::assertDirectoryExists($directoryPath);
×
175
}
176

177
function isNotDir(string $notDirectoryPath, string $message = ''): void
178
{
179
    if (\is_dir($notDirectoryPath)) {
×
180
        fail("\"{$notDirectoryPath}\" is directory");
×
181
    } else {
182
        success($message);
×
183
    }
184
}
185

186
function isFile(string $filePath, string $message = ''): void
187
{
188
    Assert::assertFileExists($filePath, $message);
×
189
}
190

191
function isNotFile(string $notFilePath, string $message = ''): void
192
{
193
    if (!\is_dir($notFilePath)) {
×
194
        Assert::assertFileDoesNotExist($notFilePath, $message);
×
195
    } else {
196
        success($message);
×
197
    }
198
}
199

200
function isContain(string $expected, string $haystack, bool $ignoreCase = false, string $message = ''): void
201
{
202
    if ($ignoreCase) {
×
203
        Assert::assertStringContainsStringIgnoringCase($expected, $haystack, $message);
×
204
    } else {
205
        Assert::assertStringContainsString($expected, $haystack, $message);
×
206
    }
207
}
208

209
function isNotContain(string $expected, string $haystack, bool $ignoreCase = false, string $message = ''): void
210
{
211
    if ($ignoreCase) {
×
212
        Assert::assertStringNotContainsStringIgnoringCase($expected, $haystack, $message);
×
213
    } else {
214
        Assert::assertStringNotContainsString($expected, $haystack, $message);
×
215
    }
216
}
217

218
// Custom Asserts
219

220
function isEmail(string $email, string $message = ''): void
221
{
222
    isTrue((bool)\filter_var($email, \FILTER_VALIDATE_EMAIL), $message);
×
223
}
224

225
function isNotEmail(string $notEmail, string $message = ''): void
226
{
227
    isFalse((bool)\filter_var($notEmail, \FILTER_VALIDATE_EMAIL), $message);
×
228
}
229

230
function isCurrentDate(string $date, int $timeDiff = 300, string $message = ''): void
231
{
232
    $nowDate   = new \DateTime('now');
×
233
    $checkDate = new \DateTime($date);
×
234
    Assert::assertEqualsWithDelta($nowDate->getTimestamp(), $checkDate->getTimestamp(), $timeDiff, $message);
×
235
}
236

237
function isAmount(
238
    array|float|int|string $expected,
239
    array|float|int|string $actual,
240
    string $message = '',
241
    float $allowableDiff = 0.03,
242
): void {
243
    if (!\is_array($expected) && !\is_array($actual)) {
×
244
        Assert::assertEqualsWithDelta(
×
245
            (float)$expected,
×
246
            (float)$actual,
×
247
            $allowableDiff,
×
248
            'Diff: ' . ((float)$expected - (float)$actual) . "; Expected diff={$allowableDiff}; " . $message,
×
249
        );
×
250
    } elseif (\is_array($expected) && \is_array($actual)) {
×
251
        isAmountCur($expected, $actual, $message, $allowableDiff);
×
252
    } else {
253
        fail('$expected and $actual both must be "array" OR "float|string|int"');
×
254
    }
255
}
256

257
function isNotAmount(
258
    array|float|int|string $expected,
259
    array|float|int|string $actual,
260
    string $message = '',
261
    float $allowableDiff = 0.03,
262
): void {
263
    if (!\is_array($expected) && !\is_array($actual)) {
×
264
        Assert::assertNotEqualsWithDelta(
×
265
            (float)$expected,
×
266
            (float)$actual,
×
267
            $allowableDiff,
×
268
            'Diff: ' . ((float)$expected - (float)$actual) . "; Expected diff={$allowableDiff}; " . $message,
×
269
        );
×
270
    } elseif (\is_array($expected) && \is_array($actual)) {
×
271
        isNotAmountCur($expected, $actual, $message, $allowableDiff);
×
272
    } else {
273
        fail('$expected and $actual both must be "array" OR "float|string|int"');
×
274
    }
275
}
276

277
/**
278
 * @param array<float|int|string> $expected
279
 * @param array<float|int|string> $actual
280
 */
281
function isAmountCur(array $expected, array $actual, string $message = '', float $allowableDiff = 0.03): void
282
{
283
    $numberOfArgs = 2;
×
284

285
    isTrue(\count($expected) === $numberOfArgs, $message);
×
286
    isTrue(\count($actual) === $numberOfArgs, $message);
×
287

288
    $diff = (float)$expected[0] - (float)$actual[0];
×
289
    $message .= " Actual diff={$diff}; Expected diff={$allowableDiff}";
×
290

291
    isTrue(\is_string($expected[1]), $message);
×
292
    isTrue(\is_string($actual[1]), $message);
×
293
    isSame($expected[1], $actual[1], $message);
×
294
    isNotEmpty($expected[1], $message);
×
295
    isNotEmpty($actual[1], $message);
×
296

297
    Assert::assertEqualsWithDelta((float)$expected[0], (float)$actual[0], $allowableDiff, $message);
×
298
}
299

300
/**
301
 * @param array<float|int|string> $expected
302
 * @param array<float|int|string> $actual
303
 */
304
function isNotAmountCur(array $expected, array $actual, string $message = '', float $allowableDiff = 0.03): void
305
{
306
    $numberOfArgs = 2;
×
307

308
    isTrue(\count($expected) === $numberOfArgs, $message);
×
309
    isTrue(\count($actual) === $numberOfArgs, $message);
×
310

311
    $diff = (float)$expected[0] - (float)$actual[0];
×
312
    $message .= " Actual diff={$diff}; Expected diff={$allowableDiff}";
×
313

314
    isTrue(\is_string($expected[1]), $message);
×
315
    isTrue(\is_string($actual[1]), $message);
×
316
    isSame($expected[1], $actual[1], $message);
×
317
    isNotEmpty($expected[1], $message);
×
318
    isNotEmpty($actual[1], $message);
×
319

320
    Assert::assertNotEqualsWithDelta((float)$expected[0], (float)$actual[0], $allowableDiff, $message);
×
321
}
322

323
function isDiffBetweenDates(string $date1, string $date2, float $expectedDiff = 300.0, string $message = ''): void
324
{
325
    $dateObj1   = new \DateTime($date1);
×
326
    $dateObj2   = new \DateTime($date2);
×
327
    $actualDiff = \abs((float)($dateObj1->getTimestamp() - $dateObj2->getTimestamp()));
×
328

329
    isTrue(
×
330
        $actualDiff === $expectedDiff,
×
331
        \trim(
×
332
            "The expected difference between \"{$date1}\" and \"{$date2}\" is {$expectedDiff} seconds. "
×
333
            . "The actual value is {$actualDiff} seconds. {$message}",
×
334
        ),
×
335
    );
×
336
}
337

338
function isDiffBetweenDatesLessThan(
339
    string $date1,
340
    string $date2,
341
    int $expectedMaxDiff = 300,
342
    string $message = '',
343
): void {
344
    $dateObj1   = new \DateTime($date1);
×
345
    $dateObj2   = new \DateTime($date2);
×
346
    $actualDiff = \abs((float)($dateObj1->getTimestamp() - $dateObj2->getTimestamp()));
×
347
    isTrue(
×
348
        $actualDiff < $expectedMaxDiff,
×
349
        \trim(
×
350
            "Diff between dates: \"{$date1}\" and \"{$date2}\" is more than expected {$expectedMaxDiff} seconds. "
×
351
            . "The actual value is {$actualDiff} seconds. {$message}",
×
352
        ),
×
353
    );
×
354
}
355

356
function isDiffBetweenDatesMoreThan(
357
    string $date1,
358
    string $date2,
359
    int $expectedMinDiff = 300,
360
    string $message = '',
361
): void {
362
    $dateObj1   = new \DateTime($date1);
×
363
    $dateObj2   = new \DateTime($date2);
×
364
    $actualDiff = \abs((float)($dateObj1->getTimestamp() - $dateObj2->getTimestamp()));
×
365
    isTrue(
×
366
        $actualDiff > $expectedMinDiff,
×
367
        \trim(
×
368
            "Diff between dates: \"{$date1}\" and \"{$date2}\" is less than expected {$expectedMinDiff} seconds. "
×
369
            . "The actual value is {$actualDiff} seconds. {$message}",
×
370
        ),
×
371
    );
×
372
}
373

374
function isSameDate(string $expected, string $actual, string $format = 'Y-m-d', string $message = ''): void
375
{
376
    $expectedObj = new \DateTime($expected);
×
377
    $actualObj   = new \DateTime($actual);
×
378
    isSame($expectedObj->format($format), $actualObj->format($format), $message);
×
379
}
380

381
function isFileContains(string $expected, string $filepath, bool $ignoreCase = false, string $message = ''): void
382
{
383
    isFile($filepath);
×
384

385
    $errMessage = \implode("\n", [
×
386
        "The file doesn't contain expected text. " . $message,
×
387
        "See: {$filepath}",
×
388
        'Expected text:',
×
389
        \str_repeat('-', 80),
×
390
        $expected,
×
391
        \str_repeat('-', 80),
×
392
    ]);
×
393

394
    $fileContent = (string)\file_get_contents($filepath);
×
395

396
    if ($ignoreCase) {
×
397
        isTrue(\mb_stripos($fileContent, $expected) !== false, $errMessage);
×
398
    } else {
399
        isTrue(\str_contains($fileContent, $expected), $errMessage);
×
400
    }
401
}
402

403
function isFileNotContains(string $expected, string $filepath, bool $ignoreCase = false, string $message = ''): void
404
{
405
    isFile($filepath);
×
406

407
    $errMessage = \implode("\n", [
×
408
        "The file shouldn't contain expected text. " . $message,
×
409
        "See: {$filepath}",
×
410
        'Expected text:',
×
411
        \str_repeat('-', 80),
×
412
        $expected,
×
413
        \str_repeat('-', 80),
×
414
    ]);
×
415

416
    $fileContent = (string)\file_get_contents($filepath);
×
417

418
    if ($ignoreCase) {
×
419
        isTrue(\mb_stripos($fileContent, $expected) === false, $errMessage);
×
420
    } else {
421
        isTrue(!\str_contains($fileContent, $expected), $errMessage);
×
422
    }
423
}
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