Download the PHP package speicher210/functional-test-bundle without Composer

On this page you can find all versions of the php package speicher210/functional-test-bundle. 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 functional-test-bundle

Speicher210 Functional Test Bundle

A Symfony bundle with base test cases and helpers for functional testing, focused on REST endpoints.

Requirements

Installation

Enable the bundle in config/bundles.php:

The only configuration option is the base class of the fixture loaders generated by the stub command:

PHPUnit setup

The bundle's bootstrap file boots the kernel once and recreates the database schema for the default entity manager. Include it from your own bootstrap file:

Then register the PHPUnit extensions:

Expected files (snapshots)

Most assertions of the bundle compare the actual output with an expected file in an Expected directory next to the test class. The file name is made of the test method name, the data set name when a data provider is used, and a counter that increases with every assertion in the same test:

Expected files can use any coduo/php-matcher pattern for values that aren't known in advance:

REST responses and arrays are compared as JSON, console output and form errors as text, Twig templates as HTML, and PDFs by text and page images. REST responses and console output without an expected file must be empty, so tests of commands that print nothing don't need one.

Updating expected files

Expected files don't have to be written by hand. While the SnapshotUpdaterExtension is registered, every failing snapshot assertion rewrites its expected file with the actual output. The test still fails that one time; run it again to see it pass, and review the changes in the diff before committing them.

Enable it only when updating snapshots: uncomment it in phpunit.xml.dist (see PHPUnit setup), or register it for a single run:

When updating JSON files, the extension keeps what makes snapshots stable:

To add a new REST snapshot, create the expected file with {} as content (the stub command can do this) and run the test with the extension.

The extension was previously called RestRequestFailTestExpectedOutputFileUpdater. The old name still works, but it is deprecated.

Updating expected files from your own assertions

Your own snapshot assertions can use the same mechanism: catch the ExpectationFailedException, update the file when the updater is enabled, and rethrow the exception.

SnapshotUpdater has a method for each kind of content the assertion compares: JSON, text, XML or binary. The expected file has to exist, even empty, because an assertion on a missing file fails without a comparison failure.

Test cases

Class Use it for
Test\KernelTestCase Anything that needs the kernel: services, Doctrine, fixtures, expected files. All other test cases below build on it.
Test\WebTestCase Requests through the KernelBrowser, response assertions, upload helpers.
Test\RestControllerWebTestCase REST endpoints with JSON snapshots and authentication.
Test\Command\CommandTestCase Console commands, with the output compared to an expected file.
Test\Symfony\Form\FormTypeTestCase Form types: submitted data, or errors compared to an expected file.
Test\Symfony\Validator\ValidatorTestCase Constraint validators, with common tests built in.
Test\Doctrine\DBAL\Types\TypeTestCase Custom Doctrine DBAL types, driven by data providers.
Test\Doctrine\ORM\Query\AST\FunctionTestCase Custom DQL functions, with an in-memory SQLite entity manager.
Test\Twig\TemplateTestCase Twig templates, with the rendered HTML compared to an expected file.
Test\Twig\IntegrationTestCase Twig's own integration tests, without the legacy tests.

All classes are in the Speicher210\FunctionalTestBundle namespace.

Testing REST endpoints

Fixtures

Fixtures are Doctrine fixtures. Extend Test\Loader\AbstractLoader and yield the entities to persist:

Declare the loaders to run before each test with attributes:

Loaders that need services can implement Test\Loader\LoaderAsService. They are then fetched from the container instead of being instantiated. Register them as public services in the test environment, otherwise Symfony removes them from the container as unused.

Other helpers

Trait or class Description
Test\Carbon\CarbonClockSensitiveTestCase Freezes Carbon's clock during each test.
Test\Symfony\Clock\SymfonyClockSensitiveTestCase Freezes the Symfony clock during each test.
Test\Assert\Pdf Compares a PDF's text or page images with expected files. Needs spatie/pdf-to-text, spatie/pdf-to-image and ext-imagick.
Test\Assert\Image Compares two images. Needs ext-imagick. Included in KernelTestCase.
Test\MockObject\AbstractClass Mocks the abstract methods of a class and keeps its concrete methods.
Test\PHPUnitHelper withConsecutive(), a replacement for PHPUnit's removed method. Included in KernelTestCase.
Comparator\MoneyPHP PHPUnit comparator for moneyphp/money. Register it in the bootstrap file.

"No expectations were configured" notices

PHPUnit 12.5 and later report a notice for mock objects without expectations. TypeTestCase and FormTypeTestCase create such mocks for every test. PHPUnit only reads the opt-out attribute from the test class itself or the test method, not from parent classes, so add it to your test classes. The built-in TypeTestCase tests already have it.

Creating test stubs

The bundle provides a command that creates the files of a new test:

The directory must already contain a *Test.php class, which is used to find the namespace. The command creates:

It then prints the #[WithFixture] attribute to add to the test.


All versions of functional-test-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ~8.4.0 || ~8.5.0
ext-dom Version *
ext-json Version *
coduo/php-matcher Version ^6.0.18
dama/doctrine-test-bundle Version ^8.4
doctrine/data-fixtures Version ^2.1.0
doctrine/dbal Version ^3.10.0 || ^4.2.0
doctrine/doctrine-fixtures-bundle Version ^3.7.3 || ^4.3.1
doctrine/orm Version ^2.20.9 || ^3.5.0
php-standard-library/php-standard-library Version ^3.3.0 || ^4.0.0 || ^5.0.0 || ^6.0.0
phpunit/phpunit Version ^12.5.8 || ^13.0
symfony/browser-kit Version ^6.4 || ^7.4 || ^8.0
symfony/css-selector Version ^6.4 || ^7.4 || ^8.0
symfony/dependency-injection Version ^6.4 || ^7.4 || ^8.0
symfony/framework-bundle Version ^6.4 || ^7.4 || ^8.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 speicher210/functional-test-bundle contains the following files

Loading the files please wait ...