ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ParallelTest.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 */
4
6use ILIAS\Data;
7
14{
15 protected function setUp()
16 {
17 $this->f = new Validation\Factory(new Data\Factory());
18 }
19
20 protected function tearDown()
21 {
22 $this->f = null;
23 }
24
25 public function testAccept()
26 {
27 $constraint = $this->f->parallel(array($this->f->isInt(), $this->f->greaterThan(3), $this->f->lessThan(5)));
28
29 $this->assertTrue($constraint->accepts(4));
30 $this->assertFalse($constraint->accepts(2));
31 }
32
33 public function testCheck()
34 {
35 $constraint = $this->f->sequential(array($this->f->isInt(), $this->f->greaterThan(3), $this->f->lessThan(5)));
36 $raised = false;
37
38 try {
39 $constraint->check(4);
40 } catch (UnexpectedValueException $e) {
41 $raised = true;
42 }
43
44 $this->assertFalse($raised);
45
46 $constraint = $this->f->parallel(array($this->f->isInt(), $this->f->greaterThan(3), $this->f->lessThan(1)));
47 try {
48 $constraint->check(2);
49 $raised = false;
50 } catch (UnexpectedValueException $e) {
51 $this->assertEquals("'2' is not greater than '3'.'2' is greater than '1'.", $e->getMessage());
52 $raised = true;
53 }
54
55 $this->assertTrue($raised);
56 }
57
58 public function testProblemWith()
59 {
60 $constraint = $this->f->parallel(array($this->f->isInt(), $this->f->greaterThan(3), $this->f->lessThan(5)));
61
62 $this->assertNull($constraint->problemWith(4));
63
64 $constraint = $this->f->parallel(array($this->f->isInt(), $this->f->greaterThan(3), $this->f->lessThan(1)));
65 $this->assertInternalType("string", $constraint->problemWith(2));
66 $this->assertEquals("'2' is not greater than '3'.'2' is greater than '1'.", $constraint->problemWith(2));
67 }
68
69 public function testRestrict()
70 {
71 $constraint = $this->f->parallel(array($this->f->isInt(), $this->f->greaterThan(3), $this->f->lessThan(5)));
72
73 $rf = new Data\Factory();
74 $ok = $rf->ok(4);
75 $ok2 = $rf->ok(2);
76 $error = $rf->error("text");
77
78 $result = $constraint->restrict($ok);
79 $this->assertTrue($result->isOk());
80
81 $result = $constraint->restrict($ok2);
82 $this->assertTrue($result->isError());
83
84 $result = $constraint->restrict($error);
85 $this->assertSame($error, $result);
86 }
87
88 public function testWithProblemBuilder()
89 {
90 $constraint = $this->f->parallel(array($this->f->isInt(), $this->f->greaterThan(3), $this->f->lessThan(1)));
91
92 $new_constraint = $constraint->withProblemBuilder(function () {
93 return "This was a vault";
94 });
95 $this->assertEquals("This was a vault", $new_constraint->problemWith(2));
96 }
97
99 {
100 $constraint = $this->f->parallel(array($this->f->isInt(), $this->f->greaterThan(3), $this->f->lessThan(2)));
101 $constraint->accepts(1);
102 $constraint->accepts(3);
103 $constraint->accepts(4);
104
105 $this->assertEquals("'1' is not greater than '3'.", $constraint->problemWith(1));
106 $this->assertEquals("'3' is not greater than '3'.'3' is greater than '2'.", $constraint->problemWith(3));
107 $this->assertEquals("'4' is greater than '2'.", $constraint->problemWith(4));
108 }
109}
$result
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:15
TestCase for the factory of constraints.
testCorrectErrorMessagesAfterMultiAccept()
testWithProblemBuilder()
$error
Definition: Error.php:17