ILIAS  release_8 Revision v8.24
BuildArtifactObjectiveTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
23use ILIAS\Setup;
25use PHPUnit\Framework\TestCase;
26
27class BuildArtifactObjectiveTest extends TestCase
28{
29 protected \PHPUnit\Framework\MockObject\MockObject $o;
30
33
34 public function setUp(): void
35 {
36 $this->o = $this
37 ->getMockBuilder(Artifact\BuildArtifactObjective::class)
38 ->onlyMethods(["build", "buildIn", "getArtifactPath"])
39 ->getMock();
40
41 $this->artifact = $this->createMock(Setup\Artifact::class);
42 $this->env = $this->createMock(Setup\Environment::class);
43 }
44
45 public function testBuildInDefaultsToBuild(): void
46 {
47 $this->o = $this
48 ->getMockBuilder(Artifact\BuildArtifactObjective::class)
49 ->onlyMethods(["build", "getArtifactPath"])
50 ->getMock();
51
52 $this->o
53 ->expects($this->once())
54 ->method("build")
55 ->with()
56 ->willReturn($this->artifact);
57
58 $this->assertSame($this->artifact, $this->o->buildIn($this->env));
59 }
60
61 public function testGetPreconditions(): void
62 {
63 $this->assertEquals([], $this->o->getPreconditions($this->env));
64 }
65
66 public function testGetHash(): void
67 {
68 $path = "path/to/artifact";
69
70 $this->o
71 ->expects($this->once())
72 ->method("getArtifactPath")
73 ->with()
74 ->willReturn($path);
75
76 $this->assertIsString($this->o->getHash());
77 }
78
79 public function testGetLabel(): void
80 {
81 $path = "path/to/artifact";
82
83 $this->o
84 ->expects($this->once())
85 ->method("getArtifactPath")
86 ->with()
87 ->willReturn($path);
88
89 $this->assertEquals("Build $path", $this->o->getLabel());
90 }
91
92 public function testIsNotable(): void
93 {
94 $this->assertTrue($this->o->isNotable());
95 }
96
97 public const TEST_PATH = "BuildArtifactObjectiveTest_testAchive";
98
99 public function testAchieve(): void
100 {
102 $this->o
103 ->expects($this->atLeastOnce())
104 ->method("getArtifactPath")
105 ->with()
106 ->willReturn($path);
107
108 $this->o
109 ->expects($this->once())
110 ->method("buildIn")
111 ->with($this->env)
112 ->willReturn($this->artifact);
113
114 $artifact = "THIS IS THE ARTIFACT";
115 $this->artifact
116 ->expects($this->once())
117 ->method("serialize")
118 ->with()
119 ->willReturn($artifact);
120
121 $this->o->achieve($this->env);
122
123 $this->assertEquals($artifact, file_get_contents($path));
124 }
125
126 public function tearDown(): void
127 {
128 if (file_exists(getcwd() . "/" . self::TEST_PATH)) {
129 unlink(getcwd() . "/" . self::TEST_PATH);
130 }
131 }
132}
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:28
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
$path
Definition: ltiservices.php:32
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...