ILIAS  release_7 Revision v7.30-3-g800a261c036
LessThanConstraintTest.php
Go to the documentation of this file.
1<?php
2
4
5/* Copyright (c) 2018 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
6require_once("libs/composer/vendor/autoload.php");
7
9use ILIAS\Data;
10use PHPUnit\Framework\TestCase;
11
12class LessThanConstraintTest extends TestCase
13{
14
18 private $c;
19
23 private $lng;
24
28 private $df;
29
33 private $less_than;
34
35 public function setUp() : void
36 {
37 $this->df = new Data\Factory();
38 $this->lng = $this->getMockBuilder(\ilLanguage::class)
39 ->disableOriginalConstructor()
40 ->getMock();
41
42 $this->less_than = 10;
43
44 $this->c = new \ILIAS\Refinery\Integer\LessThan(
45 $this->less_than,
46 $this->df,
47 $this->lng
48 );
49 }
50
51 public function testAccepts()
52 {
53 $this->assertTrue($this->c->accepts(2));
54 }
55
56 public function testNotAccepts()
57 {
58 $this->assertFalse($this->c->accepts(10));
59 }
60
61 public function testCheckSucceed()
62 {
63 $this->c->check(2);
64 $this->assertTrue(true); // does not throw
65 }
66
67 public function testCheckFails()
68 {
69 $this->expectException(\UnexpectedValueException::class);
70 $this->c->check(11);
71 }
72
73 public function testNoProblemWith()
74 {
75 $this->assertNull($this->c->problemWith(1));
76 }
77
78 public function testProblemWith()
79 {
80 $this->lng
81 ->expects($this->once())
82 ->method("txt")
83 ->with("not_less_than")
84 ->willReturn("-%s-%s-");
85
86 $this->assertEquals("-12-{$this->less_than}-", $this->c->problemWith("12"));
87 }
88
89 public function testRestrictOk()
90 {
91 $ok = $this->df->ok(1);
92
93 $res = $this->c->applyTo($ok);
94 $this->assertTrue($res->isOk());
95 }
96
97 public function testRestrictNotOk()
98 {
99 $not_ok = $this->df->ok(1234);
100
101 $res = $this->c->applyTo($not_ok);
102 $this->assertFalse($res->isOk());
103 }
104
105 public function testRestrictError()
106 {
107 $error = $this->df->error("error");
108
109 $res = $this->c->applyTo($error);
110 $this->assertSame($error, $res);
111 }
112
113 public function testWithProblemBuilder()
114 {
115 $new_c = $this->c->withProblemBuilder(function () {
116 return "This was a fault";
117 });
118 $this->assertEquals("This was a fault", $new_c->problemWith(13));
119 }
120}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
foreach($_POST as $key=> $value) $res