loginController = new LoginController(); } public function testShouldRespondErrorIfAlreadyLoggedIn() { Session::mockInstanceFunction('sessionExists', \Mock::stub()->returns(true)); $this->expectExceptionMessage(ERRORS::SESSION_EXISTS); $this->loginController->handler(); } public function testShouldCreateSessionAndRespondSuccessIfCredentialsAreValid() { Session::mockInstanceFunction('sessionExists', \Mock::stub()->returns(false)); $this->loginController->handler(); $this->assertTrue(!!Session::getInstance()->createSession->hasBeenCalledWithArgs('MOCK_ID', false)); $this->assertTrue(Response::get('respondSuccess')->hasBeenCalledWithArgs(array( 'userId' => 'MOCK_ID', 'userEmail' => 'MOCK_EMAIL', 'staff' => false, 'token' => 'TEST_TOKEN', 'rememberToken' => null ))); } public function testShouldRespondErrorIfCredentialsAreInvalid() { User::setStatics(array( 'authenticate' => \Mock::stub()->returns(new NullDataStore()) )); Controller::$requestReturnMock = ''; $this->expectExceptionMessage(ERRORS::INVALID_CREDENTIALS); $this->loginController->handler(); } }