ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BuildArtifactObjectiveTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
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", "getArtifactName"])
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", "getArtifactName"])
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 $this->assertIsString($this->o->getHash());
69 }
70
71 public function testGetLabel(): void
72 {
73 $name = "my_artifact";
74
75 $this->o
76 ->expects($this->once())
77 ->method("getArtifactName")
78 ->with()
79 ->willReturn($name);
80
81 $this->assertEquals("Build $name Artifact", $this->o->getLabel());
82 }
83
84 public function testIsNotable(): void
85 {
86 $this->assertTrue($this->o->isNotable());
87 }
88
89 public function testAchieve(): void
90 {
91 $this->o
92 ->expects($this->once())
93 ->method("buildIn")
94 ->with($this->env)
95 ->willReturn($this->artifact);
96
97 $artifact = "THIS IS THE ARTIFACT";
98 $this->artifact
99 ->expects($this->once())
100 ->method("serialize")
101 ->with()
102 ->willReturn($artifact);
103
104 $this->o->achieve($this->env);
105
106 $path = $this->o::PATH();
107
108 $this->assertEquals($artifact, file_get_contents($path));
109 }
110
111 public function tearDown(): void
112 {
113 if (file_exists($this->o::PATH())) {
114 unlink($this->o::PATH());
115 }
116 }
117}
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:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...