EntityToolTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 9.6666
1
<?php
2
3
namespace KochTest\Doctrine;
4
5
use Koch\Doctrine\EntityTool;
6
use Koch\Tests\DoctrineTestCase;
7
8
class EntityToolTest extends DoctrineTestCase
9
{
10
    /**
11
     * @var CreateEntity
12
     */
13
    protected $object;
14
15
    public function setUp()
16
    {
17
        parent::setUp();
18
19
        $this->object = new EntityTool($this->entityManager);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Koch\Doctrine\Entit...l($this->entityManager) of type object<Koch\Doctrine\EntityTool> is incompatible with the declared type object<KochTest\Doctrine\CreateEntity> of property $object.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
20
21
        // force Doctrine annotations to be loaded
22
        class_exists('Doctrine\ORM\Mapping\Driver\AnnotationDriver');
23
    }
24
25
    /**
26
     * @covers Koch\Doctrine\EntityTool::createEntity
27
     */
28
    public function testCreateEntity()
29
    {
30
        $data = [
31
            'name'  => 'Ford',
32
            'price' => 15000,
33
        ];
34
35
        $product = $this->object->createEntity(
36
            new \KochTest\Fixtures\Doctrine\Entity\Product(),
37
            $data
38
        );
39
40
        $this->assertEquals($data['name'], $product->getName());
41
        $this->assertEquals($data['price'], $product->getPrice());
42
    }
43
44
    /**
45
     * @expectedException \InvalidArgumentException
46
     * @expectedExceptionMessage Property "category" does not exist on class "KochTest\Fixtures\Doctrine\Entity\Product".
47
     */
48
    public function testCannotAddInvalidProperty()
49
    {
50
        $data = [
51
            'name'     => 'Ford',
52
            'category' => 'Cars',
53
        ];
54
55
        $product = $this->object->createEntity(
0 ignored issues
show
Unused Code introduced by
$product 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...
56
            new \KochTest\Fixtures\Doctrine\Entity\Product(),
57
            $data
58
        );
59
    }
60
}
61