Passed
Push — develop ( 415154...b14201 )
by Andreas
03:08
created

CatalogFactoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 77.08 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 4
dl 37
loc 48
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
use League\Flysystem\Filesystem;
3
use League\Flysystem\Memory\MemoryAdapter;
4
use Wambo\Catalog\CatalogFactory;
5
use Wambo\Catalog\Error\CatalogException;
6
7
/**
8
 * Class CatalogFactoryTest tests the Wambo\Catalog\CatalogFactory class.
9
 */
10
class CatalogFactoryTest extends PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @test
14
     */
15
    public function getCatalog_IntegrationTest_CatalogJSONIsValid_CatalogIsReturned()
16
    {
17
        // arrange
18
        $catalogFilePath = "catalog.json";
19
        $filesystem = new Filesystem(new MemoryAdapter());
20
        $catalogJSON = <<<JSON
21
[]
22
JSON;
23
        $filesystem->write($catalogFilePath, $catalogJSON);
24
25
        $catalogFactory = new CatalogFactory($filesystem, $catalogFilePath);
26
27
        // act
28
        $catalog = $catalogFactory->getCatalog();
29
30
        // assert
31
        $this->assertNotNull($catalog, "The catalog should not be null");
32
    }
33
34
    /**
35
     * @test
36
     * @expectedException Wambo\Catalog\Error\CatalogException
37
     */
38
    public function getCatalog_IntegrationTest_CatalogJSONIsInvalid_CatalogExceptionIsThrown()
39
    {
40
        // arrange
41
        $catalogFilePath = "catalog.json";
42
        $filesystem = new Filesystem(new MemoryAdapter());
43
        $catalogJSON = <<<JSON
44
[
45
    {
46
        "sku": ""
47
    }
48
]
49
JSON;
50
        $filesystem->write($catalogFilePath, $catalogJSON);
51
52
        $catalogFactory = new CatalogFactory($filesystem, $catalogFilePath);
53
54
        // act
55
        $catalogFactory->getCatalog();
56
    }
57
}
58