Completed
Push — master ( af585b...552f9c )
by André
51:44 queued 37:19
created

ISBNTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 40
rs 10
wmc 3
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testToFieldDefinition() 0 13 1
A providerForTestToFieldDefinition() 8 8 1

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
3
/**
4
 * File containing the ISBNTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content\FieldValue\Converter;
10
11
use eZ\Publish\Core\FieldType\FieldSettings;
12
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\ISBNConverter;
13
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;
14
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition as PersistenceFieldDefinition;
15
use PHPUnit_Framework_TestCase;
16
17
/**
18
 * Test for ISBNConverter in Legacy Storage.
19
 */
20
class ISBNTest extends PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\ISBNConverter
24
     */
25
    protected $converter;
26
27
    protected function setUp()
28
    {
29
        $this->converter = new ISBNConverter();
30
    }
31
32
    /**
33
     * @dataProvider providerForTestToFieldDefinition
34
     *
35
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\ISBNConverter::toFieldDefinition
36
     */
37
    public function testToFieldDefinition($dataInt, $excpectedIsbn13Value)
38
    {
39
        $fieldDef = new PersistenceFieldDefinition();
40
        $storageDefinition = new StorageFieldDefinition([
41
            'dataInt1' => $dataInt,
42
        ]);
43
44
        $this->converter->toFieldDefinition($storageDefinition, $fieldDef);
45
46
        /** @var FieldSettings $fieldSettings */
47
        $fieldSettings = $fieldDef->fieldTypeConstraints->fieldSettings;
48
        self::assertSame($excpectedIsbn13Value, $fieldSettings['isISBN13']);
49
    }
50
51 View Code Duplication
    public function providerForTestToFieldDefinition()
52
    {
53
        return [
54
            [1, true],
55
            [0, false],
56
            [null, false],
57
        ];
58
    }
59
}
60