ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
GreaterThanConstraintTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data\Factory as DataFactory;
26use PHPUnit\Framework\TestCase;
28
29class GreaterThanConstraintTest extends TestCase
30{
31 private DataFactory $df;
32 private Language $lng;
33 private int $greater_than;
34 private Constraint $c;
35
36 protected function setUp(): void
37 {
38 $this->df = new DataFactory();
39 $this->lng = $this->getMockBuilder(Language::class)
40 ->disableOriginalConstructor()
41 ->getMock();
42
43 $this->greater_than = 10;
44
45 $this->c = new GreaterThan(
46 $this->greater_than,
47 $this->df,
48 $this->lng
49 );
50 }
51
52 public function testAccepts(): void
53 {
54 $this->assertTrue($this->c->accepts(12));
55 }
56
57 public function testNotAccepts(): void
58 {
59 $this->assertFalse($this->c->accepts(2));
60 }
61
62 public function testCheckSucceed(): void
63 {
64 $this->c->check(12);
65 $this->assertTrue(true); // does not throw
66 }
67
68 public function testCheckFails(): void
69 {
70 $this->expectException(\UnexpectedValueException::class);
71 $this->c->check(2);
72 }
73
74 public function testNoProblemWith(): void
75 {
76 $this->assertNull($this->c->problemWith(12));
77 }
78
79 public function testProblemWith(): void
80 {
81 $this->lng
82 ->expects($this->once())
83 ->method("txt")
84 ->with("not_greater_than")
85 ->willReturn("-%s-%s-");
86
87 $this->assertEquals("-2-10-", $this->c->problemWith(2));
88 }
89
90 public function testRestrictOk(): void
91 {
92 $ok = $this->df->ok(12);
93
94 $res = $this->c->applyTo($ok);
95 $this->assertTrue($res->isOk());
96 }
97
98 public function testRestrictNotOk(): void
99 {
100 $not_ok = $this->df->ok(2);
101
102 $res = $this->c->applyTo($not_ok);
103 $this->assertFalse($res->isOk());
104 }
105
106 public function testRestrictError(): void
107 {
108 $error = $this->df->error("error");
109
110 $res = $this->c->applyTo($error);
111 $this->assertSame($error, $res);
112 }
113
114 public function testWithProblemBuilder(): void
115 {
116 $new_c = $this->c->withProblemBuilder(static function (): string {
117 return "This was a fault";
118 });
119 $this->assertEquals("This was a fault", $new_c->problemWith(2));
120 }
121}
Builds data types.
Definition: Factory.php:36
ilErrorHandling $error
Definition: class.ilias.php:69
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
$res
Definition: ltiservices.php:69