ValueObjectTest::testEquals()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Wambo\Core\ValueObject;
4
5
use PHPUnit\Framework\TestCase;
6
use Wambo\Core\ValueObject\Exception\ValueObjectException;
7
8
/**
9
 * Class ValueObjectTest
10
 * @package Wambo\Core\ValueObject
11
 */
12
class ValueObjectTest extends TestCase
13
{
14
    public function testConstructor()
15
    {
16
        new ValueObjectImpl('a');
17
    }
18
19
    /**
20
     * test Immutable Class can´t use __constructor again
21
     *
22
     * @test
23
     * @expectedException \Wambo\Core\Immutable\Exception\ImmutableException
24
     */
25
    public function testConstructor_asFunction()
26
    {
27
        // arrange
28
        $obj = new ValueObjectImpl('a');
29
30
        // act
31
        $obj->__construct('b');
32
    }
33
34
    /**
35
     * @test
36
     * @expectedException \Wambo\Core\Immutable\Exception\ImmutableException
37
     */
38
    public function testMagicSetMethod()
39
    {
40
        // arrange
41
        $obj = new ValueObjectImpl('a');
42
43
        // act
44
        $obj->__set('test', 'test value');
45
    }
46
47
    /**
48
     * @test
49
     * @expectedException \Wambo\Core\ValueObject\Exception\ValueObjectException
50
     */
51
    public function testClone()
52
    {
53
        // arrange
54
        $obj = new ValueObjectImpl('a');
55
56
        $objB = clone $obj;
0 ignored issues
show
Unused Code introduced by
$objB is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
    }
58
59
    public function testEquals()
60
    {
61
        // arrange
62
        $obj_a = new ValueObjectImpl('a');
63
        $obj_b = new ValueObjectImpl('a');
64
65
        // act
66
        $isEquals_func = $obj_a->equals($obj_b);
67
        $isEquals_doubleOperator = $obj_a == $obj_b;
68
69
        // assert
70
        $this->assertTrue($isEquals_func);
71
        $this->assertTrue($isEquals_doubleOperator);
72
    }
73
}