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