em = self::getContainer()->get(EntityManagerInterface::class); $this->em->getConnection()->beginTransaction(); $this->command = new CommandTester((new Application(self::$kernel))->find('app:user:lock')); } protected function tearDown(): void { $this->em->getConnection()->rollBack(); parent::tearDown(); } public function testAnAccountIsLockedWithItsReason(): void { $user = $this->user(); $this->command->execute(['email' => 'anna@ep-reisen.de', 'reason' => 'Auf eigenen Wunsch']); $this->command->assertCommandIsSuccessful(); self::assertTrue($user->isDisabled()); self::assertSame('Auf eigenen Wunsch', $user->getDisabledReason()); } public function testTheLockIsReleasedAgain(): void { $user = $this->user(); $user->disable('Auf eigenen Wunsch'); $this->em->flush(); $this->command->execute(['email' => 'anna@ep-reisen.de', '--release' => true]); $this->command->assertCommandIsSuccessful(); self::assertFalse($user->isDisabled()); self::assertNull($user->getDisabledReason()); } /** * Addresses are stored normalised, so a differently cased argument has to find the row * rather than report that there is none. */ public function testTheAddressIsMatchedTheWayALoginMatchesIt(): void { $user = $this->user(); $this->command->execute(['email' => ' Anna@EP-Reisen.de ']); $this->command->assertCommandIsSuccessful(); self::assertTrue($user->isDisabled()); } public function testAnUnknownAddressFails(): void { self::assertSame(1, $this->command->execute(['email' => 'niemand@ep-reisen.de'])); self::assertStringContainsString('No account', $this->command->getDisplay()); } private function user(): User { $user = new User('anna@ep-reisen.de', 'Anna'); $user->setRoles(['ROLE_EMPLOYEE']); $this->em->persist($user); $this->em->flush(); return $user; } }