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

NexusPHP / assert / 25651449791

11 May 2026 05:06AM UTC coverage: 90.097% (-9.9%) from 100.0%
25651449791

push

github

paulbalandan
Add key-iterating and value-iterating expectations

646 of 839 new or added lines in 3 files covered. (77.0%)

1756 of 1949 relevant lines covered (90.1%)

5.26 hits per line

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

55.53
/src/KeysIteratingExpectation.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of the Nexus Assert library.
7
 *
8
 * (c) 2025 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Nexus\Assert;
15

16
/**
17
 * An expectation that iterates over the keys of an iterable value.
18
 *
19
 * @template TValue
20
 *
21
 * @implements Expectable<TValue>
22
 *
23
 * @auto-generated
24
 */
25
final readonly class KeysIteratingExpectation implements Expectable
26
{
27
    private const MESSAGE_CONTAINS = 'Key "{value}" in iterable is expected to contain "{needle}".';
28
    private const MESSAGE_ENDS_WITH = 'Key "{value}" in iterable is expected to end with "{needle}".';
29
    private const MESSAGE_HAS_METHOD = 'Object key of class "{value}" in iterable is expected to have method "{method}".';
30
    private const MESSAGE_HAS_OFFSET = 'Array key "{value}" in iterable is expected to have offset "{key}".';
31
    private const MESSAGE_HAS_PROPERTY = 'Object key of class "{value}" in iterable is expected to have property "{property}".';
32
    private const MESSAGE_IS_ARRAY = 'Key "{value}" in iterable is expected to be an array but got {type} instead.';
33
    private const MESSAGE_IS_ARRAY_KEY = 'Key "{value}" in iterable is expected to be an array key but got {type} instead.';
34
    private const MESSAGE_IS_BOOL = 'Key "{value}" in iterable is expected to be a bool but got {type} instead.';
35
    private const MESSAGE_IS_CALLABLE = 'Key "{value}" in iterable is expected to be callable but got {type} instead.';
36
    private const MESSAGE_IS_COUNTABLE = 'Key "{value}" in iterable is expected to be countable but got {type} instead.';
37
    private const MESSAGE_IS_FALSE = 'Key "{value}" in iterable is expected to be false but got {type} instead.';
38
    private const MESSAGE_IS_FLOAT = 'Key "{value}" in iterable is expected to be a float but got {type} instead.';
39
    private const MESSAGE_IS_IDENTICAL = 'Key "{value}" in iterable is expected to be identical to "{other}".';
40
    private const MESSAGE_IS_INSTANCE_OF = 'Key "{value}" in iterable is expected to be an instance of {class} but got {type} instead.';
41
    private const MESSAGE_IS_INT = 'Key "{value}" in iterable is expected to be an int but got {type} instead.';
42
    private const MESSAGE_IS_ITERABLE = 'Key "{value}" in iterable is expected to be iterable but got {type} instead.';
43
    private const MESSAGE_IS_LIST = 'Key "{value}" in iterable is expected to be a list but got {type} instead.';
44
    private const MESSAGE_IS_LOWERCASE_STRING = 'Key "{value}" in iterable is expected to be a lowercase string but got {type} instead.';
45
    private const MESSAGE_IS_MAP = 'Key "{value}" in iterable is expected to be a map but got {type} instead.';
46
    private const MESSAGE_IS_NATURAL_INT = 'Key "{value}" in iterable is expected to be a natural int but got {type} instead.';
47
    private const MESSAGE_IS_NEGATIVE_INT = 'Key "{value}" in iterable is expected to be a negative int but got {type} instead.';
48
    private const MESSAGE_IS_NON_EMPTY_STRING = 'Key "{value}" in iterable is expected to be a non-empty string but got {type} instead.';
49
    private const MESSAGE_IS_NULL = 'Key "{value}" in iterable is expected to be null but got {type} instead.';
50
    private const MESSAGE_IS_NUMERIC = 'Key "{value}" in iterable is expected to be numeric but got {type} instead.';
51
    private const MESSAGE_IS_OBJECT = 'Key "{value}" in iterable is expected to be an object but got {type} instead.';
52
    private const MESSAGE_IS_POSITIVE_INT = 'Key "{value}" in iterable is expected to be a positive int but got {type} instead.';
53
    private const MESSAGE_IS_RESOURCE = 'Key "{value}" in iterable is expected to be a resource but got {type} instead.';
54
    private const MESSAGE_IS_SCALAR = 'Key "{value}" in iterable is expected to be a scalar but got {type} instead.';
55
    private const MESSAGE_IS_STRING = 'Key "{value}" in iterable is expected to be a string but got {type} instead.';
56
    private const MESSAGE_IS_TRUE = 'Key "{value}" in iterable is expected to be true but got {type} instead.';
57
    private const MESSAGE_IS_UPPERCASE_STRING = 'Key "{value}" in iterable is expected to be an uppercase string but got {type} instead.';
58
    private const MESSAGE_MATCHES_REGULAR_EXPRESSION = 'Key "{value}" in iterable is expected to match the PCRE pattern \'{pattern}\'.';
59
    private const MESSAGE_STARTS_WITH = 'Key "{value}" in iterable is expected to start with "{needle}".';
60

61
    /**
62
     * @var iterable<mixed>
63
     */
64
    public iterable $value;
65

66
    private bool $isArray;
67

68
    /**
69
     * @param Expectation<TValue> $expectation
70
     */
71
    public function __construct(public Expectation $expectation)
136✔
72
    {
73
        Assert::that($this->expectation->value)->isIterable();
136✔
74

75
        $this->isArray = \is_array($this->expectation->value);
132✔
76
        $this->value = $this->expectation->value;
132✔
77
    }
78

79
    /**
80
     * @return self<TValue>
81
     */
82
    public function contains(string $needle, ?string $message = null): self
4✔
83
    {
84
        foreach ($this->value as $offsetKey => $_) {
4✔
85
            try {
86
                Assert::that($offsetKey)->contains($needle, $message);
4✔
87
            } catch (ExpectationFailedException) {
4✔
88
                throw new ExpectationFailedException(
4✔
89
                    $message ?? self::MESSAGE_CONTAINS,
4✔
90
                    [
4✔
91
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
92
                        'needle' => $this->expectation->exporter->exportValue($needle),
4✔
93
                    ],
4✔
94
                );
4✔
95
            }
96
        }
97

98
        return $this;
4✔
99
    }
100

101
    /**
102
     * @return self<TValue>
103
     */
104
    public function endsWith(string $needle, ?string $message = null): self
4✔
105
    {
106
        foreach ($this->value as $offsetKey => $_) {
4✔
107
            try {
108
                Assert::that($offsetKey)->endsWith($needle, $message);
4✔
109
            } catch (ExpectationFailedException) {
4✔
110
                throw new ExpectationFailedException(
4✔
111
                    $message ?? self::MESSAGE_ENDS_WITH,
4✔
112
                    [
4✔
113
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
114
                        'needle' => $this->expectation->exporter->exportValue($needle),
4✔
115
                    ],
4✔
116
                );
4✔
117
            }
118
        }
119

120
        return $this;
4✔
121
    }
122

123
    /**
124
     * @return self<TValue>
125
     */
126
    public function hasMethod(string $method, ?string $message = null): self
4✔
127
    {
128
        if ($this->isArray) {
4✔
129
            throw new \LogicException('Method hasMethod() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
130
        }
131

NEW
132
        foreach ($this->value as $offsetKey => $_) {
×
133
            try {
NEW
134
                Assert::that($offsetKey)->hasMethod($method, $message);
×
NEW
135
            } catch (ExpectationFailedException) {
×
NEW
136
                throw new ExpectationFailedException(
×
NEW
137
                    $message ?? self::MESSAGE_HAS_METHOD,
×
NEW
138
                    [
×
NEW
139
                        'value' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
140
                        'method' => $method,
×
NEW
141
                    ],
×
NEW
142
                );
×
143
            }
144
        }
145

NEW
146
        return $this;
×
147
    }
148

149
    /**
150
     * @return self<TValue>
151
     */
152
    public function hasOffset(int|string $key, ?string $message = null): self
4✔
153
    {
154
        if ($this->isArray) {
4✔
155
            throw new \LogicException('Method hasOffset() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
156
        }
157

NEW
158
        foreach ($this->value as $offsetKey => $_) {
×
159
            try {
NEW
160
                Assert::that($offsetKey)->hasOffset($key, $message);
×
NEW
161
            } catch (ExpectationFailedException) {
×
NEW
162
                throw new ExpectationFailedException(
×
NEW
163
                    $message ?? self::MESSAGE_HAS_OFFSET,
×
NEW
164
                    [
×
NEW
165
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
166
                        'key' => $key,
×
NEW
167
                    ],
×
NEW
168
                );
×
169
            }
170
        }
171

NEW
172
        return $this;
×
173
    }
174

175
    /**
176
     * @return self<TValue>
177
     */
178
    public function hasProperty(string $property, ?string $message = null): self
4✔
179
    {
180
        if ($this->isArray) {
4✔
181
            throw new \LogicException('Method hasProperty() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
182
        }
183

NEW
184
        foreach ($this->value as $offsetKey => $_) {
×
185
            try {
NEW
186
                Assert::that($offsetKey)->hasProperty($property, $message);
×
NEW
187
            } catch (ExpectationFailedException) {
×
NEW
188
                throw new ExpectationFailedException(
×
NEW
189
                    $message ?? self::MESSAGE_HAS_PROPERTY,
×
NEW
190
                    [
×
NEW
191
                        'value' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
192
                        'property' => $property,
×
NEW
193
                    ],
×
NEW
194
                );
×
195
            }
196
        }
197

NEW
198
        return $this;
×
199
    }
200

201
    /**
202
     * @return self<TValue>
203
     */
204
    public function isArray(?string $message = null): self
4✔
205
    {
206
        if ($this->isArray) {
4✔
207
            throw new \LogicException('Method isArray() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
208
        }
209

NEW
210
        foreach ($this->value as $offsetKey => $_) {
×
211
            try {
NEW
212
                Assert::that($offsetKey)->isArray($message);
×
NEW
213
            } catch (ExpectationFailedException) {
×
NEW
214
                throw new ExpectationFailedException(
×
NEW
215
                    $message ?? self::MESSAGE_IS_ARRAY,
×
NEW
216
                    [
×
NEW
217
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
218
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
219
                    ],
×
NEW
220
                );
×
221
            }
222
        }
223

NEW
224
        return $this;
×
225
    }
226

227
    /**
228
     * @return self<TValue>
229
     */
230
    public function isArrayKey(?string $message = null): self
4✔
231
    {
232
        foreach ($this->value as $offsetKey => $_) {
4✔
233
            try {
234
                Assert::that($offsetKey)->isArrayKey($message);
4✔
NEW
235
            } catch (ExpectationFailedException) {
×
NEW
236
                throw new ExpectationFailedException(
×
NEW
237
                    $message ?? self::MESSAGE_IS_ARRAY_KEY,
×
NEW
238
                    [
×
NEW
239
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
240
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
241
                    ],
×
NEW
242
                );
×
243
            }
244
        }
245

246
        return $this;
4✔
247
    }
248

249
    /**
250
     * @return self<TValue>
251
     */
252
    public function isBool(?string $message = null): self
4✔
253
    {
254
        if ($this->isArray) {
4✔
255
            throw new \LogicException('Method isBool() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
256
        }
257

NEW
258
        foreach ($this->value as $offsetKey => $_) {
×
259
            try {
NEW
260
                Assert::that($offsetKey)->isBool($message);
×
NEW
261
            } catch (ExpectationFailedException) {
×
NEW
262
                throw new ExpectationFailedException(
×
NEW
263
                    $message ?? self::MESSAGE_IS_BOOL,
×
NEW
264
                    [
×
NEW
265
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
266
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
267
                    ],
×
NEW
268
                );
×
269
            }
270
        }
271

NEW
272
        return $this;
×
273
    }
274

275
    /**
276
     * @return self<TValue>
277
     */
278
    public function isCallable(?string $message = null): self
4✔
279
    {
280
        foreach ($this->value as $offsetKey => $_) {
4✔
281
            try {
282
                Assert::that($offsetKey)->isCallable($message);
4✔
283
            } catch (ExpectationFailedException) {
4✔
284
                throw new ExpectationFailedException(
4✔
285
                    $message ?? self::MESSAGE_IS_CALLABLE,
4✔
286
                    [
4✔
287
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
288
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
289
                    ],
4✔
290
                );
4✔
291
            }
292
        }
293

294
        return $this;
4✔
295
    }
296

297
    /**
298
     * @return self<TValue>
299
     */
300
    public function isCountable(?string $message = null): self
4✔
301
    {
302
        if ($this->isArray) {
4✔
303
            throw new \LogicException('Method isCountable() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
304
        }
305

NEW
306
        foreach ($this->value as $offsetKey => $_) {
×
307
            try {
NEW
308
                Assert::that($offsetKey)->isCountable($message);
×
NEW
309
            } catch (ExpectationFailedException) {
×
NEW
310
                throw new ExpectationFailedException(
×
NEW
311
                    $message ?? self::MESSAGE_IS_COUNTABLE,
×
NEW
312
                    [
×
NEW
313
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
314
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
315
                    ],
×
NEW
316
                );
×
317
            }
318
        }
319

NEW
320
        return $this;
×
321
    }
322

323
    /**
324
     * @return self<TValue>
325
     */
326
    public function isFalse(?string $message = null): self
4✔
327
    {
328
        if ($this->isArray) {
4✔
329
            throw new \LogicException('Method isFalse() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
330
        }
331

NEW
332
        foreach ($this->value as $offsetKey => $_) {
×
333
            try {
NEW
334
                Assert::that($offsetKey)->isFalse($message);
×
NEW
335
            } catch (ExpectationFailedException) {
×
NEW
336
                throw new ExpectationFailedException(
×
NEW
337
                    $message ?? self::MESSAGE_IS_FALSE,
×
NEW
338
                    [
×
NEW
339
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
340
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
341
                    ],
×
NEW
342
                );
×
343
            }
344
        }
345

NEW
346
        return $this;
×
347
    }
348

349
    /**
350
     * @return self<TValue>
351
     */
352
    public function isFloat(?string $message = null): self
4✔
353
    {
354
        if ($this->isArray) {
4✔
355
            throw new \LogicException('Method isFloat() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
356
        }
357

NEW
358
        foreach ($this->value as $offsetKey => $_) {
×
359
            try {
NEW
360
                Assert::that($offsetKey)->isFloat($message);
×
NEW
361
            } catch (ExpectationFailedException) {
×
NEW
362
                throw new ExpectationFailedException(
×
NEW
363
                    $message ?? self::MESSAGE_IS_FLOAT,
×
NEW
364
                    [
×
NEW
365
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
366
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
367
                    ],
×
NEW
368
                );
×
369
            }
370
        }
371

NEW
372
        return $this;
×
373
    }
374

375
    /**
376
     * @return self<TValue>
377
     */
378
    public function isIdentical(mixed $other, ?string $message = null): self
4✔
379
    {
380
        foreach ($this->value as $offsetKey => $_) {
4✔
381
            try {
382
                Assert::that($offsetKey)->isIdentical($other, $message);
4✔
383
            } catch (ExpectationFailedException) {
4✔
384
                throw new ExpectationFailedException(
4✔
385
                    $message ?? self::MESSAGE_IS_IDENTICAL,
4✔
386
                    [
4✔
387
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
388
                        'other' => $this->expectation->exporter->exportValue($other),
4✔
389
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
390
                    ],
4✔
391
                );
4✔
392
            }
393
        }
394

395
        return $this;
4✔
396
    }
397

398
    /**
399
     * @return self<TValue>
400
     */
401
    public function isInstanceOf(object|string $class, ?string $message = null): self
4✔
402
    {
403
        if ($this->isArray) {
4✔
404
            throw new \LogicException('Method isInstanceOf() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
405
        }
406

NEW
407
        foreach ($this->value as $offsetKey => $_) {
×
408
            try {
NEW
409
                Assert::that($offsetKey)->isInstanceOf($class, $message);
×
NEW
410
            } catch (ExpectationFailedException) {
×
NEW
411
                throw new ExpectationFailedException(
×
NEW
412
                    $message ?? self::MESSAGE_IS_INSTANCE_OF,
×
NEW
413
                    [
×
NEW
414
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
415
                        'class' => $this->expectation->exporter->exportValue($class),
×
NEW
416
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
417
                    ],
×
NEW
418
                );
×
419
            }
420
        }
421

NEW
422
        return $this;
×
423
    }
424

425
    /**
426
     * @return self<TValue>
427
     */
428
    public function isInt(?string $message = null): self
4✔
429
    {
430
        foreach ($this->value as $offsetKey => $_) {
4✔
431
            try {
432
                Assert::that($offsetKey)->isInt($message);
4✔
433
            } catch (ExpectationFailedException) {
4✔
434
                throw new ExpectationFailedException(
4✔
435
                    $message ?? self::MESSAGE_IS_INT,
4✔
436
                    [
4✔
437
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
438
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
439
                    ],
4✔
440
                );
4✔
441
            }
442
        }
443

444
        return $this;
4✔
445
    }
446

447
    /**
448
     * @return self<TValue>
449
     */
450
    public function isIterable(?string $message = null): self
4✔
451
    {
452
        if ($this->isArray) {
4✔
453
            throw new \LogicException('Method isIterable() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
454
        }
455

NEW
456
        foreach ($this->value as $offsetKey => $_) {
×
457
            try {
NEW
458
                Assert::that($offsetKey)->isIterable($message);
×
NEW
459
            } catch (ExpectationFailedException) {
×
NEW
460
                throw new ExpectationFailedException(
×
NEW
461
                    $message ?? self::MESSAGE_IS_ITERABLE,
×
NEW
462
                    [
×
NEW
463
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
464
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
465
                    ],
×
NEW
466
                );
×
467
            }
468
        }
469

NEW
470
        return $this;
×
471
    }
472

473
    /**
474
     * @return self<TValue>
475
     */
476
    public function isList(?string $message = null): self
4✔
477
    {
478
        if ($this->isArray) {
4✔
479
            throw new \LogicException('Method isList() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
480
        }
481

NEW
482
        foreach ($this->value as $offsetKey => $_) {
×
483
            try {
NEW
484
                Assert::that($offsetKey)->isList($message);
×
NEW
485
            } catch (ExpectationFailedException) {
×
NEW
486
                throw new ExpectationFailedException(
×
NEW
487
                    $message ?? self::MESSAGE_IS_LIST,
×
NEW
488
                    [
×
NEW
489
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
490
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
491
                    ],
×
NEW
492
                );
×
493
            }
494
        }
495

NEW
496
        return $this;
×
497
    }
498

499
    /**
500
     * @return self<TValue>
501
     */
502
    public function isLowercaseString(?string $message = null): self
4✔
503
    {
504
        foreach ($this->value as $offsetKey => $_) {
4✔
505
            try {
506
                Assert::that($offsetKey)->isLowercaseString($message);
4✔
507
            } catch (ExpectationFailedException) {
4✔
508
                throw new ExpectationFailedException(
4✔
509
                    $message ?? self::MESSAGE_IS_LOWERCASE_STRING,
4✔
510
                    [
4✔
511
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
512
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
513
                    ],
4✔
514
                );
4✔
515
            }
516
        }
517

518
        return $this;
4✔
519
    }
520

521
    /**
522
     * @return self<TValue>
523
     */
524
    public function isMap(?string $message = null): self
4✔
525
    {
526
        if ($this->isArray) {
4✔
527
            throw new \LogicException('Method isMap() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
528
        }
529

NEW
530
        foreach ($this->value as $offsetKey => $_) {
×
531
            try {
NEW
532
                Assert::that($offsetKey)->isMap($message);
×
NEW
533
            } catch (ExpectationFailedException) {
×
NEW
534
                throw new ExpectationFailedException(
×
NEW
535
                    $message ?? self::MESSAGE_IS_MAP,
×
NEW
536
                    [
×
NEW
537
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
538
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
539
                    ],
×
NEW
540
                );
×
541
            }
542
        }
543

NEW
544
        return $this;
×
545
    }
546

547
    /**
548
     * @return self<TValue>
549
     */
550
    public function isNaturalInt(?string $message = null): self
4✔
551
    {
552
        foreach ($this->value as $offsetKey => $_) {
4✔
553
            try {
554
                Assert::that($offsetKey)->isNaturalInt($message);
4✔
555
            } catch (ExpectationFailedException) {
4✔
556
                throw new ExpectationFailedException(
4✔
557
                    $message ?? self::MESSAGE_IS_NATURAL_INT,
4✔
558
                    [
4✔
559
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
560
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
561
                    ],
4✔
562
                );
4✔
563
            }
564
        }
565

566
        return $this;
4✔
567
    }
568

569
    /**
570
     * @return self<TValue>
571
     */
572
    public function isNegativeInt(?string $message = null): self
4✔
573
    {
574
        foreach ($this->value as $offsetKey => $_) {
4✔
575
            try {
576
                Assert::that($offsetKey)->isNegativeInt($message);
4✔
577
            } catch (ExpectationFailedException) {
4✔
578
                throw new ExpectationFailedException(
4✔
579
                    $message ?? self::MESSAGE_IS_NEGATIVE_INT,
4✔
580
                    [
4✔
581
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
582
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
583
                    ],
4✔
584
                );
4✔
585
            }
586
        }
587

588
        return $this;
4✔
589
    }
590

591
    /**
592
     * @return self<TValue>
593
     */
594
    public function isNonEmptyString(?string $message = null): self
4✔
595
    {
596
        foreach ($this->value as $offsetKey => $_) {
4✔
597
            try {
598
                Assert::that($offsetKey)->isNonEmptyString($message);
4✔
599
            } catch (ExpectationFailedException) {
4✔
600
                throw new ExpectationFailedException(
4✔
601
                    $message ?? self::MESSAGE_IS_NON_EMPTY_STRING,
4✔
602
                    [
4✔
603
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
604
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
605
                    ],
4✔
606
                );
4✔
607
            }
608
        }
609

610
        return $this;
4✔
611
    }
612

613
    /**
614
     * @return self<TValue>
615
     */
616
    public function isNull(?string $message = null): self
4✔
617
    {
618
        if ($this->isArray) {
4✔
619
            throw new \LogicException('Method isNull() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
620
        }
621

NEW
622
        foreach ($this->value as $offsetKey => $_) {
×
623
            try {
NEW
624
                Assert::that($offsetKey)->isNull($message);
×
NEW
625
            } catch (ExpectationFailedException) {
×
NEW
626
                throw new ExpectationFailedException(
×
NEW
627
                    $message ?? self::MESSAGE_IS_NULL,
×
NEW
628
                    [
×
NEW
629
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
630
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
631
                    ],
×
NEW
632
                );
×
633
            }
634
        }
635

NEW
636
        return $this;
×
637
    }
638

639
    /**
640
     * @return self<TValue>
641
     */
642
    public function isNumeric(?string $message = null): self
4✔
643
    {
644
        foreach ($this->value as $offsetKey => $_) {
4✔
645
            try {
646
                Assert::that($offsetKey)->isNumeric($message);
4✔
647
            } catch (ExpectationFailedException) {
4✔
648
                throw new ExpectationFailedException(
4✔
649
                    $message ?? self::MESSAGE_IS_NUMERIC,
4✔
650
                    [
4✔
651
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
652
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
653
                    ],
4✔
654
                );
4✔
655
            }
656
        }
657

658
        return $this;
4✔
659
    }
660

661
    /**
662
     * @return self<TValue>
663
     */
664
    public function isObject(?string $message = null): self
4✔
665
    {
666
        if ($this->isArray) {
4✔
667
            throw new \LogicException('Method isObject() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
668
        }
669

NEW
670
        foreach ($this->value as $offsetKey => $_) {
×
671
            try {
NEW
672
                Assert::that($offsetKey)->isObject($message);
×
NEW
673
            } catch (ExpectationFailedException) {
×
NEW
674
                throw new ExpectationFailedException(
×
NEW
675
                    $message ?? self::MESSAGE_IS_OBJECT,
×
NEW
676
                    [
×
NEW
677
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
678
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
679
                    ],
×
NEW
680
                );
×
681
            }
682
        }
683

NEW
684
        return $this;
×
685
    }
686

687
    /**
688
     * @return self<TValue>
689
     */
690
    public function isPositiveInt(?string $message = null): self
4✔
691
    {
692
        foreach ($this->value as $offsetKey => $_) {
4✔
693
            try {
694
                Assert::that($offsetKey)->isPositiveInt($message);
4✔
695
            } catch (ExpectationFailedException) {
4✔
696
                throw new ExpectationFailedException(
4✔
697
                    $message ?? self::MESSAGE_IS_POSITIVE_INT,
4✔
698
                    [
4✔
699
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
700
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
701
                    ],
4✔
702
                );
4✔
703
            }
704
        }
705

706
        return $this;
4✔
707
    }
708

709
    /**
710
     * @return self<TValue>
711
     */
712
    public function isResource(?string $message = null): self
4✔
713
    {
714
        if ($this->isArray) {
4✔
715
            throw new \LogicException('Method isResource() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
716
        }
717

NEW
718
        foreach ($this->value as $offsetKey => $_) {
×
719
            try {
NEW
720
                Assert::that($offsetKey)->isResource($message);
×
NEW
721
            } catch (ExpectationFailedException) {
×
NEW
722
                throw new ExpectationFailedException(
×
NEW
723
                    $message ?? self::MESSAGE_IS_RESOURCE,
×
NEW
724
                    [
×
NEW
725
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
726
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
727
                    ],
×
NEW
728
                );
×
729
            }
730
        }
731

NEW
732
        return $this;
×
733
    }
734

735
    /**
736
     * @return self<TValue>
737
     */
738
    public function isScalar(?string $message = null): self
4✔
739
    {
740
        foreach ($this->value as $offsetKey => $_) {
4✔
741
            try {
742
                Assert::that($offsetKey)->isScalar($message);
4✔
NEW
743
            } catch (ExpectationFailedException) {
×
NEW
744
                throw new ExpectationFailedException(
×
NEW
745
                    $message ?? self::MESSAGE_IS_SCALAR,
×
NEW
746
                    [
×
NEW
747
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
748
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
749
                    ],
×
NEW
750
                );
×
751
            }
752
        }
753

754
        return $this;
4✔
755
    }
756

757
    /**
758
     * @return self<TValue>
759
     */
760
    public function isString(?string $message = null): self
4✔
761
    {
762
        foreach ($this->value as $offsetKey => $_) {
4✔
763
            try {
764
                Assert::that($offsetKey)->isString($message);
4✔
765
            } catch (ExpectationFailedException) {
4✔
766
                throw new ExpectationFailedException(
4✔
767
                    $message ?? self::MESSAGE_IS_STRING,
4✔
768
                    [
4✔
769
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
770
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
771
                    ],
4✔
772
                );
4✔
773
            }
774
        }
775

776
        return $this;
4✔
777
    }
778

779
    /**
780
     * @return self<TValue>
781
     */
782
    public function isTrue(?string $message = null): self
4✔
783
    {
784
        if ($this->isArray) {
4✔
785
            throw new \LogicException('Method isTrue() cannot be called on keys of an array; array keys are constrained to int|string.');
4✔
786
        }
787

NEW
788
        foreach ($this->value as $offsetKey => $_) {
×
789
            try {
NEW
790
                Assert::that($offsetKey)->isTrue($message);
×
NEW
791
            } catch (ExpectationFailedException) {
×
NEW
792
                throw new ExpectationFailedException(
×
NEW
793
                    $message ?? self::MESSAGE_IS_TRUE,
×
NEW
794
                    [
×
NEW
795
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
×
NEW
796
                        'type' => $this->expectation->exporter->exportType($offsetKey),
×
NEW
797
                    ],
×
NEW
798
                );
×
799
            }
800
        }
801

NEW
802
        return $this;
×
803
    }
804

805
    /**
806
     * @return self<TValue>
807
     */
808
    public function isUppercaseString(?string $message = null): self
4✔
809
    {
810
        foreach ($this->value as $offsetKey => $_) {
4✔
811
            try {
812
                Assert::that($offsetKey)->isUppercaseString($message);
4✔
813
            } catch (ExpectationFailedException) {
4✔
814
                throw new ExpectationFailedException(
4✔
815
                    $message ?? self::MESSAGE_IS_UPPERCASE_STRING,
4✔
816
                    [
4✔
817
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
818
                        'type' => $this->expectation->exporter->exportType($offsetKey),
4✔
819
                    ],
4✔
820
                );
4✔
821
            }
822
        }
823

824
        return $this;
4✔
825
    }
826

827
    /**
828
     * @return self<TValue>
829
     */
830
    public function matchesRegularExpression(string $pattern, ?string $message = null): self
4✔
831
    {
832
        foreach ($this->value as $offsetKey => $_) {
4✔
833
            try {
834
                Assert::that($offsetKey)->matchesRegularExpression($pattern, $message);
4✔
835
            } catch (ExpectationFailedException) {
4✔
836
                throw new ExpectationFailedException(
4✔
837
                    $message ?? self::MESSAGE_MATCHES_REGULAR_EXPRESSION,
4✔
838
                    [
4✔
839
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
840
                        'pattern' => $pattern,
4✔
841
                    ],
4✔
842
                );
4✔
843
            }
844
        }
845

846
        return $this;
4✔
847
    }
848

849
    /**
850
     * @return self<TValue>
851
     */
852
    public function startsWith(string $needle, ?string $message = null): self
4✔
853
    {
854
        foreach ($this->value as $offsetKey => $_) {
4✔
855
            try {
856
                Assert::that($offsetKey)->startsWith($needle, $message);
4✔
857
            } catch (ExpectationFailedException) {
4✔
858
                throw new ExpectationFailedException(
4✔
859
                    $message ?? self::MESSAGE_STARTS_WITH,
4✔
860
                    [
4✔
861
                        'value' => $this->expectation->exporter->exportValue($offsetKey),
4✔
862
                        'needle' => $this->expectation->exporter->exportValue($needle),
4✔
863
                    ],
4✔
864
                );
4✔
865
            }
866
        }
867

868
        return $this;
4✔
869
    }
870
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc