Passed
Push — main ( db6d59...d4b692 )
by Michiel
25:01 queued 14:36
created

VisualizerTaskTest::testDestinationFileExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Test\Task\Optional;
22
23
use Phing\Test\Support\BuildFileTest;
24
25
/**
26
 * @internal
27
 */
28
class VisualizerTaskTest extends BuildFileTest
29
{
30
    /**
31
     * @throws \Phing\Io\IOException
32
     */
33
    public function setUp(): void
34
    {
35
        $this->configureProject(PHING_TEST_BASE . '/etc/tasks/ext/visualizer/VisualizerTaskTest.xml');
36
    }
37
38
    public function tearDown(): void
39
    {
40
        $this->executeTarget('clean');
41
    }
42
43
    /**
44
     * Testing different diagram formats: png, puml, svg and eps.
45
     */
46
    public function testFormat(): void
47
    {
48
        $this->executeTarget(__FUNCTION__);
49
        $this->assertFileExists(PHING_TEST_BASE . '/etc/tasks/ext/visualizer/VisualizerTaskTest.puml');
50
        $this->assertInLogs('VisualizerTaskTest.puml');
51
        $this->assertFileSizeAtLeast(PHING_TEST_BASE . '/etc/tasks/ext/visualizer/VisualizerTaskTest.puml', 1200);
52
    }
53
54
    /**
55
     * Test that an exception is raised when invalid format is used.
56
     */
57
    public function testInvalidFormat(): void
58
    {
59
        $this->expectBuildException(__FUNCTION__, "'jpg' is not a valid format");
60
        $this->assertInLogs("'jpg' is not a valid format");
61
    }
62
63
    /**
64
     * Testing custom destination including filename.
65
     */
66
    public function testDestinationFile(): void
67
    {
68
        $this->executeTarget(__FUNCTION__);
69
        $this->assertFileExists(PHING_TEST_BASE . '/tmp/my-diagram.puml');
70
        $this->assertInLogs('my-diagram.puml');
71
        $this->assertFileSizeAtLeast(PHING_TEST_BASE . '/tmp/my-diagram.puml', 1200);
72
    }
73
74
    /**
75
     * Testing file extension is the same as the one declared with `format`.
76
     */
77
    public function testDestinationFileExtension(): void
78
    {
79
        $this->executeTarget(__FUNCTION__);
80
        $this->assertFileExists(PHING_TEST_BASE . '/tmp/my-diagram.png.puml');
81
        $this->assertInLogs('my-diagram.png.puml');
82
        $this->assertFileSizeAtLeast(PHING_TEST_BASE . '/tmp/my-diagram.png.puml', 1200);
83
    }
84
85
    /**
86
     * Testing custom destination without filename.
87
     */
88
    public function testDestinationDirectory(): void
89
    {
90
        $this->executeTarget(__FUNCTION__);
91
        $this->assertFileExists(PHING_TEST_BASE . '/tmp/VisualizerTaskTest.puml');
92
        $this->assertInLogs('VisualizerTaskTest.puml');
93
        $this->assertFileSizeAtLeast(PHING_TEST_BASE . '/tmp/VisualizerTaskTest.puml', 1200);
94
    }
95
96
    /**
97
     * Testing that an exception is raised when an invalid directory is used as destination.
98
     */
99
    public function testInvalidDestination(): void
100
    {
101
        $this->expectBuildException(__FUNCTION__, "Directory 'foo/bar/baz/' is invalid");
102
        $this->assertInLogs("Directory 'foo/bar/baz/' is invalid");
103
    }
104
105
    /**
106
     * Testing that exception is raised when an invalid URL is used.
107
     */
108
    public function testInvalidServer(): void
109
    {
110
        $this->expectBuildException(__FUNCTION__, 'Invalid PlantUml server');
111
        $this->assertInLogs('Invalid PlantUml server');
112
    }
113
}
114