'dave@slovocast.com', 'name' => 'Dave SH', 'password' => 'hashed_password' ]); } protected function createNewUserRequest(): Request { $user = $this->getUser(); return $this->createRequest('POST', '/users/register') ->withParsedBody([ 'email' => $user->getEmail(), 'name' => $user->getName(), 'password' => $user->getPassword(), 'checked_password' => $user->getPassword() ]); } public function testSuccessfulRegistration(): void { $user = $this->getUser(); $app = $this->getAppInstance(); /** @var \DI\Container */ $container = $app->getContainer(); $userRepository = $this->prophesize(UserRepositoryInterface::class); $userRepository->save($user)->willReturn(true); $container->set( UserRepositoryInterface::class, $userRepository->reveal() ); $request = $this->createNewUserRequest(); $response = $app->handle($request); $this->assertEquals(200, $response->getStatusCode()); } public function testFailingRegistration(): void { $user = $this->getUser(); $app = $this->getAppInstance(); /** @var $container \DI\Container */ $container = $app->getContainer(); $userRepository = $this->prophesize(UserRepositoryInterface::class); $userRepository->save($user)->willReturn(false); $container->set( UserRepositoryInterface::class, $userRepository->reveal() ); $request = $this->createNewUserRequest(); $response = $app->handle($request); $this->assertEquals(400, $response->getStatusCode()); $flash = $container->get(SessionInterface::class)->getFlash(); $this->assertEquals('Unable to register user.', $flash->get('error')[0]); } }