Code Duplication    Length = 75-75 lines in 2 locations

tests/unit/Format/Formatter/FormatterFactoryTest.php 1 location

@@ 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

tests/unit/Format/Parser/ParserFactoryTest.php 1 location

@@ 27-101 (lines=75) @@
24
use InvalidArgumentException;
25
use Mockery as m;
26
27
class ParserFactoryTest extends TestCase
28
{
29
    /**
30
     * @var ParserFactory
31
     */
32
    private $factory;
33
34
    public function setUp()
35
    {
36
        $this->factory = new ParserFactory();
37
    }
38
39
    public function testInstanceOf()
40
    {
41
        static::assertInstanceOf(ParserFactoryInterface::class, $this->factory);
42
    }
43
44
    public function testCsvParser()
45
    {
46
        $csvFormat = m::mock(CsvFormat::class)->makePartial();
47
48
        $formatter = $this->factory->getParser($csvFormat);
49
50
        static::assertInstanceOf(CsvParser::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->getParser($csvFormat);
62
    }
63
64
    public function testJsonParser()
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->getParser($jsonFormat);
76
77
        static::assertInstanceOf(JsonParser::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->getParser($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->getParser($format);
100
    }
101
}
102