Code Duplication    Length = 17-22 lines in 3 locations

tests/JSONCatalogProviderTest.php 3 locations

@@ 46-64 (lines=19) @@
43
     * @test
44
     * @expectedException \Wambo\Catalog\Error\CatalogException
45
     */
46
    public function getCatalog_JSONIsInvalid_CatalogExceptionIsThrown()
47
    {
48
        // arrange
49
        $filesystem = new Filesystem(new MemoryAdapter());
50
        $catalogMapperMock = $this->getMockBuilder(CatalogMapper::class)->disableOriginalConstructor()->getMock();
51
        $catalogMapperMock->method("getCatalog")->willReturn(new Catalog(array()));
52
        /** @var $catalogMapperMock CatalogMapper A mock for the CatalogMapper class */
53
54
        $catalogJSON = <<<JSON
55
[
56
    {},,],,
57
]
58
JSON;
59
        $filesystem->write("catalog.json", $catalogJSON);
60
        $jsonCatalogProvider = new JSONCatalogProvider($filesystem, "catalog.json", $catalogMapperMock);
61
62
        // act
63
        $jsonCatalogProvider->getCatalog();
64
    }
65
66
    /**
67
     * If the CatalogMapper throws an exception, the provider should throw a CatalogException.
@@ 72-88 (lines=17) @@
69
     * @test
70
     * @expectedException Wambo\Catalog\Error\CatalogException
71
     */
72
    public function getCatalog_JSONIsValid_MapperThrowsException_CatalogExceptionIsThrown()
73
    {
74
        // arrange
75
        $filesystem = new Filesystem(new MemoryAdapter());
76
        $catalogMapperMock = $this->getMockBuilder(CatalogMapper::class)->disableOriginalConstructor()->getMock();
77
        $catalogMapperMock->method("getCatalog")->willThrowException(new Exception("Some mapping error"));
78
        /** @var $catalogMapperMock CatalogMapper A mock for the CatalogMapper class */
79
80
        $catalogJSON = <<<JSON
81
[]
82
JSON;
83
        $filesystem->write("catalog.json", $catalogJSON);
84
        $jsonCatalogProvider = new JSONCatalogProvider($filesystem, "catalog.json", $catalogMapperMock);
85
86
        // act
87
        $jsonCatalogProvider->getCatalog();
88
    }
89
90
    /**
91
     * If the CatalogMapper returns a catalog, the provider should return that catalog.
@@ 95-116 (lines=22) @@
92
     *
93
     * @test
94
     */
95
    public function getCatalog_JSONIsValid_MapperReturnsCatalog_CatalogIsReturned()
96
    {
97
        // arrange
98
        $filesystem = new Filesystem(new MemoryAdapter());
99
        $catalogMapperMock = $this->getMockBuilder(CatalogMapper::class)->disableOriginalConstructor()->getMock();
100
        $catalogMapperMock->method("getCatalog")->willReturn(new Catalog(array()));
101
        /** @var $catalogMapperMock CatalogMapper A mock for the CatalogMapper class */
102
103
        $catalogJSON = <<<JSON
104
[
105
    {}
106
]
107
JSON;
108
        $filesystem->write("catalog.json", $catalogJSON);
109
        $jsonCatalogProvider = new JSONCatalogProvider($filesystem, "catalog.json", $catalogMapperMock);
110
111
        // act
112
        $catalog = $jsonCatalogProvider->getCatalog();
113
114
        // assert
115
        $this->assertNotNull($catalog, "getCatalog should return a catalog if the mapper returned one");
116
    }
117
118
    /**
119
     * Integration test with local filesystem