ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
IncidentTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Exception;
24use PHPUnit\Framework\TestCase;
26
27class IncidentTest extends TestCase
28{
29 public function testConstruct(): void
30 {
31 $this->assertInstanceOf(Incident::class, new Incident());
32 }
33
34 public function testAny(): void
35 {
36 $this->assertTrue((new Incident())->any(static fn(int $x) => $x === 2, [1, 2, 3]));
37 }
38
39 public function testAnyBreaksAtFirstTrue(): void
40 {
41 $throw_error = false;
42
43 $this->assertTrue((new Incident())->any(static function (int $x) use (&$throw_error): bool {
44 if ($throw_error) {
45 throw new Exception('Should not be called anymore.');
46 }
47 return $x === 2 && ($throw_error = true);
48 }, [1, 2, 3]));
49 }
50
51 public function testAnyReturnsFalse(): void
52 {
53 $this->assertFalse((new Incident())->any(static fn(int $x) => false, [1, 2, 3]));
54 }
55}