ILIAS  release_7 Revision v7.30-3-g800a261c036
IncidentTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
25
26class 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 function (int $x) {return $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 function (int $x) {return false;}, [1, 2, 3]));
59 }
60}
An exception for terminatinating execution or to throw for unit testing.