Completed
Push — master ( 11b69a...8cf83c )
by André
27:37 queued 12:55
created

ContentTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 48.84 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 21
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetName() 0 10 1
A testObjectProperties() 21 21 4

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 ContentTest 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\Repository\Tests\Values\Content;
10
11
use eZ\Publish\Core\Repository\Values\Content\Content;
12
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
13
use Mockery;
14
use PHPUnit_Framework_TestCase;
15
16
class ContentTest extends PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @covers \eZ\Publish\Core\Repository\Values\Content\Content::getProperties
20
     */
21 View Code Duplication
    public function testObjectProperties()
22
    {
23
        $object = new Content(array('internalFields' => array()));
24
        $properties = $object->attributes();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...lueObject::attributes() has been deprecated with message: Since 5.0, available purely for legacy eZTemplate compatibility

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
25
        self::assertNotContains('internalFields', $properties, 'Internal property found ');
26
        self::assertContains('id', $properties, 'Property not found ');
27
        self::assertContains('fields', $properties, 'Property not found ');
28
        self::assertContains('versionInfo', $properties, 'Property not found ');
29
        self::assertContains('contentInfo', $properties, 'Property not found ');
30
31
        // check for duplicates and double check existence of property
32
        $propertiesHash = array();
33
        foreach ($properties as $property) {
34
            if (isset($propertiesHash[$property])) {
35
                self::fail("Property '{$property}' exists several times in properties list");
36
            } elseif (!isset($object->$property)) {
37
                self::fail("Property '{$property}' does not exist on object, even though it was hinted to be there");
38
            }
39
            $propertiesHash[$property] = 1;
40
        }
41
    }
42
43
    /**
44
     * Test getName method.
45
     *
46
     * @covers \eZ\Publish\Core\Repository\Values\Content\Content::getName
47
     */
48
    public function testGetName()
49
    {
50
        $name = 'Translated name';
51
        $versionInfoMock = Mockery::mock(VersionInfo::class);
52
        $versionInfoMock->shouldReceive('getName')->andReturn($name);
53
54
        $object = new Content(['versionInfo' => $versionInfoMock]);
55
56
        $this->assertEquals($name, $object->getName());
57
    }
58
}
59