/** * testIsSuccess * * @covers \RcmUser\User\Result::isSuccess * * @return void */ public function testIsSuccess() { $result = new Result(); $user = new User(); $result->setCode(Result::CODE_SUCCESS); $result->setUser($user); $this->assertTrue($result->isSuccess(), 'Success not returned.'); $result->setCode(Result::CODE_FAIL); $this->assertFalse($result->isSuccess(), 'Success returned.'); }
/** * createUser * * @param User $requestUser requestUser * * @return Result */ public function createUser(User $requestUser) { /* <LOW_LEVEL_PREP> */ /* REMOVE SOME LOW LEVEL - LET THE MAPPER DECIDE $result = $this->readUser($requestUser); if ($result->isSuccess()) { // ERROR - user exists return new Result(null, Result::CODE_FAIL, 'User already exists.'); } */ $responseUser = new User(); $responseUser->populate($requestUser); $requestUser = new ReadOnlyUser($requestUser); $state = $responseUser->getState(); if (empty($state)) { $responseUser->setState($this->getDefaultUserState()); } /* </LOW_LEVEL_PREP> */ /* @event beforeCreateUser */ $results = $this->getEventManager()->trigger('beforeCreateUser', $this, ['requestUser' => $requestUser, 'responseUser' => $responseUser], function ($result) { return !$result->isSuccess(); }); if ($results->stopped()) { return $results->last(); } /* @event createUser */ $results = $this->getEventManager()->trigger('createUser', $this, ['requestUser' => $requestUser, 'responseUser' => $responseUser], function ($result) { return !$result->isSuccess(); }); if ($results->stopped()) { $result = $results->last(); $this->getEventManager()->trigger('createUserFail', $this, ['result' => $result]); return $result; } $result = new Result($responseUser); if (!$result->isSuccess()) { $this->getEventManager()->trigger('createUserFail', $this, ['result' => $result]); return $result; } /* @event createUserSuccess */ $this->getEventManager()->trigger('createUserSuccess', $this, ['result' => $result]); return $result; }