CompileCommandTest::getPathSuccessFixtures()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Tests\BernardoSecades\Accommodation\Mocks\Command;
4
5
use BernardoSecades\SplitBlue\Command\CompileCommand;
6
use Symfony\Component\Console\Tester\CommandTester;
7
use Symfony\Component\Filesystem\Filesystem;
8
9
class CompileCommandTest extends \PHPUnit_Framework_TestCase
10
{
11
    /** @var  CommandTester $commandTester */
12
    protected $commandTester;
13
14
    protected function setUp()
15
    {
16
        $command = new CompileCommand();
17
        $this->commandTester = new CommandTester($command);
18
    }
19
20
    protected function tearDown()
21
    {
22
        $fileSystem = new FileSystem();
23
        $fileSystem->remove($this->getPathFixtures() . '/Success/Compile/Build');
24
    }
25
26
    /**
27
     * @test
28
     */
29
    public function generateMockAndDocFiles()
30
    {
31
        $this->commandTester->execute($this->getSuccessArgumentsCommand());
32
        $this->assertEquals(0, $this->commandTester->getStatusCode());
33
        $this->assertContains('Compiling "apib" files to mock', $this->commandTester->getDisplay());
34
        $this->assertContains('Creating documentation from mock files compiled', $this->commandTester->getDisplay());
35
        $this->assertFileExists($this->getPathFixtures() . '/Success/Compile/Build/out.apib');
36
        $this->assertFileExists($this->getPathFixtures() . '/Success/Compile/Build/out.html');
37
38
        $this->assertContains(
39
            $this->getStringJSONFileIncluded(),
40
            file_get_contents($this->getPathFixtures() . '/Success/Compile/Build/out.apib')
41
        );
42
43
        $this->assertContains(
44
            $this->getStringXMLFileIncluded(),
45
            file_get_contents($this->getPathFixtures() . '/Success/Compile/Build/out.apib')
46
        );
47
    }
48
49
    /**
50
     * @test
51
     */
52
    public function errorGenerateMockAndDocFiles()
53
    {
54
        $this->commandTester->execute($this->getErrorArgumentsCommand());
55
        $this->assertEquals(1, $this->commandTester->getStatusCode());
56
        $this->assertContains('There are not index files to generate mock or doc files', $this->commandTester->getDisplay());
57
        $this->assertDirectoryNotExists($this->getPathErrorFixtures() . 'Build');
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    protected function getSuccessArgumentsCommand()
64
    {
65
        return [
66
            'path' => $this->getPathSuccessFixtures(),
67
        ];
68
    }
69
70
    /**
71
     * @return array
72
     */
73
    protected function getErrorArgumentsCommand()
74
    {
75
        return [
76
            'path' => $this->getPathErrorFixtures(),
77
        ];
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    protected function getPathFixtures()
84
    {
85
        return dirname(__DIR__) . '/Fixtures';
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    protected function getPathSuccessFixtures()
92
    {
93
        return $this->getPathFixtures() . '/Success';
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    protected function getPathErrorFixtures()
100
    {
101
        return $this->getPathFixtures() . '/Error';
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    protected function getStringJSONFileIncluded()
108
    {
109
        $content = <<<EOF
110
{
111
    "rate_provider": [
112
        {
113
            "provider_cancel_policies": "xxx",
114
            "deatiledRate": "xxx",
115
            "remarks": "xxx"
116
        }
117
    ],
118
    "ticket": [
119
        {
120
            "a": "xxx",
121
            "b": "xxx"
122
        }
123
    ],
124
    "ttl": 3600
125
}
126
EOF;
127
        return $content;
128
    }
129
130
    /**
131
     * @return string
132
     */
133
    protected function getStringXMLFileIncluded()
134
    {
135
        $content = <<<EOF
136
<csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw" xmlns:dc="http://www.purl.org/dc/elements/1.1/" xmlns:dct="http://www.purl.org/dc/terms/" xsi:schemaLocation="http://www.opengis.net/cat/csw http://localhost:8888/SpatialWS-SpatialWS-context-root/cswservlet?recordTypeId=1 " version="2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
137
   <csw:RequestId>4</csw:RequestId>
138
   <csw:SearchStatus status="complete"/>
139
   <csw:SearchResults recordSchema="http://www.opengis.net/cat/csw" numberOfRecordsMatched="1" numberOfRecordsReturned="1" nextRecord="0" expires="2007-02-09T16:32:35.29Z">
140
      <csw:Record xmlns:dc="http://www.purl.org/dc/elements/1.1/" xmlns:ows="http://www.opengis.net/ows" xmlns:dct="http://www.purl.org/dc/terms/">
141
         <dc:contributor xmlns:dc="http://www.purl.org/dc/elements/1.1/" scheme="http://www.example.com">Raja</dc:contributor>
142
         <dc:identifier xmlns:dc="http://www.purl.org/dc/elements/1.1/">REC-1</dc:identifier>
143
      </csw:Record>
144
   </csw:SearchResults>
145
</csw:GetRecordsResponse>
146
EOF;
147
148
        return $content;
149
    }
150
}
151