Code Duplication    Length = 17-22 lines in 3 locations

tests/JSONCatalogProviderTest.php 3 locations

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