|
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('Compiling "apib" files to mock', $this->commandTester->getDisplay()); |
|
57
|
|
|
$this->assertContains('Creating documentation from mock files compiled', $this->commandTester->getDisplay()); |
|
58
|
|
|
$this->assertDirectoryNotExists($this->getPathErrorFixtures() . 'Build'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return array |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function getSuccessArgumentsCommand() |
|
65
|
|
|
{ |
|
66
|
|
|
return [ |
|
67
|
|
|
'path' => $this->getPathSuccessFixtures(), |
|
68
|
|
|
]; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return array |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function getErrorArgumentsCommand() |
|
75
|
|
|
{ |
|
76
|
|
|
return [ |
|
77
|
|
|
'path' => $this->getPathErrorFixtures(), |
|
78
|
|
|
]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function getPathFixtures() |
|
85
|
|
|
{ |
|
86
|
|
|
return dirname(__DIR__) . '/Fixtures'; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function getPathSuccessFixtures() |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->getPathFixtures() . '/Success'; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function getPathErrorFixtures() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->getPathFixtures() . '/Error'; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function getStringJSONFileIncluded() |
|
109
|
|
|
{ |
|
110
|
|
|
$content = <<<EOF |
|
111
|
|
|
{ |
|
112
|
|
|
"rate_provider": [ |
|
113
|
|
|
{ |
|
114
|
|
|
"provider_cancel_policies": "xxx", |
|
115
|
|
|
"deatiledRate": "xxx", |
|
116
|
|
|
"remarks": "xxx" |
|
117
|
|
|
} |
|
118
|
|
|
], |
|
119
|
|
|
"ticket": [ |
|
120
|
|
|
{ |
|
121
|
|
|
"a": "xxx", |
|
122
|
|
|
"b": "xxx" |
|
123
|
|
|
} |
|
124
|
|
|
], |
|
125
|
|
|
"ttl": 3600 |
|
126
|
|
|
} |
|
127
|
|
|
EOF; |
|
128
|
|
|
return $content; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return string |
|
133
|
|
|
*/ |
|
134
|
|
|
protected function getStringXMLFileIncluded() |
|
135
|
|
|
{ |
|
136
|
|
|
$content = <<<EOF |
|
137
|
|
|
<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"> |
|
138
|
|
|
<csw:RequestId>4</csw:RequestId> |
|
139
|
|
|
<csw:SearchStatus status="complete"/> |
|
140
|
|
|
<csw:SearchResults recordSchema="http://www.opengis.net/cat/csw" numberOfRecordsMatched="1" numberOfRecordsReturned="1" nextRecord="0" expires="2007-02-09T16:32:35.29Z"> |
|
141
|
|
|
<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/"> |
|
142
|
|
|
<dc:contributor xmlns:dc="http://www.purl.org/dc/elements/1.1/" scheme="http://www.example.com">Raja</dc:contributor> |
|
143
|
|
|
<dc:identifier xmlns:dc="http://www.purl.org/dc/elements/1.1/">REC-1</dc:identifier> |
|
144
|
|
|
</csw:Record> |
|
145
|
|
|
</csw:SearchResults> |
|
146
|
|
|
</csw:GetRecordsResponse> |
|
147
|
|
|
EOF; |
|
148
|
|
|
|
|
149
|
|
|
return $content; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|