| Total Complexity | 19 |
| Total Lines | 142 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | class PersistentObjectTest extends DoctrineTestCase |
||
| 23 | { |
||
| 24 | /** @var TestObjectMetadata */ |
||
| 25 | private $cm; |
||
| 26 | |||
| 27 | /** @var ObjectManager|PHPUnit_Framework_MockObject_MockObject */ |
||
| 28 | private $om; |
||
| 29 | |||
| 30 | /** @var TestObject */ |
||
| 31 | private $object; |
||
| 32 | |||
| 33 | public function setUp() |
||
| 34 | { |
||
| 35 | $this->cm = new TestObjectMetadata(); |
||
| 36 | $this->om = $this->createMock(ObjectManager::class); |
||
| 37 | $this->om->expects($this->any())->method('getClassMetadata') |
||
| 38 | ->will($this->returnValue($this->cm)); |
||
| 39 | $this->object = new TestObject(); |
||
| 40 | PersistentObject::setObjectManager($this->om); |
||
| 41 | $this->object->injectObjectManager($this->om, $this->cm); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function testGetObjectManager() |
||
| 45 | { |
||
| 46 | self::assertSame($this->om, PersistentObject::getObjectManager()); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function testNonMatchingObjectManager() |
||
| 50 | { |
||
| 51 | $this->expectException(RuntimeException::class); |
||
| 52 | $om = $this->createMock(ObjectManager::class); |
||
| 53 | $this->object->injectObjectManager($om, $this->cm); |
||
| 54 | } |
||
| 55 | |||
| 56 | public function testGetField() |
||
| 57 | { |
||
| 58 | self::assertSame('beberlei', $this->object->getName()); |
||
|
1 ignored issue
–
show
|
|||
| 59 | } |
||
| 60 | |||
| 61 | public function testSetField() |
||
| 62 | { |
||
| 63 | $this->object->setName('test'); |
||
|
1 ignored issue
–
show
|
|||
| 64 | self::assertSame('test', $this->object->getName()); |
||
| 65 | } |
||
| 66 | |||
| 67 | public function testGetIdentifier() |
||
| 68 | { |
||
| 69 | self::assertSame(1, $this->object->getId()); |
||
|
1 ignored issue
–
show
|
|||
| 70 | } |
||
| 71 | |||
| 72 | public function testSetIdentifier() |
||
| 73 | { |
||
| 74 | $this->expectException(BadMethodCallException::class); |
||
| 75 | $this->object->setId(2); |
||
|
1 ignored issue
–
show
|
|||
| 76 | } |
||
| 77 | |||
| 78 | public function testSetUnknownField() |
||
| 79 | { |
||
| 80 | $this->expectException(BadMethodCallException::class); |
||
| 81 | $this->object->setUnknown('test'); |
||
|
1 ignored issue
–
show
|
|||
| 82 | } |
||
| 83 | |||
| 84 | public function testGetUnknownField() |
||
| 85 | { |
||
| 86 | $this->expectException(BadMethodCallException::class); |
||
| 87 | $this->object->getUnknown(); |
||
|
1 ignored issue
–
show
|
|||
| 88 | } |
||
| 89 | |||
| 90 | public function testUndefinedMethod() |
||
| 91 | { |
||
| 92 | $this->expectException(BadMethodCallException::class); |
||
| 93 | $this->expectExceptionMessage('There is no method'); |
||
| 94 | (new TestObject())->undefinedMethod(); |
||
|
1 ignored issue
–
show
|
|||
| 95 | } |
||
| 96 | |||
| 97 | public function testGetToOneAssociation() |
||
| 98 | { |
||
| 99 | self::assertNull($this->object->getParent()); |
||
|
1 ignored issue
–
show
|
|||
| 100 | } |
||
| 101 | |||
| 102 | public function testSetToOneAssociation() |
||
| 103 | { |
||
| 104 | $parent = new TestObject(); |
||
| 105 | $this->object->setParent($parent); |
||
|
1 ignored issue
–
show
|
|||
| 106 | self::assertSame($parent, $this->object->getParent($parent)); |
||
| 107 | } |
||
| 108 | |||
| 109 | public function testSetInvalidToOneAssociation() |
||
| 110 | { |
||
| 111 | $parent = new stdClass(); |
||
| 112 | |||
| 113 | $this->expectException(InvalidArgumentException::class); |
||
| 114 | $this->object->setParent($parent); |
||
| 115 | } |
||
| 116 | |||
| 117 | public function testSetToOneAssociationNull() |
||
| 118 | { |
||
| 119 | $parent = new TestObject(); |
||
| 120 | $this->object->setParent($parent); |
||
| 121 | $this->object->setParent(null); |
||
| 122 | self::assertNull($this->object->getParent()); |
||
| 123 | } |
||
| 124 | |||
| 125 | public function testAddToManyAssociation() |
||
| 126 | { |
||
| 127 | $child = new TestObject(); |
||
| 128 | $this->object->addChildren($child); |
||
|
1 ignored issue
–
show
|
|||
| 129 | |||
| 130 | self::assertSame($this->object, $child->getParent()); |
||
| 131 | self::assertSame(1, count($this->object->getChildren())); |
||
|
1 ignored issue
–
show
|
|||
| 132 | |||
| 133 | $child = new TestObject(); |
||
| 134 | $this->object->addChildren($child); |
||
| 135 | |||
| 136 | self::assertSame(2, count($this->object->getChildren())); |
||
| 137 | } |
||
| 138 | |||
| 139 | public function testAddInvalidToManyAssociation() |
||
| 140 | { |
||
| 141 | $this->expectException(InvalidArgumentException::class); |
||
| 142 | $this->object->addChildren(new stdClass()); |
||
| 143 | } |
||
| 144 | |||
| 145 | public function testNoObjectManagerSet() |
||
| 152 | } |
||
| 153 | |||
| 154 | public function testInvalidMethod() |
||
| 155 | { |
||
| 156 | $this->expectException(BadMethodCallException::class); |
||
| 157 | $this->object->asdf(); |
||
|
1 ignored issue
–
show
|
|||
| 158 | } |
||
| 159 | |||
| 160 | public function testAddInvalidCollection() |
||
| 161 | { |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | class TestObject extends PersistentObject |
||
| 168 | { |
||
| 169 | /** @var int */ |
||
| 170 | protected $id = 1; |
||
| 171 | |||
| 172 | /** @var string */ |
||
| 272 |