Skip to content

Create JsonResponse and add response status code assertions#45

Merged
robocoder merged 2 commits intoinstaclick:masterfrom
cabello:patch-2
Dec 20, 2013
Merged

Create JsonResponse and add response status code assertions#45
robocoder merged 2 commits intoinstaclick:masterfrom
cabello:patch-2

Conversation

@cabello
Copy link
Copy Markdown
Contributor

@cabello cabello commented Dec 19, 2013

JsonResponse makes life easier for testing properties, expected use:

$response     = $this->testCase->getClient()->getResponse();
$jsonResponse = new JsonResponse($response);

$this->assertEquals('funny name', $jsonResponse->getProperty('profile.name'));

New assertions for checking response status code to avoid hard coding numbers everywhere.

@robocoder
Copy link
Copy Markdown
Member

phpunit convention is that every assert method can take an optional message parameter.

robocoder added a commit that referenced this pull request Dec 20, 2013
Create JsonResponse and add response status code assertions
@robocoder robocoder merged commit c4688ed into instaclick:master Dec 20, 2013
@cabello cabello deleted the patch-2 branch December 20, 2013 19:16
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no Response typehint on these helper assertions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few reasons, but the main one is: If you look the JsonResponse class, it's actually a composition of a Response object and it would fail the type hint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class JsonResponse extends Response

The type hint should not fail.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JsonResponse is not inheriting Response it's a composition.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about Symfony\Component\HttpFoundation\JsonResponse ?

JsonResponse

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants