Download the PHP package raphhh/pumpkin without Composer
On this page you can find all versions of the php package raphhh/pumpkin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download raphhh/pumpkin
More information about raphhh/pumpkin
Files in raphhh/pumpkin
Package pumpkin
Short Description A helper for mocks and database resources in PHPUnit
License MIT
Homepage http://labs.raphaellefebvre.be/pumpkin
Informations about the package pumpkin
README
What is Pumpkin?
Pumpkin helps you to organize the storage of your mocks for PHPUnit. It gives mocks objects and database resources when you execute a test.
How to start?
You just have to add the Pumpkin package in your composer.json and update your project.
What can I do?
Get the current test
Usually, when you use PHPUnit, you create a new test class extending \PHPUnit_Framework_TestCase
. Instead, with Pumpkin, you have to extend \Pumpkin\TestCase
.
\Pumpkin\TestCase
extends \PHPUnit_Framework_TestCase
, so you have the same interface as if you use PHPUnit.
But you can also know the current test with \Pumpkin\TestCase::getTest(
). You receive a \Pumpkin\Test\Test
object which reflects the current method of the test.
The current test is the method executed by PHPUnit and containing your assertions. Typically, this is a test* method.
For example
With this method you can reflected the method of the executed test, retrieve annotations, ... anything!
Note that if you do not want to extend \Pumpkin\TestCase
, you can also directly extend \PHPUnit_Framework_TestCase
and use the trait \Pumpkin\Test\TestCaseTrait
.
Get mocks of the current test
You can retrieve mocks of a the current test. Mocks objects must be user objects. They are declared in a specific file for the current test.
The file is located in the following path:
This path can start from the test directory or from a parent one.
You can declare as many mocks as you want in this file.
For example:
Reset the database with specific data for the current test
When you want to mock databases with PHPUnit, you need to use \PHPUnit_Extensions_Database_TestCase
. Instead, with Pumpkin, you have to extend \Pumpkin\Database\TestCase
.
\Pumpkin\Database\TestCase extends \PHPUnit_Extensions_Database_TestCase
, so you have the same interface as if you use PHPUnit.
Note that if you do not want to extend \Pumpkin\Database\TestCase
, you can also directly extend \PHPUnit_Extensions_Database_TestCase
and use the trait \Pumpkin\Test\Database\TestCaseTrait
.
The annotations
But you can also specify the tables you want to load for the current test. This is done in the comments of the current test, with the @db tag.
The data file
The data are stored in a file with the following path:
Currently, Pumpkin support only csv files, but it can be evolved in future.
Your data can be specific for the current test, or be common with several tests. Everything is determined by the data file path. If you want specific data, you have to locate the data file in the directory of your test. If you want common data, you have to locate the data file in a common directory of your tests.
The database config
If you want to load your mocked data, you have to allow PHPUnit to access to your database. With Pumpkin you have just to specify your config in the phpunit.xml.
For example
All versions of pumpkin with dependencies
phpunit/phpunit Version *
phpunit/dbunit Version *
raphhh/trex-parser Version ^1.1
doctrine/annotations Version ^1.2