Skip to content

Commit

Permalink
cs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
matej21 committed Mar 14, 2018
1 parent aeddd43 commit 61b5f6b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 51 deletions.
6 changes: 3 additions & 3 deletions src/PresenterAssert.php
Expand Up @@ -12,10 +12,10 @@ class PresenterAssert
use StaticClass;


public static function assertRequestMatch(Request $expected, ?Request $actual, bool $onlyIntersectedParameters = TRUE): void
public static function assertRequestMatch(Request $expected, ?Request $actual, bool $onlyIntersectedParameters = true): void
{
Assert::notSame(NULL, $actual);
assert($actual !== NULL);
Assert::notSame(null, $actual);
assert($actual !== null);
Assert::same($expected->getPresenterName(), $actual->getPresenterName());
$expectedParameters = $expected->getParameters();
$actualParameters = $actual->getParameters();
Expand Down
17 changes: 8 additions & 9 deletions src/PresenterTester.php
Expand Up @@ -50,8 +50,9 @@ public function __construct(
IRouter $router,
IRequest $httpRequest,
User $user,
callable $identityFactory = NULL
) {
callable $identityFactory = null
)
{
$this->session = $session;

$this->presenterFactory = $presenterFactory;
Expand All @@ -75,9 +76,9 @@ public function execute(TestPresenterRequest $testRequest): TestPresenterResult

try {
$response = $presenter->run($applicationRequest);
$badRequestException = NULL;
$badRequestException = null;
} catch (BadRequestException $badRequestException) {
$response = NULL;
$response = null;
}
if ($applicationRequest->getParameter(Presenter::SIGNAL_KEY) && method_exists($presenter, 'isSignalProcessed')) {
if (!$presenter->isSignalProcessed()) {
Expand Down Expand Up @@ -140,7 +141,7 @@ protected function createApplicationRequest(TestPresenterRequest $testRequest):

protected function loginUser(TestPresenterRequest $request): void
{
$this->user->logout(TRUE);
$this->user->logout(true);
$identity = $request->getIdentity();
if (!$identity && $request->shouldHaveIdentity()) {
if (!$this->identityFactory) {
Expand All @@ -164,8 +165,7 @@ protected function setupHttpRequest(TestPresenterRequest $request): void
/** @var Request $this */
if ($request->isAjax()) {
$this->headers['x-requested-with'] = 'XMLHttpRequest';
}
else {
} else {
unset($this->headers['x-requested-with']);
}
$this->post = $request->getPost();
Expand All @@ -177,8 +177,7 @@ protected function setupHttpRequest(TestPresenterRequest $request): void

protected function setupUIPresenter(Presenter $presenter): void
{
$presenter->autoCanonicalize = FALSE;
$presenter->autoCanonicalize = false;
$presenter->invalidLinkMode = Presenter::INVALID_LINK_EXCEPTION;
}

}
22 changes: 11 additions & 11 deletions src/TestPresenterRequest.php
Expand Up @@ -32,13 +32,13 @@ class TestPresenterRequest
private $files = [];

/** @var bool */
private $ajax = FALSE;
private $ajax = false;

/** @var NULL|string */
private $componentClass;

/** @var bool */
private $shouldHaveIdentity = FALSE;
private $shouldHaveIdentity = false;

/** @var IIdentity|NULL */
private $identity;
Expand Down Expand Up @@ -113,19 +113,19 @@ public function getIdentity(): ?IIdentity


/**
* @param string $signal
* @param array $componentParameters
* @param string $signal
* @param array $componentParameters
* @param string|NULL $componentClass required for a secured signal
* @return TestPresenterRequest
*/
public function withSignal(string $signal, array $componentParameters = [], string $componentClass = NULL): TestPresenterRequest
public function withSignal(string $signal, array $componentParameters = [], string $componentClass = null): TestPresenterRequest
{
assert(!isset($this->parameters['do']));
$request = clone $this;
$request->componentClass = $componentClass;
$request->parameters['do'] = $signal;
$lastDashPosition = strrpos($signal, '-');
$componentName = $lastDashPosition !== FALSE ? substr($signal, 0, $lastDashPosition) : '';
$componentName = $lastDashPosition !== false ? substr($signal, 0, $lastDashPosition) : '';

if ($componentClass && class_exists(NextrasSecuredHelpers::class)) {
$csrfToken = NextrasSecuredHelpers::getCsrfToken(
Expand Down Expand Up @@ -162,11 +162,11 @@ public function withMethod(string $methodName): TestPresenterRequest
}


public function withForm(string $formName, array $post, array $files = [], bool $withProtection = TRUE): TestPresenterRequest
public function withForm(string $formName, array $post, array $files = [], bool $withProtection = true): TestPresenterRequest
{
$request = $this->withSignal("$formName-submit");
if ($withProtection) {
$token = 'abcdefghij' . base64_encode(sha1(('mango.token' ^ $this->session->getId()) . 'abcdefghij', TRUE));
$token = 'abcdefghij' . base64_encode(sha1(('mango.token' ^ $this->session->getId()) . 'abcdefghij', true));
$post = $post + ['_token_' => $token];
}
$request->post = $post;
Expand All @@ -176,7 +176,7 @@ public function withForm(string $formName, array $post, array $files = [], bool
}


public function withAjax(bool $enable = TRUE): TestPresenterRequest
public function withAjax(bool $enable = true): TestPresenterRequest
{
$request = clone $this;
$request->ajax = $enable;
Expand Down Expand Up @@ -212,10 +212,10 @@ public function withFiles(array $files): TestPresenterRequest
}


public function withIdentity(IIdentity $identity = NULL): TestPresenterRequest
public function withIdentity(IIdentity $identity = null): TestPresenterRequest
{
$request = clone $this;
$request->shouldHaveIdentity = TRUE;
$request->shouldHaveIdentity = true;
$request->identity = $identity;

return $request;
Expand Down
54 changes: 26 additions & 28 deletions src/TestPresenterResult.php
Expand Up @@ -21,7 +21,6 @@

class TestPresenterResult
{

/** @var IRouter */
private $router;

Expand All @@ -41,7 +40,7 @@ class TestPresenterResult
private $badRequestException;

/** @var bool */
private $responseInspected = FALSE;
private $responseInspected = false;


public function __construct(IRouter $router, Request $request, IPresenter $presenter, ?IResponse $response, ?BadRequestException $badRequestException)
Expand Down Expand Up @@ -77,7 +76,7 @@ public function getUIPresenter(): Presenter
public function getResponse(): IResponse
{
Assert::null($this->badRequestException);
assert($this->response !== NULL);
assert($this->response !== null);
return $this->response;
}

Expand All @@ -104,7 +103,7 @@ public function getTextResponseSource(): string
{
if (!$this->textResponseSource) {
$source = $this->getTextResponse()->getSource();
$this->textResponseSource = is_object($source) ? $source->__toString(TRUE) : (string) $source;
$this->textResponseSource = is_object($source) ? $source->__toString(true) : (string) $source;
Assert::type('string', $this->textResponseSource);
}
return $this->textResponseSource;
Expand All @@ -123,15 +122,14 @@ public function getJsonResponse(): JsonResponse
public function getBadRequestException(): BadRequestException
{
Assert::null($this->response);
assert($this->badRequestException !== NULL);
assert($this->badRequestException !== null);
return $this->badRequestException;
}



public function assertHasResponse(string $type = NULL): self
public function assertHasResponse(string $type = null): self
{
$this->responseInspected = TRUE;
$this->responseInspected = true;
Assert::type($type ?? IResponse::class, $this->response);

return $this;
Expand All @@ -141,15 +139,15 @@ public function assertHasResponse(string $type = NULL): self
/**
* @param string|array|NULL $match
*/
public function assertRenders($match = NULL): self
public function assertRenders($match = null): self
{
$this->responseInspected = TRUE;
$this->responseInspected = true;
if (is_array($match)) {
$match = '%A?%' . implode('%A?%', $match) . '%A?%';
}
assert(is_string($match) || $match === NULL);
assert(is_string($match) || $match === null);
$source = $this->getTextResponseSource();
if ($match !== NULL) {
if ($match !== null) {
Assert::match($match, $source);
}
return $this;
Expand All @@ -165,7 +163,7 @@ public function assertNotRenders($matches): self
$matches = [$matches];
}
assert(is_array($matches));
$this->responseInspected = TRUE;
$this->responseInspected = true;
$source = $this->getTextResponseSource();
foreach ($matches as $match) {
assert(is_string($match));
Expand All @@ -182,9 +180,9 @@ public function assertNotRenders($matches): self
/**
* @param array|object|NULL $expected
*/
public function assertJson($expected = NULL): self
public function assertJson($expected = null): self
{
$this->responseInspected = TRUE;
$this->responseInspected = true;
$response = $this->getJsonResponse();
if (func_num_args() !== 0) {
Assert::equal($expected, $response->getPayload());
Expand All @@ -198,21 +196,21 @@ public function assertJson($expected = NULL): self
*/
public function assertRedirects(string $presenterName, array $parameters = []): self
{
$this->responseInspected = TRUE;
$this->responseInspected = true;
$response = $this->getRedirectResponse();
$url = $response->getUrl();

$httpRequest = new HttpRequest(new UrlScript($url, '/'));
$result = $this->router->match($httpRequest);
PresenterAssert::assertRequestMatch(new Request($presenterName, NULL, $parameters), $result);
PresenterAssert::assertRequestMatch(new Request($presenterName, null, $parameters), $result);

return $this;
}


public function assertRedirectsUrl(string $url): self
{
$this->responseInspected = TRUE;
$this->responseInspected = true;
$response = $this->getRedirectResponse();
Assert::match($url, $response->getUrl());

Expand All @@ -222,13 +220,13 @@ public function assertRedirectsUrl(string $url): self

public function assertFormValid(string $formName): self
{
$this->responseInspected = TRUE;
$this->responseInspected = true;
$presenter = $this->getUIPresenter();
$form = $presenter->getComponent($formName, FALSE);
$form = $presenter->getComponent($formName, false);
Assert::type(Form::class, $form);
assert($form instanceof Form);
if ($form->hasErrors()) {
$controls = $form->getComponents(TRUE, IControl::class);
$controls = $form->getComponents(true, IControl::class);
$errorsStr = [];
foreach ($form->getOwnErrors() as $error) {
$errorsStr[] = "\town error: " . $error;
Expand All @@ -251,9 +249,9 @@ public function assertFormValid(string $formName): self

public function assertFormHasErrors(string $formName, ?array $formErrors = null): self
{
$this->responseInspected = TRUE;
$this->responseInspected = true;
$presenter = $this->getUIPresenter();
$form = $presenter->getComponent($formName, FALSE);
$form = $presenter->getComponent($formName, false);
Assert::type(Form::class, $form);
assert($form instanceof Form);
Assert::true($form->hasErrors());
Expand All @@ -266,17 +264,17 @@ public function assertFormHasErrors(string $formName, ?array $formErrors = null)
}


public function assertBadRequest(int $code = NULL, string $messagePattern = NULL)
public function assertBadRequest(int $code = null, string $messagePattern = null)
{
$this->responseInspected = TRUE;
$this->responseInspected = true;
Assert::type(BadRequestException::class, $this->badRequestException);
assert($this->badRequestException !== NULL);
assert($this->badRequestException !== null);

if ($code !== NULL) {
if ($code !== null) {
Assert::same($code, $this->badRequestException->getHttpCode());
}

if ($messagePattern !== NULL) {
if ($messagePattern !== null) {
Assert::match($messagePattern, $this->badRequestException->getMessage());
}

Expand Down

0 comments on commit 61b5f6b

Please sign in to comment.