ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ParallelConstraintsTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4require_once("libs/composer/vendor/autoload.php");
5
7use ILIAS\Data;
8use PHPUnit\Framework\TestCase;
9
15class ParallelTest extends TestCase
16{
20 private $df;
21
25 private $lng;
26
30 private $refinery;
31
32 protected function setUp() : void
33 {
34 $this->df = new Data\Factory();
35 $this->lng = $this->createMock(\ilLanguage::class);
36 $this->refinery = new \ILIAS\Refinery\Factory($this->df, $this->lng);
37
38 $group = $this->refinery->custom();
39
40 $this->less_than_3 = $group->constraint(
41 function ($value) {
42 return $value < 3;
43 },
44 "not_less_than_3"
45 );
46
47 $this->less_than_5 = $group->constraint(
48 function ($value) {
49 return $value < 5;
50 },
51 "not_less_than_5"
52 );
53
54 $this->c = $this->refinery
55 ->logical()
56 ->parallel([$this->less_than_3, $this->less_than_5]);
57 }
58
59 public function testAccepts()
60 {
61 $this->assertTrue($this->c->accepts(2));
62 }
63
64 public function testNotAccepts()
65 {
66 $this->assertFalse($this->c->accepts(4));
67 }
68
69 public function testCheckSucceed()
70 {
71 $this->c->check(2);
72 $this->assertTrue(true); // does not throw
73 }
74
75 public function testCheckFails()
76 {
77 $this->expectException(\UnexpectedValueException::class);
78 $this->c->check(6);
79 }
80
81 public function testNoProblemWith()
82 {
83 $this->assertNull($this->c->problemWith(2));
84 }
85
86 public function testProblemWith1()
87 {
88 $this->lng
89 ->expects($this->never())
90 ->method("txt");
91
92 $this->assertEquals("not_less_than_3", $this->c->problemWith(4));
93 }
94
95 public function testProblemWith2()
96 {
97 $this->lng
98 ->expects($this->never())
99 ->method("txt");
100
101 $this->assertEquals("not_less_than_3 not_less_than_5", $this->c->problemWith(6));
102 }
103
104 public function testRestrictOk()
105 {
106 $ok = $this->df->ok(2);
107
108 $res = $this->c->applyTo($ok);
109 $this->assertTrue($res->isOk());
110 }
111
112 public function testRestrictNotOk()
113 {
114 $not_ok = $this->df->ok(7);
115
116 $res = $this->c->applyTo($not_ok);
117 $this->assertFalse($res->isOk());
118 }
119
120 public function testRestrictError()
121 {
122 $error = $this->df->error("error");
123
124 $res = $this->c->applyTo($error);
125 $this->assertSame($error, $res);
126 }
127
128 public function testWithProblemBuilder()
129 {
130 $new_c = $this->c->withProblemBuilder(function () {
131 return "This was a fault";
132 });
133 $this->assertEquals("This was a fault", $new_c->problemWith(7));
134 }
135}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
TestCase for the parellel constraint.
foreach($_POST as $key=> $value) $res