Completed
Push — master ( 87312f...78171c )
by Alexander
03:21 queued 01:01
created

DiffTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 84
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testDifferenceWithEmpty() 0 9 1
A testDifferenceWithAdditional() 0 16 1
A testDifferenceWithNoProperty() 0 8 1
A testDifference() 0 22 1
A generateFirst() 0 11 1
A generateSecond() 0 10 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: horat1us
5
 * Date: 5/4/17
6
 * Time: 12:10 PM
7
 */
8
9
namespace Horat1us\Tests;
10
11
12
use Horat1us\Examples\Head;
13
use Horat1us\Examples\Person;
14
use Horat1us\XmlConvertibleObject;
15
use SebastianBergmann\PHPLOC\Log\XML;
16
17
class DiffTest extends \PHPUnit_Framework_TestCase
18
{
19
    public function testDifferenceWithEmpty()
20
    {
21
        $first = new Person('Alex', 'Jobs');
22
        $second = new Person('Alex', 'Jobs', [
23
            new XmlConvertibleObject()
24
        ]);
25
        $diff = $first->xmlDiff($second);
26
        $this->assertInstanceOf(get_class($first), $diff);
27
    }
28
29
    public function testDifferenceWithAdditional()
30
    {
31
        $first = new Person('Alex', 'Jobs', [
32
            new XmlConvertibleObject('a'),
33
            new XmlConvertibleObject('b'),
34
        ]);
35
        $second = new Person('Alex', 'Jobs', [
36
            new XmlConvertibleObject('b'),
37
        ]);
38
39
        $diff = $first->xmlDiff($second);
40
        $this->assertInstanceOf(get_class($first), $diff);
41
        $this->assertNotNull($diff->xmlChildren);
0 ignored issues
show
Bug introduced by
Accessing xmlChildren on the interface Horat1us\XmlConvertibleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
42
        $this->assertEquals(1, count($diff->xmlChildren ?? []));
0 ignored issues
show
Bug introduced by
Accessing xmlChildren on the interface Horat1us\XmlConvertibleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
43
        $this->assertEquals('a', $diff->xmlChildren[0]->getXmlElementName());
0 ignored issues
show
Bug introduced by
Accessing xmlChildren on the interface Horat1us\XmlConvertibleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
44
    }
45
46
    public function testDifferenceWithNoProperty()
47
    {
48
        $a = new XmlConvertibleObject('undefined');
49
        $b = new XmlConvertibleObject('undefined');
50
        $a->{'property'} = mt_rand();
51
        $diff = $a->xmlDiff($b);
52
        $this->assertInstanceOf(get_class($a), $diff);
53
    }
54
55
    public function testDifference()
56
    {
57
        $xml = $this->generateFirst();
58
        $compared = $this->generateSecond();
59
60
        $result = $xml->xmlDiff($compared);
61
62
        $this->assertInstanceOf(Person::class, $result);
63
64
        $this->assertNotNull($result->xmlChildren);
0 ignored issues
show
Bug introduced by
Accessing xmlChildren on the interface Horat1us\XmlConvertibleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
65
        $this->assertCount(1, $result->xmlChildren);
0 ignored issues
show
Bug introduced by
Accessing xmlChildren on the interface Horat1us\XmlConvertibleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
66
67
        $this->assertInstanceOf(Head::class, $result->xmlChildren[0]);
0 ignored issues
show
Bug introduced by
Accessing xmlChildren on the interface Horat1us\XmlConvertibleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
68
        $this->assertNotNull($result->xmlChildren[0]->xmlChildren);
0 ignored issues
show
Bug introduced by
Accessing xmlChildren on the interface Horat1us\XmlConvertibleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
69
        $this->assertCount(1, $result->xmlChildren[0]->xmlChildren);
0 ignored issues
show
Bug introduced by
Accessing xmlChildren on the interface Horat1us\XmlConvertibleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
70
71
        $this->assertInstanceOf(
72
            XmlConvertibleObject::class,
73
            $result->xmlChildren[0]->xmlChildren[0]
0 ignored issues
show
Bug introduced by
Accessing xmlChildren on the interface Horat1us\XmlConvertibleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
74
        );
75
        $this->assertNull($result->xmlChildren[0]->xmlChildren[0]->xmlChildren);
0 ignored issues
show
Bug introduced by
Accessing xmlChildren on the interface Horat1us\XmlConvertibleInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
76
    }
77
78
    protected function generateFirst()
79
    {
80
        return new Person("Alex", "Letni", [
81
            new Head("small", 'cool', [
82
                new XmlConvertibleObject('Eye'),
83
                new XmlConvertibleObject('Eye', [
84
                    new Person('Adam', 'Morgan'),
85
                ]),
86
            ])
87
        ]);
88
    }
89
90
    protected function generateSecond()
91
    {
92
        return new Person("Alex", "Letni", [
93
            new Head('small', 'cool', [
94
                new XmlConvertibleObject('Eye', [
95
                    new Person('Adam', 'Morgan'),
96
                ]),
97
            ])
98
        ]);
99
    }
100
}