api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.45k stars 877 forks source link

ApiTestCase: usage with other testing tools (not only PHPUnit) #3130

Closed souhail-5 closed 5 years ago

souhail-5 commented 5 years ago

Hello 🙂,

PHPUnit is mandatory when using ApiTestCase.

What do you think about offering an ApiTestClass (or a Trait) without requiring PHPUnit, something compatible with any testing tool? Maybe something like that: https://github.com/symfony/panther/#usage-with-other-testing-tools

dunglas commented 5 years ago

I'm not sure that it's technically possible to use ApiTestCase without PHPUnit. I mean, the used services can already be used with other testing tools, but the test class itself and the assertions are tight to PHPUnit.

In the link you pointed, PHPunit is still used (LiipFunctionalTestBundle uses PHPUnit under the hood). Extracting the content of ApiTestCase in a trait to be able to use it with LiipFunctionalTestBundle can be interesting however.

souhail-5 commented 5 years ago

That's right, ApiTesCase extends PHPUnit\Framework\TestCase and that's precisely what's too bad :). Of course, my comment has no place if we say that ApiTestCase is a class made only to test under PHPUnit. But in this case, it should be renamed (?); and we should say that it addresses only a limited number of API Platform developers.

In fact, ApiTesCase can get rid of the PHPUnit dependency if it has this (through Dependency Injection principle):

dunglas commented 5 years ago

We already have all of that.

I really don't get what more we can do here. The tools provided by API Platform and used in the PHPUnit integration can be used directly by any other testing framework.

souhail-5 commented 5 years ago

I edited my previous comment.

If we already have all of that, would it be a good idea to make ApiTestCase not extending PHPUnit\Framework\TestCase?

Note that I understand that we can use ApiTestCase, as it is, with any other testing framework. But It's too bad to require PHPUnit while using Behat (without Mink), per example.

teohhanhui commented 5 years ago

If we already have all of that, would it be a good idea to make ApiTestCase not extending PHPUnit\Framework\TestCase?

No, because ApiTestCase is the integration with PHPUnit. :smile:

Note that I understand that we can use ApiTestCase, as it is, with any other testing framework. But It's too bad to require PHPUnit while using Behat (without Mink), per example.

Please do not use ApiTestCase with Behat. :pray: (see point above)

An Assertion Service that implements an Interface (to be defined). It can be ApiTestAssertionsTrait

I'm -1 for this. We don't want to create more abstractions for no benefit.

without relying it on PHPUnit (It can rely on webmozart/assert?)

These assertions are PHPUnit assertions, they have nothing to do with other kinds of assertions such as the webmozart ones. (The only thing in common is that they're both called "assertions".)