-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API] Initial API tests #3701
[API] Initial API tests #3701
Conversation
5602d4c
to
b892ce8
Compare
/** | ||
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com> | ||
*/ | ||
class ShippingCategoryControllerTest extends JsonApiTestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we should name tests like this. The ShippingCategoryController class does not exist and people are used to the fact that there is usually Xyz class and XyzTest. Something that sounds less like a class will be less confusing I hope.
ShippingCategoryApiTest
vs ShippingCategoryControllerTest
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm for ShippingCategoryApiTest
to minimalize confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShippingCategoryApiTest
is fine for me.
Nice work Łukasz! Let's hear more comments. |
$this->assertResponse($response, 'shipping_category/create_validation_fail', 400); | ||
} | ||
|
||
public function testCreateShippingCategoryResponse() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should suffix all methods with Response
. Isn't it enough to call it testCreateShippingCategory
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is: do we test logic or received response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are testing response contents/headers only so I am fine with leaving that suffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO we test logic and we check if it's correct by comparing received responses.
2436168
to
66cc1f6
Compare
@bendavies Thanks for advices! I have to update ApiTestCase README to, to point out these features ;) |
3074947
to
a4c2b96
Compare
</testsuites> | ||
|
||
<php> | ||
<server name="KERNEL_CLASS_PATH" value="/app/TestKernel.php" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing KERNEL_DIR
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ApiTestCase allows you to use Kernel class directly. We need it, because we have two separated Kernels. The problem is with version of ApiTestCase on travis.
a4c2b96
to
ef68913
Compare
9ecf8bd
to
37f385e
Compare
bootstrap="app/bootstrap.php.cache" | ||
> | ||
<testsuites> | ||
<testsuite name="Project Test Suite"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sylius Test Suite
@Arn0d neither WebTestCase nor our Behat with Symfony2Extension (without JS) send a real HTTP request as both of them use |
> | ||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>src/*/*Bundle/Tests</directory> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any directory that matches this pattern? Shouldn't it be src/*/Component/*/Tests
as the component equivalent of the bundle one line below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove this. Components don't have PHPUnit test and won't have them anytime soon I guess.
@pamil I know but it is enough for web case (get and post) when you use put method and you want to update a file, it is another story ;). PHP does not decode HTTP header... I just wanted to warn you but anyway, even if I prefer behat I prefer you test the API with any solution because : |
@Arn0d didn't know about that, thanks! Does it happen only on PUT request, but not on POST ones? Last week I was uploading image in some scenario on while creating taxonomy (POST) and it worked like a charm. |
@@ -7,6 +7,7 @@ sylius_api_shipping_category_index: | |||
defaults: | |||
_controller: sylius.controller.shipping_category:indexAction | |||
_sylius: | |||
serialization_groups: [Default] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed? Isn't Default
a default serialization group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now:
https://github.com/Sylius/SyliusResourceBundle/blob/master/Controller/Configuration.php#L369
I don't know if JMS requires to specify Default explicitly as it won't add it automatically if you pass an empty array - not sure. So I think we should add 'Default' to the Configuration::getSerializationGroups() method which I linked above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be done in a separate PR?
@pamil Just with PUT and PATCH I did not test the latest version of PHP. |
]); | ||
|
||
$response = $this->client->getResponse(); | ||
$this->assertResponse($response, 'shipping_category/create_validation_fail', 400); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use constant for codes? E.g. Response::HTTP_BAD_REQUEST
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Please change the payload formatting according to my sample PR if you agree and update ApiTestCase version. And we are good to go! Good job Łukasz! |
e200cce
to
acf044d
Compare
@lchrusciel Please rebase. :) |
acf044d
to
e7b8b26
Compare
@pjedrzejewski done! I have done a little refactoring also, cuz of changes in ApiTestCase and feature added by @bendavies. |
[API] Initial API tests
Awesome work, thank you Łukasz! 👍 |
$this->client->request('PATCH', '/api/shipping-categories/'.$shippingCategories['shipping_category_1']->getId(), [], [], [ | ||
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', | ||
'CONTENT_TYPE' => 'application/json', | ||
], '{"name": "Light", "description": "Light weight items"}'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to update these to use the format I suggested above.
@lchrusciel Please have a look at my comment above and also... seems like we missed test for delete? /cc @michalmarcinkowski |
I want to introduce initial tests for Sylius API. The previous ApiTestCase was removed from Sylius and after small refactoring and a few improvements we prepared a stand-alone library Lakion ApiTestCase. I added this library to composer and wrote some sample test for Shipping Categories. I want to test all available endpoints so feel free to help me with this task.
Update:
NOTE: Because of depending on PHP to string, which has a class String the tests will fail on PHP7. We are waitng to merge PR which will resolve this issue.
Update2:
NOTE: PHP to string was fixed and it supports PHP7. But because we are still waiting for the official release temporary I added "minimum-stability": "dev" to composer. Do not merge it yet.
Update3:
NOTE: As far as we are good with depending on PHP-Matcher dev explicitly its ready for merge. At the end, ApiTestCase doesn't have a stable version to.