| Conditions | 1 |
| Paths | 1 |
| Total Lines | 124 |
| Code Lines | 120 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); |
||
| 76 | * @large |
||
| 77 | */ |
||
| 78 | public function itLoadsAllTheFixturesWithRandomDataByDefault(): array |
||
| 79 | { |
||
| 80 | $this->helper->setCacheKey(__CLASS__ . '_unmodified'); |
||
| 81 | $fixture = $this->getUnmodifiedFixture(); |
||
| 82 | $this->helper->addFixture($fixture); |
||
| 83 | $this->helper->createDb(); |
||
| 84 | $entityFqn = $this->getCopiedFqn(self::ENTITY_WITHOUT_MODIFIER); |
||
| 85 | $actual = $this->getRepositoryFactory() |
||
| 86 | ->getRepository($entityFqn) |
||
| 87 | ->findAll(); |
||
| 88 | $actualCount = count($actual); |
||
| 89 | self::assertSame($fixture::BULK_AMOUNT_TO_GENERATE, $actualCount); |
||
| 90 | |||
| 91 | return $actual; |
||
| 92 | } |
||
| 93 | |||
| 94 | private function getUnmodifiedFixture(): AbstractEntityFixtureLoader |
||
| 95 | { |
||
| 96 | return $this->getFixture($this->getCopiedFqn(self::ENTITY_WITHOUT_MODIFIER)); |
||
| 97 | } |
||
| 98 | |||
| 99 | private function getFixture( |
||
| 100 | string $entityFqn, |
||
| 101 | ?FixtureEntitiesModifierInterface $modifier = null |
||
| 102 | ): AbstractEntityFixtureLoader { |
||
| 103 | return $this->helper->createFixtureInstanceForEntityFqn($entityFqn, $modifier); |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @test |
||
| 108 | * @large |
||
| 109 | * @depends itLoadsAllTheFixturesWithRandomDataByDefault |
||
| 110 | * |
||
| 111 | * @param array $loadedFirstTime |
||
| 112 | * |
||
| 113 | * @return array |
||
| 114 | * @throws DoctrineStaticMetaException |
||
| 115 | * @throws ReflectionException |
||
| 116 | */ |
||
| 117 | public function itUsesTheCacheTheSecondTime(array $loadedFirstTime): array |
||
| 118 | { |
||
| 119 | $this->getFileSystem() |
||
| 120 | ->mirror( |
||
| 121 | $this->copiedWorkDir . |
||
| 122 | '/../FixturesHelperTest_ItLoadsAllTheFixturesWithRandomDataByDefault_/cache', |
||
| 123 | $this->copiedWorkDir . '/cache' |
||
| 124 | ); |
||
| 125 | $this->helper->setCacheKey(__CLASS__ . '_unmodified'); |
||
| 126 | $fixture = $this->getUnmodifiedFixture(); |
||
| 127 | $this->helper->addFixture($fixture); |
||
| 128 | $this->helper->createDb(); |
||
| 129 | self::assertTrue($this->helper->isLoadedFromCache()); |
||
| 130 | /** |
||
| 131 | * @var EntityInterface[] $loadedSecondTime |
||
| 132 | */ |
||
| 133 | $loadedSecondTime = $this->getRepositoryFactory() |
||
| 134 | ->getRepository($this->getCopiedFqn(self::ENTITY_WITHOUT_MODIFIER)) |
||
| 135 | ->findAll(); |
||
| 136 | $actualCount = count($loadedSecondTime); |
||
| 137 | $expectedCount = count($loadedFirstTime); |
||
| 138 | self::assertSame($expectedCount, $actualCount); |
||
| 139 | $first = $this->getArrayKeyedByUuid($loadedFirstTime); |
||
| 140 | $second = $this->getArrayKeyedByUuid($loadedSecondTime); |
||
| 141 | foreach ($second as $secondId => $actualEntity) { |
||
| 142 | self::assertArrayHasKey($secondId, $first, 'Failed finding UUID ' . $secondId . ' in first Entities'); |
||
| 143 | $expectedEntity = $first[$secondId]; |
||
| 144 | $expectedText = $expectedEntity->getString(); |
||
| 145 | $actualText = $actualEntity->getString(); |
||
| 146 | self::assertEquals($expectedText, $actualText, 'Cached Faker data does not match'); |
||
| 147 | } |
||
| 148 | |||
| 149 | return $loadedSecondTime; |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @param array $entities |
||
| 154 | * |
||
| 155 | * @return EntityInterface[] |
||
| 156 | * @return EntityInterface[] |
||
| 157 | */ |
||
| 158 | private function getArrayKeyedByUuid(array $entities): array |
||
| 159 | { |
||
| 160 | $return = []; |
||
| 161 | foreach ($entities as $entity) { |
||
| 162 | $return[$entity->getId()->toString()] = $entity; |
||
| 163 | } |
||
| 164 | |||
| 165 | return $return; |
||
| 166 | } |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @test |
||
| 170 | * @large |
||
| 171 | * @depends itUsesTheCacheTheSecondTime |
||
| 172 | * |
||
| 173 | * @param array $loadedSecondTime |
||
| 174 | * |
||
| 175 | * @throws DoctrineStaticMetaException |
||
| 176 | * @throws ReflectionException |
||
| 177 | */ |
||
| 178 | public function itCanBeConfiguredNotToLoadFromTheCache(array $loadedSecondTime): void |
||
| 179 | { |
||
| 180 | $this->getFileSystem() |
||
| 181 | ->mirror( |
||
| 182 | $this->copiedWorkDir . |
||
| 183 | '/../FixturesHelperTest_ItUsesTheCacheTheSecondTime_/cache', |
||
| 184 | $this->copiedWorkDir . '/cache' |
||
| 185 | ); |
||
| 186 | $this->helper->setCacheKey(__CLASS__ . '_unmodified'); |
||
| 187 | $fixture = $this->getUnmodifiedFixture(); |
||
| 188 | $this->helper->setLoadFromCache(false); |
||
| 189 | $this->helper->addFixture($fixture); |
||
| 190 | $this->helper->createDb(); |
||
| 191 | self::assertFalse($this->helper->isLoadedFromCache()); |
||
| 192 | /** |
||
| 193 | * @var EntityInterface[] $loadedThirdTime |
||
| 194 | */ |
||
| 195 | $loadedThirdTime = $this->getRepositoryFactory() |
||
| 196 | ->getRepository($this->getCopiedFqn(self::ENTITY_WITHOUT_MODIFIER)) |
||
| 197 | ->findAll(); |
||
| 198 | $actualCount = count($loadedThirdTime); |
||
| 199 | $expectedCount = count($loadedSecondTime); |
||
| 200 | self::assertSame($expectedCount, $actualCount); |
||
| 409 |
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.