Download the PHP package teamneusta/pimcore-testing-framework without Composer
On this page you can find all versions of the php package teamneusta/pimcore-testing-framework. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download teamneusta/pimcore-testing-framework
More information about teamneusta/pimcore-testing-framework
Files in teamneusta/pimcore-testing-framework
Package pimcore-testing-framework
Short Description The Pimcore testing framework provides base classes for unit, integration and functional testing
License GPL-3.0-or-later
Informations about the package pimcore-testing-framework
Pimcore Testing Framework
Provides tools for Pimcore unit/integration testing with PHPUnit.
Installation
- Require the bundle
Usage
Bootstrapping Pimcore
We provide a convenience method to bootstrap Pimcore for running tests.
Just call BootstrapPimcore::bootstrap()
in your tests/bootstrap.php
as seen below, and you're done.
You can also pass any environment variable via named arguments to this method:
Integration Tests For a Bundle
If you want to add integration tests for a Bundle, you need to set up an application with a kernel.
Pimcore also expects some configuration
(e.g., for the security
) to be present.
You can use the \Neusta\Pimcore\TestingFramework\Kernel\TestKernel
as a base,
which already provides all necessary configurations with default values
(see: dist/config
and dist/pimcore10/config
or dist/pimcore11/config
, depending on your Pimcore version).
For a basic setup, you can use the TestKernel
directly:
[!IMPORTANT]
Don't forget to create thetests/app
directory![!NOTE] Since the kernels of Pimcore 10 and 11 are not compatible (the signature of the method
configureContainer()
differs), we have extended ourTestKernel
with the ability to load separate configuration files depending on the version. Configuration that is compatible with both Pimcore versions belongs to theconfig/
folder of the test app as before. Version specific configuration can be placed inside theconfig/pimcore10/
orconfig/pimcore11/
folder and will be loaded last.
Switch Common Behavior on/off in Test Cases
We provide traits to switch common behavior on/off in whole test case classes.
Admin Mode
The admin mode is disabled by default when calling BootstrapPimcore::bootstrap()
.
To enable it again, you can use the WithAdminMode
trait.
Cache
WithoutCache
Inherited Values of DataObjects
WithInheritedValues
WithoutInheritedValues
Integration Tests With a Configurable Kernel
The TestKernel
can be configured dynamically for each test.
This is useful if different configurations or dependent bundles are to be tested.
To do this, your test class must inherit from KernelTestCase
:
Attributes
An alternative to passing a config
closure in the options
array to KernelTestCase::bootKernel()
is to use attributes for the kernel configuration.
[!TIP] All attributes can be used on class and test method level.
Data Provider
You can also use the RegisterBundle
, ConfigureContainer
, ConfigureExtension
, or RegisterCompilerPass
classes
to configure the kernel in a data provider.
[!TIP] The kernel configuration objects are not passed as arguments to the test method, which means you can use them anywhere between your provided real test data.
Custom Attributes
You can create your own kernel configuration attributes by implementing the KernelConfiguration
interface:
Then you can use the new class as an attribute or inside a data provider.
Integration Tests With a Database
If you write integration tests that use the database, we've got you covered too.
We provide the ResetDatabase
trait, which does the heavy lifting:
Just use it in one of your test case classes,
and it'll install a fresh Pimcore into the configured database before the first test is run.
It'll also reset the database between each test, so you don't have to worry about leftovers from previous tests.
Using a Dump
If you already have a database dump that you want to use instead of a fresh Pimcore installation,
there's the DATABASE_DUMP_LOCATION
environment variable.
Point it to the location of your dump, and it'll be used instead.
Faster Database Reset
By default, resetting the database between the tests works by dropping the database, recreating it and reinstalling Pimcore (or reimporting the dump).
This is rather slow, but there are some tricks that can speed it up:
Storing the Database in the RAM
Normally, the database is stored on the disk, so that the data is persisted. But we don't really need this for testing, so if you're using Docker, you can configure it to store it in RAM instead:
Wrapping Each Test in a Transaction
We support the dama/doctrine-test-bundle
,
which isolates database tests by wrapping them into a transaction.
You just have to install the bundle according to its readme,
and it'll automatically be used.
Contribution
Feel free to open issues for any bug, feature request, or other ideas.
Please remember to create an issue before creating large pull requests.
Local Development
To develop on local machine, the vendor dependencies are required.
We use composer scripts for our main quality tools. They can be executed via the bin/composer
file as well.
All versions of pimcore-testing-framework with dependencies
doctrine/persistence Version ^2.2 || ^3.0
phpunit/phpunit Version ^9.6.0
pimcore/pimcore Version ^10.5 || ~11.0.0 || ~11.1.0 || ~11.2.2 || ~11.3.0 || ~11.4.0
psr/log Version ^1.1.3 || ^2.0 || ^3.0
symfony/config Version ^5.4 || ^6.4
symfony/console Version ^5.4 || ^6.4
symfony/dependency-injection Version ^5.4 || ^6.4
symfony/event-dispatcher Version ^5.4 || ^6.4
symfony/filesystem Version ^5.4 || ^6.4
symfony/framework-bundle Version ^5.4 || ^6.4
symfony/http-kernel Version ^5.4 || ^6.4