| Total Complexity | 12 |
| Total Lines | 292 |
| Duplicated Lines | 84.25 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 20 | class ReadWriteCachedCollectionPersisterTest extends AbstractCollectionPersisterTest |
||
| 21 | { |
||
| 22 | protected $regionMockMethods = [ |
||
| 23 | 'getName', |
||
| 24 | 'contains', |
||
| 25 | 'get', |
||
| 26 | 'getMultiple', |
||
| 27 | 'put', |
||
| 28 | 'evict', |
||
| 29 | 'evictAll', |
||
| 30 | 'lock', |
||
| 31 | 'unlock', |
||
| 32 | ]; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritdoc} |
||
| 36 | */ |
||
| 37 | protected function createPersister( |
||
| 38 | EntityManagerInterface $em, |
||
| 39 | CollectionPersister $persister, |
||
| 40 | Region $region, |
||
| 41 | AssociationMetadata $association |
||
| 42 | ) |
||
| 43 | { |
||
| 44 | return new ReadWriteCachedCollectionPersister($persister, $region, $em, $association); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return \Doctrine\ORM\Cache\Region |
||
| 49 | */ |
||
| 50 | protected function createRegion() |
||
| 55 | } |
||
| 56 | |||
| 57 | View Code Duplication | public function testDeleteShouldLockItem() |
|
| 58 | { |
||
| 59 | $entity = new State("Foo"); |
||
| 60 | $lock = Lock::createLockRead(); |
||
| 61 | $persister = $this->createPersisterDefault(); |
||
| 62 | $collection = $this->createCollection($entity); |
||
| 63 | $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); |
||
| 64 | |||
| 65 | $this->region->expects($this->once()) |
||
|
1 ignored issue
–
show
|
|||
| 66 | ->method('lock') |
||
| 67 | ->with($this->equalTo($key)) |
||
| 68 | ->will($this->returnValue($lock)); |
||
| 69 | |||
| 70 | $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); |
||
| 71 | |||
| 72 | $persister->delete($collection); |
||
| 73 | } |
||
| 74 | |||
| 75 | View Code Duplication | public function testUpdateShouldLockItem() |
|
| 91 | } |
||
| 92 | |||
| 93 | View Code Duplication | public function testUpdateTransactionRollBackShouldEvictItem() |
|
| 94 | { |
||
| 95 | $entity = new State("Foo"); |
||
| 96 | $lock = Lock::createLockRead(); |
||
| 97 | $persister = $this->createPersisterDefault(); |
||
| 98 | $collection = $this->createCollection($entity); |
||
| 99 | $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); |
||
| 100 | |||
| 101 | $this->region->expects($this->once()) |
||
| 102 | ->method('lock') |
||
| 103 | ->with($this->equalTo($key)) |
||
| 104 | ->will($this->returnValue($lock)); |
||
| 105 | |||
| 106 | $this->region->expects($this->once()) |
||
| 107 | ->method('evict') |
||
| 108 | ->with($this->equalTo($key)) |
||
| 109 | ->will($this->returnValue($lock)); |
||
| 110 | |||
| 111 | $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); |
||
| 112 | |||
| 113 | $persister->update($collection); |
||
| 114 | $persister->afterTransactionRolledBack(); |
||
| 115 | } |
||
| 116 | |||
| 117 | View Code Duplication | public function testDeleteTransactionRollBackShouldEvictItem() |
|
| 118 | { |
||
| 119 | $entity = new State("Foo"); |
||
| 120 | $lock = Lock::createLockRead(); |
||
| 121 | $persister = $this->createPersisterDefault(); |
||
| 122 | $collection = $this->createCollection($entity); |
||
| 123 | $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); |
||
| 124 | |||
| 125 | $this->region->expects($this->once()) |
||
| 126 | ->method('lock') |
||
| 127 | ->with($this->equalTo($key)) |
||
| 128 | ->will($this->returnValue($lock)); |
||
| 129 | |||
| 130 | $this->region->expects($this->once()) |
||
| 131 | ->method('evict') |
||
| 132 | ->with($this->equalTo($key)); |
||
| 133 | |||
| 134 | $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); |
||
| 135 | |||
| 136 | $persister->delete($collection); |
||
| 137 | $persister->afterTransactionRolledBack(); |
||
| 138 | } |
||
| 139 | |||
| 140 | View Code Duplication | public function testTransactionRollBackDeleteShouldClearQueue() |
|
| 141 | { |
||
| 142 | $entity = new State("Foo"); |
||
| 143 | $lock = Lock::createLockRead(); |
||
| 144 | $persister = $this->createPersisterDefault(); |
||
| 145 | $collection = $this->createCollection($entity); |
||
| 146 | $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); |
||
| 147 | $property = new \ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache'); |
||
| 148 | |||
| 149 | $property->setAccessible(true); |
||
| 150 | |||
| 151 | $this->region->expects($this->once()) |
||
| 152 | ->method('lock') |
||
| 153 | ->with($this->equalTo($key)) |
||
| 154 | ->will($this->returnValue($lock)); |
||
| 155 | |||
| 156 | $this->region->expects($this->once()) |
||
| 157 | ->method('evict') |
||
| 158 | ->with($this->equalTo($key)); |
||
| 159 | |||
| 160 | $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); |
||
| 161 | |||
| 162 | $persister->delete($collection); |
||
| 163 | |||
| 164 | self::assertCount(1, $property->getValue($persister)); |
||
| 165 | |||
| 166 | $persister->afterTransactionRolledBack(); |
||
| 167 | |||
| 168 | self::assertCount(0, $property->getValue($persister)); |
||
| 169 | } |
||
| 170 | |||
| 171 | View Code Duplication | public function testTransactionRollBackUpdateShouldClearQueue() |
|
| 200 | } |
||
| 201 | |||
| 202 | View Code Duplication | public function testTransactionRollCommitDeleteShouldClearQueue() |
|
| 203 | { |
||
| 204 | $entity = new State("Foo"); |
||
| 205 | $lock = Lock::createLockRead(); |
||
| 206 | $persister = $this->createPersisterDefault(); |
||
| 207 | $collection = $this->createCollection($entity); |
||
| 208 | $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); |
||
| 209 | $property = new \ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache'); |
||
| 210 | |||
| 211 | $property->setAccessible(true); |
||
| 212 | |||
| 213 | $this->region->expects($this->once()) |
||
| 214 | ->method('lock') |
||
| 215 | ->with($this->equalTo($key)) |
||
| 216 | ->will($this->returnValue($lock)); |
||
| 217 | |||
| 218 | $this->region->expects($this->once()) |
||
| 219 | ->method('evict') |
||
| 220 | ->with($this->equalTo($key)); |
||
| 221 | |||
| 222 | $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); |
||
| 223 | |||
| 224 | $persister->delete($collection); |
||
| 225 | |||
| 226 | self::assertCount(1, $property->getValue($persister)); |
||
| 227 | |||
| 228 | $persister->afterTransactionComplete(); |
||
| 229 | |||
| 230 | self::assertCount(0, $property->getValue($persister)); |
||
| 231 | } |
||
| 232 | |||
| 233 | View Code Duplication | public function testTransactionRollCommitUpdateShouldClearQueue() |
|
| 262 | } |
||
| 263 | |||
| 264 | View Code Duplication | public function testDeleteLockFailureShouldIgnoreQueue() |
|
| 287 | } |
||
| 288 | |||
| 289 | View Code Duplication | public function testUpdateLockFailureShouldIgnoreQueue() |
|
| 312 | } |
||
| 313 | } |
||
| 314 |