| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 28 | public function testSetupGameFromDatabase(): void |
||
| 29 | { |
||
| 30 | // Mock the manager |
||
| 31 | $objectManager = $this->createMock(ObjectManager::class); |
||
| 32 | |||
| 33 | // Set up the mock to return sample data from repositories |
||
| 34 | $objectManager->method('getRepository')->willReturnMap([ |
||
| 35 | [LocationEntity::class, $this->getLocationRepositoryMock()], |
||
| 36 | [ItemEntity::class, $this->getItemRepositoryMock()], |
||
| 37 | [Action::class, $this->getActionRepositoryMock()], |
||
| 38 | [Response::class, $this->getResponseRepositoryMock()], |
||
| 39 | [Connection::class, $this->getConnectionRepositoryMock()], |
||
| 40 | ]); |
||
| 41 | |||
| 42 | // Create an instance of GameSetupManager with the mock manager |
||
| 43 | $gameSetupManager = new GameSetupManager($objectManager); |
||
| 44 | |||
| 45 | // Configure game object |
||
| 46 | $game = $gameSetupManager->setupGameFromDatabase(); |
||
| 47 | |||
| 48 | // Assert that the returned object is a Game instance |
||
| 49 | $this->assertInstanceOf(Game::class, $game); |
||
| 50 | |||
| 51 | // Perform additional assertion to check if the game object is configured as expected |
||
| 52 | $forrest = $game->getCurrentLocation(); |
||
| 53 | $this->assertInstanceOf(Location::class, $forrest); |
||
| 54 | $this->assertSame('Forrest', $forrest->getName()); |
||
| 55 | |||
| 56 | $this->assertTrue($forrest->hasConnection('north')); // To the Cave |
||
| 57 | $this->assertFalse($forrest->hasConnection('south')); // No connection |
||
| 58 | $this->assertInstanceOf(Location::class, $forrest->getConnectedLocation('north')); |
||
| 59 | $this->assertNull($forrest->getConnectedLocation('south')); |
||
| 60 | |||
| 61 | $cave = $forrest->getConnectedLocation('north'); |
||
| 62 | $this->assertSame('Cave', $cave->getName()); |
||
| 63 | |||
| 64 | $this->assertTrue($cave->hasItem('Axe')); |
||
| 65 | $this->assertFalse($cave->hasItem('Sword')); |
||
| 66 | $this->assertNull($cave->getItem('Sword')); |
||
| 67 | |||
| 68 | /** @var Item */ |
||
| 69 | $axe = $cave->getItem('Axe'); |
||
| 70 | |||
| 71 | $this->assertSame('Axe', $axe->getName()); |
||
| 72 | $this->assertTrue($axe->hasAction('take')); |
||
| 73 | |||
| 74 | $examineAxe = $axe->getAction('examine'); |
||
| 75 | $this->assertInstanceOf(ExamineAction::class, $examineAxe); |
||
| 76 | $this->assertNull($examineAxe->getRequiredLocation()); |
||
| 77 | $this->assertNull($examineAxe->getLocationResponse()); |
||
| 78 | |||
| 79 | $useAxe = $axe->getAction('use'); |
||
| 80 | $this->assertInstanceOf(UseAction::class, $useAxe); |
||
| 81 | $this->assertSame($forrest, $useAxe->getRequiredLocation()); |
||
| 82 | $this->assertInstanceOf(SwapLocationResponse::class, $useAxe->getLocationResponse()); |
||
| 83 | } |
||
| 249 |