Download the PHP package dotdev/api-test-case without Composer

On this page you can find all versions of the php package dotdev/api-test-case. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package api-test-case

ApiTestCase

Build Status Coverage Status

ApiTestCase is a PHPUnit TestCase that will make your life as a Symfony API developer much easier. It extends basic Symfony WebTestCase with some cool features.

Thanks to PHP-Matcher you can, according to its readme, "write expected json responses like a gangster". We definitely agree.

It also uses Alice for easy Doctrine fixtures loading.

Features:

Installation

Assuming you already have Composer installed globally:

And it's done! ApiTestCase is working with the default configuration.

Usage

We provide two base classes for your test cases: JsonApiTestCase and the XmlApiTestCase. Choose one based on the format of the API you want to create.

Json Example

The basic TDD workflow is the following:

  1. Write a test case that sends the request and use assertResponse assertion method to check if response contents are matching your expectations. You need a name for the response file;
  2. Create the file with name that you picked in step 1. and put expected response contents there. It should be put in src/AppBundle/Tests/Responses/Expected/hello_world.json for example.
  3. Make it red.
  4. Make it green.
  5. Refactor.

Let's see a simple example! Write the following test:

Now define the expected response file:

Run your tests:

Your test should fail with some errors, you are probably missing the controller and routing, so go ahead and define them! As soon as you implement your Controller and configure appropriate routing, you can run your tests again:

If the response contents will match our expectations, console will present a simple message:

Otherwise it will present diff of received messages:

Firstly, function assertResponse will check the response code (200 is a default response code), then it will check if header of response contains application/json content type. At the end it will check if the response contents matches the expectation. Sometimes you can't predict some values in the response, for example autogenerated date or id from the database. No magic is needed here because PHP-Matcher comes with a helping hand. These are just a few examples of available patterns:

Check for more on PHP-Matcher's documentation.

With these patterns your expected response will look like this:

With this in place, any string under key message will match the pattern. More complicated expected response could look like this:

And will match the following list of products:

Testing With Database Fixtures

ApiTestCase is integrated with nelmio/alice. Thanks to this nice library you can easily load your fixtures when you need them. You have to define your fixtures and place them in an appropriate directory. Here is some example how to define your fixtures and use case. For more information how to define your fixtures check Alice's documentation.

In order to use Alice with Doctrine, you should enable two additional bundles:

Symfony 4.0+

Symfony 3

Now, let's say you have a mapped Doctrine entity called Book in your application:

To load fixtures for the test, you need to define a simple YAML file in src/AppBundle/Tests/DataFixtures/ORM/books.yml:

Finally, to use these fixtures in a test, just call a proper method:

Configuration Reference

To customize your test suite configuration you can add a few more options to phpunit.xml:

Sample Project

In the test/ directory, you can find sample Symfony project with minimal configuration required to use this library.

Testing

In order to run our PHPUnit tests suite, execute following commands:

Bug Tracking and Suggestions

If you have found a bug or have a great idea for improvement, please open an issue on this repository.

Versioning

Releases will be numbered with the format major.minor.patch.

And constructed with the following guidelines.

For more information on SemVer, please visit semver.org website.

MIT License

License can be found here.

Authors

The library was originally created by:

at Lakion company under https://github.com/Lakion/ApiTestCase repository.

See the list of contributors.


All versions of api-test-case with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
coduo/php-matcher Version ^6.0
doctrine/data-fixtures Version ^1.2
doctrine/doctrine-bundle Version ^1.6|^2.0
doctrine/orm Version ^2.5
nelmio/alice Version ^3.6
phpspec/php-diff Version ^1.1
phpunit/phpunit Version ^7.0|^8.0|^9.0
symfony/browser-kit Version ^4.4|^5.0
symfony/finder Version ^4.4|^5.0
symfony/framework-bundle Version ^4.4|^5.0
theofidry/alice-data-fixtures Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dotdev/api-test-case contains the following files

Loading the files please wait ....