ILIAS  release_7 Revision v7.30-3-g800a261c036
LogicalOrTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'libs/composer/vendor/autoload.php';
5
6use ILIAS\Data;
8use PHPUnit\Framework\TestCase;
9
14class LogicalOrTest extends TestCase
15{
22 public function testAccept(LogicalOr $constraint, $okValue, $errorValue)
23 {
24 $this->assertTrue($constraint->accepts($okValue));
25 $this->assertFalse($constraint->accepts($errorValue));
26 }
27
34 public function testCheck(LogicalOr $constraint, $okValue, $errorValue)
35 {
36 $raised = false;
37
38 try {
39 $constraint->check($errorValue);
40 } catch (\UnexpectedValueException $e) {
41 $raised = true;
42 }
43
44 $this->assertTrue($raised);
45
46 try {
47 $constraint->check($okValue);
48 $raised = false;
49 } catch (\UnexpectedValueException $e) {
50 $raised = true;
51 }
52
53 $this->assertFalse($raised);
54 }
55
62 public function testProblemWith(LogicalOr $constraint, $okValue, $errorValue)
63 {
64 $this->assertNull($constraint->problemWith($okValue));
65 $this->assertIsString($constraint->problemWith($errorValue));
66 }
67
74 public function testRestrict(LogicalOr $constraint, $okValue, $errorValue)
75 {
76 $rf = new Data\Factory();
77 $ok = $rf->ok($okValue);
78 $ok2 = $rf->ok($errorValue);
79 $error = $rf->error('text');
80
81 $result = $constraint->applyTo($ok);
82 $this->assertTrue($result->isOk());
83
84 $result = $constraint->applyTo($ok2);
85 $this->assertTrue($result->isError());
86
87 $result = $constraint->applyTo($error);
88 $this->assertSame($error, $result);
89 }
90
97 public function testWithProblemBuilder(LogicalOr $constraint, $okValue, $errorValue)
98 {
99 $new_constraint = $constraint->withProblemBuilder(function () {
100 return "This was a vault";
101 });
102 $this->assertEquals("This was a vault", $new_constraint->problemWith($errorValue));
103 }
104
108 public function constraintsProvider() : array
109 {
110 $mock = $this->getMockBuilder(\ilLanguage::class)->disableOriginalConstructor()->getMock();
111 $data_factory = new Data\Factory();
112
113 $refinery = new \ILIAS\Refinery\Factory($data_factory, $mock);
114 return [
115 [$refinery->logical()->logicalOr([$refinery->int()->isLessThan(6), $refinery->int()->isGreaterThan(100)]), '5', 8],
116 [$refinery->logical()->logicalOr([$refinery->int()->isGreaterThan(5), $refinery->int()->isLessThan(2)]), 7, 3]
117 ];
118 }
119}
$result
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
Class LogicalOrTest.
testRestrict(LogicalOr $constraint, $okValue, $errorValue)
@dataProvider constraintsProvider
testWithProblemBuilder(LogicalOr $constraint, $okValue, $errorValue)
@dataProvider constraintsProvider
testAccept(LogicalOr $constraint, $okValue, $errorValue)
@dataProvider constraintsProvider
testProblemWith(LogicalOr $constraint, $okValue, $errorValue)
@dataProvider constraintsProvider
testCheck(LogicalOr $constraint, $okValue, $errorValue)
@dataProvider constraintsProvider
accepts($value)
Tells if the provided value complies.
applyTo(Result $result)
Restricts a Result.
check($value)
Checks the provided value.
problemWith($value)
Tells what the problem with the provided value is.
withProblemBuilder(callable $builder)
Get a constraint like this one with a builder for a custom error message.