| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Tests\Service\ServiceIterator;
- use App\ApiResources\Export\ExportRequest;
- use App\Service\Export\ExporterInterface;
- use App\Service\ServiceIterator\ExporterIterator;
- use Exception;
- use PHPUnit\Framework\TestCase;
- class ExporterIteratorTest extends TestCase
- {
- /**
- * @see ExporterIterator::getExporterFor()
- */
- public function testGetExporterFor(): void
- {
- $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 = $this->getMockBuilder(ExporterIterator::class)
- ->setConstructorArgs([$exporters])
- ->setMethodsExcept(['getExporterFor'])
- ->getMock();
- $actualExporter = $iterator->getExporterFor($exportRequest);
- $this->assertEquals($exporter2, $actualExporter);
- }
- /**
- * @see ExporterIterator::getExporterFor()
- */
- public function testGetExporterForError(): void
- {
- $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 = $this->getMockBuilder(ExporterIterator::class)
- ->setConstructorArgs([$exporters])
- ->setMethodsExcept(['getExporterFor'])
- ->getMock();
- $this->expectException(Exception::class);
- $iterator->getExporterFor($exportRequest);
- }
- }
|