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

Created on 1 Oct 2019  路  5Comments  路  Source: api-platform/core

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

question

All 5 comments

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.

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):

  • [x] An HTTP Client that implements HttpClientInterface ; example: Symfony HttpClient Component
  • [x] A "Kernel HTTP Client" (not real HTTP requests) that implements HttpClientInterface ; I think it doesn't exist inside Symfony (currently). (EDIT: but it exists inside API Platform)
  • [x] An Assertion Service that implements an Interface (to be defined). It can be ApiTestAssertionsTrait without relying it on PHPUnit (It can rely on webmozart/assert?) Of course this Assertion Service needs to be tight to HttpClientInterface.

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.

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.

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".)

Was this page helpful?
0 / 5 - 0 ratings