ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
IncidentTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Modules\Test\test;
22 
25 
26 class IncidentTest extends TestCase
27 {
28  public function testConstruct(): void
29  {
30  $this->assertInstanceOf(Incident::class, new Incident());
31  }
32 
33  public function testAny(): void
34  {
35  $incident = new Incident();
36  $this->assertTrue($incident->any(static fn (int $x) => $x === 2, [1, 2, 3]));
37  }
38 
39  public function testAnyBreaksAtFirstTrue(): void
40  {
41  $incident = new Incident();
42  $throw_error = false;
43 
44  $this->assertTrue($incident->any(static function (int $x) use (&$throw_error): bool {
45  if ($throw_error) {
46  throw new Exception('Should not be called anymore.');
47  } elseif ($x === 2) {
48  $throw_error = true;
49  return true;
50  }
51  return false;
52  }, [1, 2, 3]));
53  }
54 
55  public function testAnyReturnsFalse(): void
56  {
57  $incident = new Incident();
58  $this->assertFalse($incident->any(static fn (int $x) => false, [1, 2, 3]));
59  }
60 }