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