Download the PHP package ben-rowan/doctrine-assert without Composer

On this page you can find all versions of the php package ben-rowan/doctrine-assert. 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 doctrine-assert

doctrine-assert

A set of PHPUnit database assertions for your Doctrine entities.

Install

Usage

Trait

To add doctrine-assert to your tests you simply use the provided trait in your test class:

And implement a getEntityManager(): EntityManager method which allows the trait to access your tests entity manager.

You now have access to the following assertions.

Assertions

All the database assertions require a root entity and a query config. The query config defines a number of joins taken from the root entity (zero or more) before then defining values for us to assert against.

For example:

Here we can see that we're joining AnotherEntity::class to SomeEntity:class, then YetAnotherEntity::class to AnotherEntity::class before asserting that the value of active on YetAnotherEntity::class is true in one or more cases.

We can continue this nesting and joining as much as we need too including adding more than one join per entity.

Using this we can quickly and easily build up complex assertions against the current database state.

Database Has

Assert that the database has one or more entities that match the provided query config.

Database Missing

Assert that the database has zero entities that match the provided query config.

Database Count

Assert that the database has exactly $count entities that match the provided query config.

Testing

If you'd like to extend doctrine-assert or create a test case for a bug you've found then you'll need to be able to run the tests and create new ones.

Running Tests

Running the tests should be as simple as:

This will run:

If you'd also like to run the tests with Infection then use:

You'll need to have XDebug installed for this to work though as it requires coverage to be generated.

Testing Framework

Feel free to skip this section and move straight on to 'Creating New Tests'

The Problem

In order to test the library we need to generate a large number of entities as well as create the associated database schema. To keep the code self contained and save committing large numbers of test entities into the code base we make use of the virtual file system vfs://stream and sqlite. This has the added side benefit of running everything in RAM making the test suite run as fast as possible.

How The Testing Framework Works

The following process takes place before each test is run and is managed by AbstractDoctrineAssertTest.

Virtual File System

We first initialise the virtual file system before copying over the Doctrine YAML mapping files that we'll later use to generate our test entities.

Entity Manager

Now we setup the entity manager with our YAML mapping config and an in memory SQLite database. The database is recreated before each test run making sure we have no leakage between tests.

Generate Entities

After we've setup the entity manager we can use it's meta data and an EntityGenerator to create the tests entities. Before we can use these we also need to loop through and require them.

Update Schema

Finally we update the database schema to match our entities and we're good to go.

Test Structure

Tests are structured based on the types of entities they'd like to test against, all tests using the same set of entities are stored in a directory, in this case DoubleOneToOne. This way we can minimise the number of entity sets that we need to define.

Next we have the virtual file system Vfs/ that will be used by any tests within this folder. Within Vfs/config we define our test entities using Doctrine's YAML Mapping format. The YAML filename should match the class name defined inside so Vfs\DoubleOneToOne\One becomes Vfs.DoubleOneToOne.One with .dcm.yml on the end Vfs.DoubleOneToOne.One.dcm.yml.

Creating A Test

Here's the basic outline of a test.

Define Entities

If the entities that we need for our test don't already exist then we create a directory for our tests and YAML files that define all the entities our test will require. If the entities do exist then we can simply add our new test to that directory.

Create Test Class

Now we create a test class. The class must extend AbstractDoctrineAssertTest.

You'll also want to use DoctrineAssertTrait so that you can make test assertions with it.

Create Test Method

We now create one method for each item we'd like to test (as normal).

Setup Fixture Data

You can setup the fixture data you require for your test using Fakers generators and populators.

Make Assertion

Finally you'll use to the doctrine-assert assertions to make an assertion. If you'd like to test that an assertion correctly fails then you can simply expect the ExpectationFailedException.


All versions of doctrine-assert with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
phpunit/phpunit Version ^7.1
doctrine/orm Version ^2.6
symfony/finder Version ^4.0
ext-json Version *
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 ben-rowan/doctrine-assert contains the following files

Loading the files please wait ....