ILIAS  release_8 Revision v8.24
TentativelyTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
23use ILIAS\Setup;
26use PHPUnit\Framework\TestCase;
27
28class TentativelyTest extends TestCase
29{
30 use Test\Helper;
31
35
36 public function setUp(): void
37 {
38 $this->objective = $this->newObjective();
39 $this->precondition = $this->newObjective();
40
41 $this->tentatively = new Objective\Tentatively($this->objective);
42 $this->double_tentatively = new Objective\Tentatively($this->tentatively);
43 }
44
45 public function testGetHash(): void
46 {
47 $this->assertEquals(
48 "tentatively " . $this->objective->getHash(),
49 $this->tentatively->getHash()
50 );
51 }
52
53 public function testDoubleTentativelyGetHash(): void
54 {
55 $this->assertEquals(
56 $this->tentatively->getHash(),
57 $this->double_tentatively->getHash()
58 );
59 }
60
61 public function testGetLabel(): void
62 {
63 $label = "some_label";
64
65 $this->objective
66 ->expects($this->once())
67 ->method("getLabel")
68 ->willReturn($label);
69
70 $this->assertEquals(
71 "Tentatively: $label",
72 $this->tentatively->getLabel()
73 );
74 }
75
76 public function testDoubleTentativelyGetLabel(): void
77 {
78 $label = "some_label";
79
80 $this->objective
81 ->method("getLabel")
82 ->willReturn($label);
83
84 $this->assertEquals(
85 $this->tentatively->getLabel(),
86 $this->double_tentatively->getLabel()
87 );
88 }
89 public function testIsNotable(): void
90 {
91 $notable = true;
92
93 $this->objective
94 ->method("isNotable")
95 ->willReturn($notable);
96
97 $this->assertEquals($notable, $this->tentatively->isNotable());
98 $this->assertEquals($notable, $this->double_tentatively->isNotable());
99 }
100
101 public function testGetPreconditions(): void
102 {
103 $other = $this->newObjective();
104
105 $env = $this->createMock(Setup\Environment::class);
106
107 $this->objective
108 ->expects($this->once())
109 ->method("getPreconditions")
110 ->with($env)
111 ->willReturn([$other]);
112
113 $this->assertEquals(
114 [new Objective\Tentatively($other)],
115 $this->tentatively->getPreconditions($env)
116 );
117 }
118
119 public function testAchieve(): void
120 {
121 $env = $this->createMock(Setup\Environment::class);
122
123 $this->objective
124 ->expects($this->once())
125 ->method("achieve")
126 ->with($env)
127 ->willReturn($env);
128
129 $res = $this->tentatively->achieve($env);
130 $this->assertSame($env, $res);
131 }
132
133 public function testAchieveThrows(): void
134 {
135 $env = $this->createMock(Setup\Environment::class);
136
137 $this->objective
138 ->expects($this->once())
139 ->method("achieve")
140 ->with($env)
141 ->will($this->throwException(new Setup\UnachievableException()));
142
143 $res = $this->tentatively->achieve($env);
144 $this->assertSame($env, $res);
145 }
146
147 public function testIsApplicable(): void
148 {
149 $env = $this->createMock(Setup\Environment::class);
150 $is_applicable = random_int(0, 1) == 1;
151
152 $this->objective
153 ->expects($this->once())
154 ->method("isApplicable")
155 ->with($env)
156 ->willReturn($is_applicable);
157
158 $this->assertEquals($is_applicable, $this->tentatively->isApplicable($env));
159 }
160}
A wrapper around an objective that attempts to achieve the wrapped objective but won't stop the proce...
Definition: Tentatively.php:30
Signals that some goal won't be achievable by actions of the system ever.
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...