ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
TentativelyTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
7 use ILIAS\Setup;
11 
13 {
14  use Test\Helper;
15 
19  protected $objective;
20 
24  protected $precondition;
25 
29  protected $tentatively;
30 
31  public function setUp() : void
32  {
33  $this->objective = $this->newObjective();
34  $this->precondition = $this->newObjective();
35 
36  $this->tentatively = new Objective\Tentatively($this->objective);
37  $this->double_tentatively = new Objective\Tentatively($this->tentatively);
38  }
39 
40  public function testGetHash() : void
41  {
42  $this->assertEquals(
43  "tentatively " . $this->objective->getHash(),
44  $this->tentatively->getHash()
45  );
46  }
47 
48  public function testDoubleTentativelyGetHash() : void
49  {
50  $this->assertEquals(
51  $this->tentatively->getHash(),
52  $this->double_tentatively->getHash()
53  );
54  }
55 
56  public function testGetLabel() : void
57  {
58  $label = "some_label";
59 
60  $this->objective
61  ->expects($this->once())
62  ->method("getLabel")
63  ->willReturn($label);
64 
65  $this->assertEquals(
66  "Tentatively: $label",
67  $this->tentatively->getLabel()
68  );
69  }
70 
71  public function testDoubleTentativelyGetLabel() : void
72  {
73  $label = "some_label";
74 
75  $this->objective
76  ->method("getLabel")
77  ->willReturn($label);
78 
79  $this->assertEquals(
80  $this->tentatively->getLabel(),
81  $this->double_tentatively->getLabel()
82  );
83  }
84  public function testIsNotable() : void
85  {
86  $notable = true;
87 
88  $this->objective
89  ->method("isNotable")
90  ->willReturn($notable);
91 
92  $this->assertEquals($notable, $this->tentatively->isNotable());
93  $this->assertEquals($notable, $this->double_tentatively->isNotable());
94  }
95 
96  public function testGetPreconditions() : void
97  {
98  $other = $this->newObjective();
99 
100  $env = $this->createMock(Setup\Environment::class);
101 
102  $this->objective
103  ->expects($this->once())
104  ->method("getPreconditions")
105  ->with($env)
106  ->willReturn([$other]);
107 
108  $this->assertEquals(
109  [new Objective\Tentatively($other)],
110  $this->tentatively->getPreconditions($env)
111  );
112  }
113 
114  public function testAchieve() : void
115  {
116  $env = $this->createMock(Setup\Environment::class);
117 
118  $this->objective
119  ->expects($this->once())
120  ->method("achieve")
121  ->with($env)
122  ->willReturn($env);
123 
124  $res = $this->tentatively->achieve($env);
125  $this->assertSame($env, $res);
126  }
127 
128  public function testAchieveThrows() : void
129  {
130  $env = $this->createMock(Setup\Environment::class);
131 
132  $this->objective
133  ->expects($this->once())
134  ->method("achieve")
135  ->with($env)
136  ->will($this->throwException(new Setup\UnachievableException()));
137 
138  $res = $this->tentatively->achieve($env);
139  $this->assertSame($env, $res);
140  }
141 
142  public function testIsApplicable() : void
143  {
144  $env = $this->createMock(Setup\Environment::class);
145  $is_applicable = random_int(0, 1) == 1;
146 
147  $this->objective
148  ->expects($this->once())
149  ->method("isApplicable")
150  ->with($env)
151  ->willReturn($is_applicable);
152 
153  $this->assertEquals($is_applicable, $this->tentatively->isApplicable($env));
154  }
155 }
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:14
Signals that some goal won&#39;t be achievable by actions of the system ever.
foreach($_POST as $key=> $value) $res
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:13