1 | <?php |
||
23 | class ImportCommandTest extends \PHPUnit_Framework_TestCase |
||
24 | { |
||
25 | /** |
||
26 | * String Http Client Class. |
||
27 | */ |
||
28 | const CLIENT = 'Graviton\ImportExport\Service\HttpClient'; |
||
29 | |||
30 | /** |
||
31 | * @dataProvider uploadFileProvider |
||
32 | * |
||
33 | * @param string $host import target host with protocol |
||
34 | * @param string $file file to import |
||
35 | * @param string $path resulting path from file |
||
36 | * |
||
37 | * @return void |
||
38 | */ |
||
39 | public function testUploadFile($host, $file, $path) |
||
40 | { |
||
41 | $clientMock = $this->getMockBuilder(self::CLIENT)->getMock(); |
||
42 | |||
43 | $promiseMock = $this->getMock('GuzzleHttp\Promise\Promise'); |
||
44 | |||
45 | $clientMock |
||
46 | ->method('requestAsync') |
||
47 | ->will($this->returnValue($promiseMock)); |
||
48 | |||
49 | $responseMock = $this->getMock('Psr\Http\Message\ResponseInterface'); |
||
50 | |||
51 | $responseMock |
||
52 | ->method('getHeader') |
||
53 | ->with('Link') |
||
54 | ->willReturn(['<' . $host . $path . '>; rel="self"']); |
||
55 | |||
56 | $promiseMock |
||
57 | ->method('then') |
||
58 | ->will( |
||
59 | $this->returnCallback( |
||
60 | function ($ok) use ($responseMock) { |
||
61 | $ok($responseMock); |
||
62 | } |
||
63 | ) |
||
64 | ); |
||
65 | |||
66 | $sut = new ImportCommand( |
||
67 | $clientMock, |
||
68 | new Finder(), |
||
69 | new FrontMatter(), |
||
70 | new Parser(), |
||
71 | new VarCloner(), |
||
72 | new Dumper() |
||
73 | ); |
||
74 | |||
75 | $cmdTester = $this->getTester($sut, $file); |
||
76 | |||
77 | $this->assertContains('Loading data from ' . $file, $cmdTester->getDisplay()); |
||
78 | $this->assertContains('Wrote <' . $host . $path . '>; rel="self"', $cmdTester->getDisplay()); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return array[] |
||
83 | */ |
||
84 | public function uploadFileProvider() |
||
94 | |||
95 | /** |
||
96 | * @return array[] |
||
97 | */ |
||
98 | public function uploadImageFileProvider() |
||
108 | |||
109 | /** |
||
110 | * @dataProvider errorFileProvider |
||
111 | * |
||
112 | * @param string $host import target host with protocol |
||
113 | * @param string $file file to import |
||
114 | * @param array $errors errors to check for (check valid case if none given) |
||
115 | * |
||
116 | * @return void |
||
117 | */ |
||
118 | public function testErrorFile($host, $file, $errors = []) |
||
180 | |||
181 | /** |
||
182 | * @return array[] |
||
183 | */ |
||
184 | public function errorFileProvider() |
||
205 | |||
206 | /** |
||
207 | * test rewriting of contents with --rewrite-host |
||
208 | * |
||
209 | * @return void |
||
210 | */ |
||
211 | public function testRewrite() |
||
267 | |||
268 | /** |
||
269 | * @param ImportCommand $sut command under test |
||
270 | * @param string $file file to load |
||
271 | * @param array $args additional arguments |
||
272 | * |
||
273 | * @return CommandTester |
||
274 | */ |
||
275 | private function getTester(ImportCommand $sut, $file, array $args = []) |
||
300 | } |
||
301 |