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 |
||
| 33 | class DefaultCacheFactoryTest extends OrmTestCase |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * @var \Doctrine\ORM\Cache\CacheFactory |
||
| 37 | */ |
||
| 38 | private $factory; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var \Doctrine\ORM\EntityManager |
||
| 42 | */ |
||
| 43 | private $em; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var \Doctrine\ORM\Cache\RegionsConfiguration |
||
| 47 | */ |
||
| 48 | private $regionsConfig; |
||
| 49 | |||
| 50 | protected function setUp() |
||
| 63 | |||
| 64 | public function testImplementsCacheFactory() |
||
| 68 | |||
| 69 | View Code Duplication | public function testBuildCachedEntityPersisterReadOnly() |
|
| 70 | { |
||
| 71 | $em = $this->em; |
||
| 72 | $metadata = clone $em->getClassMetadata(State::class); |
||
| 73 | $persister = new BasicEntityPersister($em, $metadata); |
||
| 74 | $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); |
||
| 75 | |||
| 76 | $metadata->cache['usage'] = ClassMetadata::CACHE_USAGE_READ_ONLY; |
||
| 77 | |||
| 78 | $this->factory->expects($this->once()) |
||
|
|
|||
| 79 | ->method('getRegion') |
||
| 80 | ->with($this->equalTo($metadata->cache)) |
||
| 81 | ->will($this->returnValue($region)); |
||
| 82 | |||
| 83 | $cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata); |
||
| 84 | |||
| 85 | $this->assertInstanceOf(CachedEntityPersister::class, $cachedPersister); |
||
| 86 | $this->assertInstanceOf(ReadOnlyCachedEntityPersister::class, $cachedPersister); |
||
| 87 | } |
||
| 88 | |||
| 89 | View Code Duplication | public function testBuildCachedEntityPersisterReadWrite() |
|
| 90 | { |
||
| 91 | $em = $this->em; |
||
| 92 | $metadata = clone $em->getClassMetadata(State::class); |
||
| 93 | $persister = new BasicEntityPersister($em, $metadata); |
||
| 94 | $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); |
||
| 95 | |||
| 96 | $metadata->cache['usage'] = ClassMetadata::CACHE_USAGE_READ_WRITE; |
||
| 97 | |||
| 98 | $this->factory->expects($this->once()) |
||
| 99 | ->method('getRegion') |
||
| 100 | ->with($this->equalTo($metadata->cache)) |
||
| 101 | ->will($this->returnValue($region)); |
||
| 102 | |||
| 103 | $cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata); |
||
| 104 | |||
| 105 | $this->assertInstanceOf(CachedEntityPersister::class, $cachedPersister); |
||
| 106 | $this->assertInstanceOf(ReadWriteCachedEntityPersister::class, $cachedPersister); |
||
| 107 | } |
||
| 108 | |||
| 109 | View Code Duplication | public function testBuildCachedEntityPersisterNonStrictReadWrite() |
|
| 110 | { |
||
| 111 | $em = $this->em; |
||
| 112 | $metadata = clone $em->getClassMetadata(State::class); |
||
| 113 | $persister = new BasicEntityPersister($em, $metadata); |
||
| 114 | $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); |
||
| 115 | |||
| 116 | $metadata->cache['usage'] = ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE; |
||
| 117 | |||
| 118 | $this->factory->expects($this->once()) |
||
| 119 | ->method('getRegion') |
||
| 120 | ->with($this->equalTo($metadata->cache)) |
||
| 121 | ->will($this->returnValue($region)); |
||
| 122 | |||
| 123 | $cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata); |
||
| 124 | |||
| 125 | $this->assertInstanceOf(CachedEntityPersister::class, $cachedPersister); |
||
| 126 | $this->assertInstanceOf(NonStrictReadWriteCachedEntityPersister::class, $cachedPersister); |
||
| 127 | } |
||
| 128 | |||
| 129 | View Code Duplication | public function testBuildCachedCollectionPersisterReadOnly() |
|
| 130 | { |
||
| 131 | $em = $this->em; |
||
| 132 | $metadata = $em->getClassMetadata(State::class); |
||
| 133 | $mapping = $metadata->associationMappings['cities']; |
||
| 134 | $persister = new OneToManyPersister($em); |
||
| 135 | $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); |
||
| 136 | |||
| 137 | $mapping['cache']['usage'] = ClassMetadata::CACHE_USAGE_READ_ONLY; |
||
| 138 | |||
| 139 | $this->factory->expects($this->once()) |
||
| 140 | ->method('getRegion') |
||
| 141 | ->with($this->equalTo($mapping['cache'])) |
||
| 142 | ->will($this->returnValue($region)); |
||
| 143 | |||
| 144 | |||
| 145 | $cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping); |
||
| 146 | |||
| 147 | $this->assertInstanceOf(CachedCollectionPersister::class, $cachedPersister); |
||
| 148 | $this->assertInstanceOf(ReadOnlyCachedCollectionPersister::class, $cachedPersister); |
||
| 149 | } |
||
| 150 | |||
| 151 | View Code Duplication | public function testBuildCachedCollectionPersisterReadWrite() |
|
| 152 | { |
||
| 153 | $em = $this->em; |
||
| 154 | $metadata = $em->getClassMetadata(State::class); |
||
| 155 | $mapping = $metadata->associationMappings['cities']; |
||
| 156 | $persister = new OneToManyPersister($em); |
||
| 157 | $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); |
||
| 158 | |||
| 159 | $mapping['cache']['usage'] = ClassMetadata::CACHE_USAGE_READ_WRITE; |
||
| 160 | |||
| 161 | $this->factory->expects($this->once()) |
||
| 162 | ->method('getRegion') |
||
| 163 | ->with($this->equalTo($mapping['cache'])) |
||
| 164 | ->will($this->returnValue($region)); |
||
| 165 | |||
| 166 | $cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping); |
||
| 167 | |||
| 168 | $this->assertInstanceOf(CachedCollectionPersister::class, $cachedPersister); |
||
| 169 | $this->assertInstanceOf(ReadWriteCachedCollectionPersister::class, $cachedPersister); |
||
| 170 | } |
||
| 171 | |||
| 172 | View Code Duplication | public function testBuildCachedCollectionPersisterNonStrictReadWrite() |
|
| 173 | { |
||
| 174 | $em = $this->em; |
||
| 175 | $metadata = $em->getClassMetadata(State::class); |
||
| 176 | $mapping = $metadata->associationMappings['cities']; |
||
| 177 | $persister = new OneToManyPersister($em); |
||
| 178 | $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); |
||
| 179 | |||
| 180 | $mapping['cache']['usage'] = ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE; |
||
| 181 | |||
| 182 | $this->factory->expects($this->once()) |
||
| 183 | ->method('getRegion') |
||
| 184 | ->with($this->equalTo($mapping['cache'])) |
||
| 185 | ->will($this->returnValue($region)); |
||
| 186 | |||
| 187 | $cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping); |
||
| 188 | |||
| 189 | $this->assertInstanceOf(CachedCollectionPersister::class, $cachedPersister); |
||
| 190 | $this->assertInstanceOf(NonStrictReadWriteCachedCollectionPersister::class, $cachedPersister); |
||
| 191 | } |
||
| 192 | |||
| 193 | View Code Duplication | public function testInheritedEntityCacheRegion() |
|
| 211 | |||
| 212 | View Code Duplication | public function testCreateNewCacheDriver() |
|
| 230 | |||
| 231 | public function testBuildCachedEntityPersisterNonStrictException() |
||
| 232 | { |
||
| 233 | $em = $this->em; |
||
| 234 | $metadata = clone $em->getClassMetadata(State::class); |
||
| 235 | $persister = new BasicEntityPersister($em, $metadata); |
||
| 236 | |||
| 244 | |||
| 245 | public function testBuildCachedCollectionPersisterException() |
||
| 259 | |||
| 260 | View Code Duplication | public function testInvalidFileLockRegionDirectoryException() |
|
| 278 | |||
| 279 | View Code Duplication | public function testInvalidFileLockRegionDirectoryExceptionWithEmptyString() |
|
| 299 | |||
| 300 | public function testBuildsNewNamespacedCacheInstancePerRegionInstance() |
||
| 320 | |||
| 321 | public function testInvalidNamespaceVersionCacheEntry() |
||
| 334 | |||
| 335 | public function testAppendsNamespacedCacheInstancePerRegionInstanceWhenItsAlreadySet() |
||
| 358 | |||
| 359 | View Code Duplication | public function testBuildsDefaultCacheRegionFromGenericCacheRegion() |
|
| 376 | |||
| 377 | View Code Duplication | public function testBuildsMultiGetCacheRegionFromGenericCacheRegion() |
|
| 394 | |||
| 395 | } |
||
| 396 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.