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