Download the PHP package cspray/database-testing-phpunit without Composer

On this page you can find all versions of the php package cspray/database-testing-phpunit. 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 database-testing-phpunit

cspray/database-testing-phpunit

A PHPUnit Extension for cspray/database-testing, designed to facilitate setting up a test database suitable for automated testing.

Installation

Composer is the only supported method for installing this library.

Please note, it is highly likely you'll need a library that provides an implementation of Cspray\DatabaseTesting\ConnectionAdapter\ConnectionAdapter! This library does not come with the adapter appropriate for your database connection!

Review the tests!

If you're here to learn more about how to use cspray/databse-testing in your PHPUnit tests, check out the tests in this library! The phpunit.xml config and the implemented tests provide a working example on how to use it!

Quick Start

The examples below uses a ConnectionAdapter and ConnectionAdapterFactory available from cspray/database-testing-pdo. If PDO is not an appropriate connection for your use case, please replace with the appropriate ConnectionAdapter implementation.

Register your Extension

The first step is to register the extension in your PHPUnit configuration. Ensure the following XML is present in phpunit.xml (or the file you use for you PHPUnit config).

Attribute your TestCase

The next step is to add the #[RequiresTestDatabase] attribute to your PHPUnit TestCase. There's no inheritance or traits required, you don't need to change what TestCase you extend!

Inject the TestDatabase

To work with your test database there is a helper class with the type, Cspray\DatabaseTesting\TestDatabase. This object allows accessing the underlying test database connection, load fixtures, and access the data in a given table.

This object is managed by the extension. It is created when your TestCase has started, before any tests or setup have run. This property MUST BE static, the extension does not have access to the TestCase instance that is running.

Load Fixtures and Run Test

In our example, we're going to load tests both in setUp and as an attribute on a given test. This example is meant to show in what order fixtures get ran, and to show that there are alternatives to loading fixtures if you do not like attributes.

Generally speaking, I would not recommend mixing approaches to loading fixtures. Either use the #[LoadFixture] Attribute, or use TestDatabase helper in your setup or test methods.


All versions of database-testing-phpunit with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
cspray/database-testing Version dev-main
phpunit/phpunit Version ^11
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 cspray/database-testing-phpunit contains the following files

Loading the files please wait ....