File: AssociationMappingTest.php

package info (click to toggle)
doctrine 3.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 11,552 kB
  • sloc: php: 108,302; xml: 1,340; makefile: 35; sh: 14
file content (96 lines) | stat: -rw-r--r-- 3,135 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Mapping;

use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use OutOfRangeException;
use PHPUnit\Framework\TestCase;

use function assert;
use function serialize;
use function unserialize;

final class AssociationMappingTest extends TestCase
{
    public function testItSurvivesSerialization(): void
    {
        $mapping = new MyAssociationMapping(
            fieldName: 'foo',
            sourceEntity: self::class,
            targetEntity: self::class,
        );

        $mapping->cascade           = ['persist'];
        $mapping->fetch             = ClassMetadata::FETCH_EAGER;
        $mapping->inherited         = self::class;
        $mapping->declared          = self::class;
        $mapping->cache             = ['usage' => ClassMetadata::CACHE_USAGE_READ_ONLY];
        $mapping->id                = true;
        $mapping->isOnDeleteCascade = true;
        $mapping->originalClass     = self::class;
        $mapping->originalField     = 'foo';
        $mapping->orphanRemoval     = true;
        $mapping->unique            = true;

        $resurrectedMapping = unserialize(serialize($mapping));
        assert($resurrectedMapping instanceof AssociationMapping);

        self::assertSame(['persist'], $resurrectedMapping->cascade);
        self::assertSame(ClassMetadata::FETCH_EAGER, $resurrectedMapping->fetch);
        self::assertSame(self::class, $resurrectedMapping->inherited);
        self::assertSame(self::class, $resurrectedMapping->declared);
        self::assertSame(['usage' => ClassMetadata::CACHE_USAGE_READ_ONLY], $resurrectedMapping->cache);
        self::assertTrue($resurrectedMapping->id);
        self::assertTrue($resurrectedMapping->isOnDeleteCascade);
        self::assertSame(self::class, $resurrectedMapping->originalClass);
        self::assertSame('foo', $resurrectedMapping->originalField);
        self::assertTrue($resurrectedMapping->orphanRemoval);
        self::assertTrue($resurrectedMapping->unique);
    }

    public function testItThrowsWhenAccessingUnknownProperty(): void
    {
        $mapping = new MyAssociationMapping(
            fieldName: 'foo',
            sourceEntity: self::class,
            targetEntity: self::class,
        );

        $this->expectException(OutOfRangeException::class);

        $mapping['foo'];
    }

    public function testItThrowsWhenSettingUnknownProperty(): void
    {
        $mapping = new MyAssociationMapping(
            fieldName: 'foo',
            sourceEntity: self::class,
            targetEntity: self::class,
        );

        $this->expectException(OutOfRangeException::class);

        $mapping['foo'] = 'bar';
    }

    public function testItThrowsWhenUnsettingUnknownProperty(): void
    {
        $mapping = new MyAssociationMapping(
            fieldName: 'foo',
            sourceEntity: self::class,
            targetEntity: self::class,
        );

        $this->expectException(OutOfRangeException::class);

        unset($mapping['foo']);
    }
}

class MyAssociationMapping extends AssociationMapping
{
}