| @@ 27-101 (lines=75) @@ | ||
| 24 | use InvalidArgumentException; | |
| 25 | use Mockery as m; | |
| 26 | ||
| 27 | class FormatterFactoryTest extends TestCase | |
| 28 | { | |
| 29 | /** | |
| 30 | * @var FormatterFactory | |
| 31 | */ | |
| 32 | private $factory; | |
| 33 | ||
| 34 | public function setUp() | |
| 35 |     { | |
| 36 | $this->factory = new FormatterFactory(); | |
| 37 | } | |
| 38 | ||
| 39 | public function testInstanceOf() | |
| 40 |     { | |
| 41 | static::assertInstanceOf(FormatterFactoryInterface::class, $this->factory); | |
| 42 | } | |
| 43 | ||
| 44 | public function testCsvFormatter() | |
| 45 |     { | |
| 46 | $csvFormat = m::mock(CsvFormat::class)->makePartial(); | |
| 47 | ||
| 48 | $formatter = $this->factory->getFormatter($csvFormat); | |
| 49 | ||
| 50 | static::assertInstanceOf(CsvFormatter::class, $formatter); | |
| 51 | } | |
| 52 | ||
| 53 | public function testACsvFormatPretendingToBeCsvWillThrowAnException() | |
| 54 |     { | |
| 55 | $csvFormat = m::mock(FormatInterface::class); | |
| 56 |         $csvFormat->shouldReceive('getType') | |
| 57 |                   ->andReturn('csv'); | |
| 58 | ||
| 59 | static::expectException(InvalidArgumentException::class); | |
| 60 | ||
| 61 | $this->factory->getFormatter($csvFormat); | |
| 62 | } | |
| 63 | ||
| 64 | public function testJsonFormatter() | |
| 65 |     { | |
| 66 | $jsonFormat = m::mock(JsonFormat::class); | |
| 67 |         $jsonFormat->shouldReceive('getType') | |
| 68 |                    ->andReturn('json'); | |
| 69 |         $jsonFormat->shouldReceive('isSingleBlock') | |
| 70 | ->andReturn(false); | |
| 71 |         $jsonFormat->shouldReceive('getJsonEncodeOptions') | |
| 72 | ->andReturn(0); | |
| 73 |         $jsonFormat->shouldReceive('isEachLine') | |
| 74 | ->andReturn(true); | |
| 75 | $formatter = $this->factory->getFormatter($jsonFormat); | |
| 76 | ||
| 77 | static::assertInstanceOf(JsonFormatter::class, $formatter); | |
| 78 | } | |
| 79 | ||
| 80 | public function testAJsonFormatPretendingToBeCsvWillThrowAnException() | |
| 81 |     { | |
| 82 | $csvFormat = m::mock(FormatInterface::class); | |
| 83 |         $csvFormat->shouldReceive('getType') | |
| 84 |                   ->andReturn('json'); | |
| 85 | ||
| 86 | static::expectException(InvalidArgumentException::class); | |
| 87 | ||
| 88 | $this->factory->getFormatter($csvFormat); | |
| 89 | } | |
| 90 | ||
| 91 | public function testGetFormatterWithUnknownTypeWillThrowException() | |
| 92 |     { | |
| 93 | $format = m::mock(FormatInterface::class); | |
| 94 |         $format->shouldReceive('getType') | |
| 95 |                ->andReturn('random'); | |
| 96 | ||
| 97 | static::expectException(InvalidArgumentException::class); | |
| 98 | ||
| 99 | $this->factory->getFormatter($format); | |
| 100 | } | |
| 101 | } | |
| 102 | ||
| @@ 29-103 (lines=75) @@ | ||
| 26 | use InvalidArgumentException; | |
| 27 | use Mockery as m; | |
| 28 | ||
| 29 | class ParserFactoryTest extends TestCase | |
| 30 | { | |
| 31 | /** | |
| 32 | * @var ParserFactory | |
| 33 | */ | |
| 34 | private $factory; | |
| 35 | ||
| 36 | public function setUp() | |
| 37 |     { | |
| 38 | $this->factory = new ParserFactory(); | |
| 39 | } | |
| 40 | ||
| 41 | public function testInstanceOf() | |
| 42 |     { | |
| 43 | static::assertInstanceOf(ParserFactoryInterface::class, $this->factory); | |
| 44 | } | |
| 45 | ||
| 46 | public function testCsvParser() | |
| 47 |     { | |
| 48 | $csvFormat = m::mock(CsvFormat::class)->makePartial(); | |
| 49 | ||
| 50 | $formatter = $this->factory->getParser($csvFormat); | |
| 51 | ||
| 52 | static::assertInstanceOf(CsvParser::class, $formatter); | |
| 53 | } | |
| 54 | ||
| 55 | public function testACsvFormatPretendingToBeCsvWillThrowAnException() | |
| 56 |     { | |
| 57 | $csvFormat = m::mock(FormatInterface::class); | |
| 58 |         $csvFormat->shouldReceive('getType') | |
| 59 |                   ->andReturn('csv'); | |
| 60 | ||
| 61 | static::expectException(InvalidArgumentException::class); | |
| 62 | ||
| 63 | $this->factory->getParser($csvFormat); | |
| 64 | } | |
| 65 | ||
| 66 | public function testJsonParser() | |
| 67 |     { | |
| 68 | $jsonFormat = m::mock(JsonFormat::class); | |
| 69 |         $jsonFormat->shouldReceive('getType') | |
| 70 |                    ->andReturn('json'); | |
| 71 |         $jsonFormat->shouldReceive('isSingleBlock') | |
| 72 | ->andReturn(false); | |
| 73 |         $jsonFormat->shouldReceive('getJsonEncodeOptions') | |
| 74 | ->andReturn(0); | |
| 75 |         $jsonFormat->shouldReceive('isEachLine') | |
| 76 | ->andReturn(true); | |
| 77 | $formatter = $this->factory->getParser($jsonFormat); | |
| 78 | ||
| 79 | static::assertInstanceOf(JsonParser::class, $formatter); | |
| 80 | } | |
| 81 | ||
| 82 | public function testAJsonFormatPretendingToBeCsvWillThrowAnException() | |
| 83 |     { | |
| 84 | $csvFormat = m::mock(FormatInterface::class); | |
| 85 |         $csvFormat->shouldReceive('getType') | |
| 86 |                   ->andReturn('json'); | |
| 87 | ||
| 88 | static::expectException(InvalidArgumentException::class); | |
| 89 | ||
| 90 | $this->factory->getParser($csvFormat); | |
| 91 | } | |
| 92 | ||
| 93 | public function testGetFormatterWithUnknownTypeWillThrowException() | |
| 94 |     { | |
| 95 | $format = m::mock(FormatInterface::class); | |
| 96 |         $format->shouldReceive('getType') | |
| 97 |                ->andReturn('random'); | |
| 98 | ||
| 99 | static::expectException(InvalidArgumentException::class); | |
| 100 | ||
| 101 | $this->factory->getParser($format); | |
| 102 | } | |
| 103 | } | |
| 104 | ||