|
|
@@ -0,0 +1,56 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+use App\ApiResources\Export\ExportRequest;
|
|
|
+use App\Service\Export\Encoder\EncoderInterface;
|
|
|
+use App\Service\Export\ExporterInterface;
|
|
|
+use App\Service\ServiceIterator\EncoderIterator;
|
|
|
+use App\Service\ServiceIterator\ExporterIterator;
|
|
|
+use PHPUnit\Framework\TestCase;
|
|
|
+
|
|
|
+class ExporterIteratorTest extends TestCase
|
|
|
+{
|
|
|
+ public function testGetExporterFor() {
|
|
|
+ $exportRequest = $this->getMockBuilder(ExportRequest::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $mocker = $this->getMockBuilder(ExporterInterface::class);
|
|
|
+
|
|
|
+ $exporter1 = $mocker->getMock();
|
|
|
+ $exporter1->method('support')->willReturn(false);
|
|
|
+
|
|
|
+ $exporter2 = $mocker->getMock();
|
|
|
+ $exporter2->expects($this->once())->method('support')->with($exportRequest)->willReturn(true);
|
|
|
+
|
|
|
+ $exporter3 = $mocker->getMock();
|
|
|
+ $exporter3->method('support')->willReturn(false);
|
|
|
+
|
|
|
+ $exporters = [$exporter1, $exporter2, $exporter3];
|
|
|
+
|
|
|
+ $iterator = new ExporterIterator($exporters);
|
|
|
+ $actualExporter = $iterator->getExporterFor($exportRequest);
|
|
|
+
|
|
|
+ $this->assertEquals($exporter2, $actualExporter);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testGetExporterForError() {
|
|
|
+ $exportRequest = $this->getMockBuilder(ExportRequest::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $mocker = $this->getMockBuilder(ExporterInterface::class);
|
|
|
+
|
|
|
+ $exporter1 = $mocker->getMock();
|
|
|
+ $exporter1->method('support')->willReturn(false);
|
|
|
+
|
|
|
+ $exporter2 = $mocker->getMock();
|
|
|
+ $exporter2->method('support')->willReturn(false);
|
|
|
+
|
|
|
+ $exporters = [$exporter1, $exporter2];
|
|
|
+
|
|
|
+ $iterator = new ExporterIterator($exporters);
|
|
|
+
|
|
|
+ $this->expectException(Exception::class);
|
|
|
+ $iterator->getExporterFor($exportRequest);
|
|
|
+ }
|
|
|
+}
|