ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
BuildArtifactObjectiveTest.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;
10 
12 {
16  protected $o;
17 
21  protected $artifact;
22 
26  protected $env;
27 
28  public function setUp() : void
29  {
30  $this->o = $this
31  ->getMockBuilder(Artifact\BuildArtifactObjective::class)
32  ->setMethods(["build", "buildIn", "getArtifactPath"])
33  ->getMock();
34 
35  $this->artifact = $this->createMock(Setup\Artifact::class);
36  $this->env = $this->createMock(Setup\Environment::class);
37  }
38 
39  public function testBuildInDefaultsToBuild() : void
40  {
41  $this->o = $this
42  ->getMockBuilder(Artifact\BuildArtifactObjective::class)
43  ->setMethods(["build", "getArtifactPath"])
44  ->getMock();
45 
46  $this->o
47  ->expects($this->once())
48  ->method("build")
49  ->with()
50  ->willReturn($this->artifact);
51 
52  $this->assertSame($this->artifact, $this->o->buildIn($this->env));
53  }
54 
55  public function testGetPreconditions() : void
56  {
57  $this->assertEquals([], $this->o->getPreconditions($this->env));
58  }
59 
60  public function testGetHash() : void
61  {
62  $path = "path/to/artifact";
63 
64  $this->o
65  ->expects($this->once())
66  ->method("getArtifactPath")
67  ->with()
68  ->willReturn($path);
69 
70  $this->assertIsString($this->o->getHash());
71  }
72 
73  public function testGetLabel() : void
74  {
75  $path = "path/to/artifact";
76 
77  $this->o
78  ->expects($this->once())
79  ->method("getArtifactPath")
80  ->with()
81  ->willReturn($path);
82 
83  $this->assertEquals("Build $path", $this->o->getLabel());
84  }
85 
86  public function testIsNotable() : void
87  {
88  $this->assertTrue($this->o->isNotable());
89  }
90 
91  const TEST_PATH = "BuildArtifactObjectiveTest_testAchive";
92 
93  public function testAchieve() : void
94  {
95  $path = self::TEST_PATH;
96  $this->o
97  ->expects($this->atLeastOnce())
98  ->method("getArtifactPath")
99  ->with()
100  ->willReturn($path);
101 
102  $this->o
103  ->expects($this->once())
104  ->method("buildIn")
105  ->with($this->env)
106  ->willReturn($this->artifact);
107 
108  $artifact = "THIS IS THE ARTIFACT";
109  $this->artifact
110  ->expects($this->once())
111  ->method("serialize")
112  ->with()
113  ->willReturn($artifact);
114 
115  $this->o->achieve($this->env);
116 
117  $this->assertEquals($artifact, file_get_contents($path));
118  }
119 
120  public function tearDown() : void
121  {
122  if (file_exists(getcwd() . "/" . self::TEST_PATH)) {
123  unlink(getcwd() . "/" . self::TEST_PATH);
124  }
125  }
126 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:11