ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
5namespace ILIAS\Tests\Setup;
6
8
9class BuildArtifactObjectiveTest extends \PHPUnit\Framework\TestCase
10{
11 public function setUp() : void
12 {
13 $this->o = $this
14 ->getMockBuilder(Setup\BuildArtifactObjective::class)
15 ->setMethods(["build", "buildIn", "getArtifactPath"])
16 ->getMock();
17
18 $this->artifact = $this->createMock(Setup\Artifact::class);
19 $this->env = $this->createMock(Setup\Environment::class);
20 }
21
23 {
24 $this->o = $this
25 ->getMockBuilder(Setup\BuildArtifactObjective::class)
26 ->setMethods(["build", "getArtifactPath"])
27 ->getMock();
28
29 $this->o
30 ->expects($this->once())
31 ->method("build")
32 ->with()
33 ->willReturn($this->artifact);
34
35 $this->assertSame($this->artifact, $this->o->buildIn($this->env));
36 }
37
38 public function testGetPreconditions()
39 {
40 $this->assertEquals([], $this->o->getPreconditions($this->env));
41 }
42
43 public function testGetHash()
44 {
45 $path = "path/to/artifact";
46
47 $this->o
48 ->expects($this->once())
49 ->method("getArtifactPath")
50 ->with()
51 ->willReturn($path);
52
53 $this->assertIsString($this->o->getHash());
54 }
55
56 public function testGetLabel()
57 {
58 $path = "path/to/artifact";
59
60 $this->o
61 ->expects($this->once())
62 ->method("getArtifactPath")
63 ->with()
64 ->willReturn($path);
65
66 $this->assertEquals("Build $path", $this->o->getLabel());
67 }
68
69 public function testIsNotable()
70 {
71 $this->assertTrue($this->o->isNotable());
72 }
73
74 const TEST_PATH = "BuildArtifactObjectiveTest_testAchive";
75
76 public function testAchieve()
77 {
78 $path = self::TEST_PATH;
79 $this->o
80 ->expects($this->atLeastOnce())
81 ->method("getArtifactPath")
82 ->with()
83 ->willReturn($path);
84
85 $this->o
86 ->expects($this->once())
87 ->method("buildIn")
88 ->with($this->env)
89 ->willReturn($this->artifact);
90
91 $artifact = "THIS IS THE ARTIFACT";
92 $this->artifact
93 ->expects($this->once())
94 ->method("serialize")
95 ->with()
96 ->willReturn($artifact);
97
98 $this->o->achieve($this->env);
99
100 $this->assertEquals($artifact, file_get_contents($path));
101 }
102
103 public function tearDown() : void
104 {
105 if (file_exists(getcwd() . "/" . self::TEST_PATH)) {
106 unlink(getcwd() . "/" . self::TEST_PATH);
107 }
108 }
109}
An exception for terminatinating execution or to throw for unit testing.