ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
IntConstraintsTest.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{
18 public function testAccept($constraint, $ok_value, $error_value)
19 {
20 $this->assertTrue($constraint->accepts($ok_value));
21 $this->assertFalse($constraint->accepts($error_value));
22 }
23
27 public function testCheck($constraint, $ok_value, $error_value)
28 {
29 $raised = false;
30 try {
31 $constraint->check($ok_value);
32 } catch (UnexpectedValueException $e) {
33 $raised = true;
34 }
35
36 $this->assertFalse($raised);
37
38 try {
39 $constraint->check($error_value);
40 } catch (UnexpectedValueException $e) {
41 $raised = true;
42 }
43
44 $this->assertTrue($raised);
45 }
46
50 public function testProblemWith($constraint, $ok_value, $error_value)
51 {
52 $this->assertNull($constraint->problemWith($ok_value));
53 $this->assertInternalType("string", $constraint->problemWith($error_value));
54 }
55
59 public function testRestrict($constraint, $ok_value, $error_value)
60 {
61 $rf = new Data\Factory();
62 $ok = $rf->ok($ok_value);
63 $ok2 = $rf->ok($error_value);
64 $error = $rf->error("text");
65
66 $result = $constraint->restrict($ok);
67 $this->assertTrue($result->isOk());
68
69 $result = $constraint->restrict($ok2);
70 $this->assertTrue($result->isError());
71
72 $result = $constraint->restrict($error);
73 $this->assertSame($error, $result);
74 }
75
79 public function testWithProblemBuilder($constraint, $ok_value, $error_value)
80 {
81 $new_constraint = $constraint->withProblemBuilder(function () {
82 return "This was a vault";
83 });
84 $this->assertEquals("This was a vault", $new_constraint->problemWith($error_value));
85 }
86
87 public function constraintsProvider()
88 {
89 $f = new Validation\Factory(new Data\Factory());
90
91 return array(array($f->isInt(), 2, 2.2),
92 array($f->greaterThan(5), 6, 4),
93 array($f->lessThan(5), 4, 6)
94 );
95 }
96}
$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.
testWithProblemBuilder($constraint, $ok_value, $error_value)
@dataProvider constraintsProvider
testAccept($constraint, $ok_value, $error_value)
@dataProvider constraintsProvider
testRestrict($constraint, $ok_value, $error_value)
@dataProvider constraintsProvider
testCheck($constraint, $ok_value, $error_value)
@dataProvider constraintsProvider
testProblemWith($constraint, $ok_value, $error_value)
@dataProvider constraintsProvider
$error
Definition: Error.php:17