CollectionIdentifierUpdaterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 24 1
A testReturnEarlyNoCtMetadata() 0 9 1
A testIgnoreNonCtMappings() 0 19 1
B testSetIdentifierValue() 0 27 1
1
<?php
2
3
namespace Psi\Bridge\ContentType\Tests\Unit\Doctrine\PhpcrOdm;
4
5
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
6
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata as OdmMetadata;
7
use Doctrine\ODM\PHPCR\Mapping\ClassMetadataFactory;
8
use Metadata\MetadataFactoryInterface;
9
use Psi\Bridge\ContentType\Doctrine\PhpcrOdm\CollectionIdentifierUpdater;
10
use Psi\Bridge\ContentType\Doctrine\PhpcrOdm\PropertyEncoder;
11
use Psi\Component\ContentType\Metadata\ClassMetadata;
12
13
class CollectionIdentifierUpdaterTest extends \PHPUnit_Framework_TestCase
14
{
15
    public function setUp()
16
    {
17
        $this->metadataFactory = $this->prophesize(MetadataFactoryInterface::class);
0 ignored issues
show
Bug introduced by
The property metadataFactory does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
        $this->encoder = $this->prophesize(PropertyEncoder::class);
0 ignored issues
show
Bug introduced by
The property encoder does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
20
        $this->updater = new CollectionIdentifierUpdater(
0 ignored issues
show
Bug introduced by
The property updater does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
21
            $this->metadataFactory->reveal(),
22
            $this->encoder->reveal()
23
        );
24
25
        $this->documentManager = $this->prophesize(DocumentManagerInterface::class);
0 ignored issues
show
Bug introduced by
The property documentManager does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
        $this->document = new \stdClass();
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
27
        $this->odmMetadataFactory = $this->prophesize(ClassMetadataFactory::class);
0 ignored issues
show
Bug introduced by
The property odmMetadataFactory does not seem to exist. Did you mean metadataFactory?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
28
        $this->odmMetadata = $this->prophesize(OdmMetadata::class);
0 ignored issues
show
Bug introduced by
The property odmMetadata does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
        $this->ctMetadata = $this->prophesize(ClassMetadata::class);
0 ignored issues
show
Bug introduced by
The property ctMetadata does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
31
        $this->documentManager->getMetadataFactory()->willReturn(
32
            $this->odmMetadataFactory->reveal()
0 ignored issues
show
Bug introduced by
The property odmMetadataFactory does not seem to exist. Did you mean metadataFactory?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
33
        );
34
35
        $this->document = new \stdClass();
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
36
        $this->child1 = new \stdClass();
0 ignored issues
show
Bug introduced by
The property child1 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
        $this->child2 = new \stdClass();
0 ignored issues
show
Bug introduced by
The property child2 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38
    }
39
40
    /**
41
     * It should return early if there is CT system has no metadata.
42
     */
43
    public function testReturnEarlyNoCtMetadata()
44
    {
45
        $this->odmMetadataFactory->getMetadataFor(\stdClass::class)->willReturn(
0 ignored issues
show
Bug introduced by
The property odmMetadataFactory does not seem to exist. Did you mean metadataFactory?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
46
            $this->odmMetadata->reveal()
47
        );
48
        $this->metadataFactory->getMetadataForClass(\stdClass::class)->willReturn(null);
49
        $this->updater->update($this->documentManager->reveal(), $this->document);
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
50
        $this->odmMetadata->getIdentifierValue($this->document)->shouldNotHaveBeenCalled();
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
51
    }
52
53
    /**
54
     * It should ignore children ODM mappings that have no corresponding CT mapping.
55
     */
56
    public function testIgnoreNonCtMappings()
57
    {
58
        $identifier = '/path/to/document';
59
        $this->odmMetadataFactory->getMetadataFor(\stdClass::class)->willReturn(
0 ignored issues
show
Bug introduced by
The property odmMetadataFactory does not seem to exist. Did you mean metadataFactory?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
60
            $this->odmMetadata->reveal()
61
        );
62
        $this->metadataFactory->getMetadataForClass(\stdClass::class)->willReturn($this->ctMetadata->reveal());
63
64
        $this->odmMetadata->getIdentifierValue($this->document)->willReturn($identifier);
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
65
        $this->odmMetadata->childrenMappings = [
66
            'some_collection',
67
        ];
68
69
        $this->odmMetadata->getFieldValue($this->document, 'some_collection')->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
70
        $this->ctMetadata->propertyMetadata = [];
71
72
        $this->updater->update($this->documentManager->reveal(), $this->document);
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
73
        $this->odmMetadata->getFieldValue($this->document, 'some_collection')->shouldNotHaveBeenCalled();
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
74
    }
75
76
    /**
77
     * It should set the identifier value of collection children documents.
78
     */
79
    public function testSetIdentifierValue()
80
    {
81
        $identifier = '/path/to/document';
82
        $this->odmMetadataFactory->getMetadataFor(\stdClass::class)->willReturn(
0 ignored issues
show
Bug introduced by
The property odmMetadataFactory does not seem to exist. Did you mean metadataFactory?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
83
            $this->odmMetadata->reveal()
84
        );
85
        $this->metadataFactory->getMetadataForClass(\stdClass::class)->willReturn($this->ctMetadata->reveal());
86
87
        $this->odmMetadata->getIdentifierValue($this->document)->willReturn($identifier);
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
88
        $this->odmMetadata->childrenMappings = [
89
            'some_collection',
90
        ];
91
        $this->ctMetadata->propertyMetadata = [
92
            'some_collection' => 'something',
93
        ];
94
        $this->odmMetadata->getFieldValue($this->document, 'some_collection')->willReturn([
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
95
            $this->child1,
96
            $this->child2,
97
        ]);
98
99
        $this->encoder->encode('some_collection', 0)->willReturn('some_collection-0');
100
        $this->encoder->encode('some_collection', 1)->willReturn('some_collection-1');
101
        $this->odmMetadata->setIdentifierValue($this->child1, $identifier . '/some_collection-0')->shouldBeCalled();
102
        $this->odmMetadata->setIdentifierValue($this->child2, $identifier . '/some_collection-1')->shouldBeCalled();
103
104
        $this->updater->update($this->documentManager->reveal(), $this->document);
0 ignored issues
show
Bug introduced by
The property document does not seem to exist. Did you mean documentManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
105
    }
106
}
107