PHPackages                             jwage/phpchunkit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. jwage/phpchunkit

AbandonedArchivedLibrary

jwage/phpchunkit
================

PHPUnit Test Runner

2458611[4 issues](https://github.com/jwage/PHPChunkit/issues)PHP

Since Dec 20Pushed 8y ago3 watchersCompare

[ Source](https://github.com/jwage/PHPChunkit)[ Packagist](https://packagist.org/packages/jwage/phpchunkit)[ RSS](/packages/jwage-phpchunkit/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHPChunkit
==========

[](#phpchunkit)

[![Build Status](https://camo.githubusercontent.com/c53522be0dd8cb0da7617646b8302c5e91ac6b31bafd3ffc5eef2aa1064c5c31/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6a776167652f7068706368756e6b69742e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/jwage/phpchunkit)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ac8c5837b0cff31a06e174f3053b16bda70dfcc8c5fb16de3aaf648d9a46f9f6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a776167652f7068706368756e6b69742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jwage/phpchunkit/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/5cdbac57df9161bc7b93d313fabd82d8027dd55e73a5a19f79f99393407b3737/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a776167652f7068706368756e6b69742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jwage/phpchunkit/?branch=master)

PHPChunkit is a library that sits on top of PHPUnit and adds additional functionality to make it easier to work with large unit and functional test suites. The primary feature is test chunking and database sandboxing which gives you the ability to run your tests in parallel chunks on the same server or across multiple servers.

In order to run functional tests in parallel on the same server, you need to have a concept of database sandboxing. You are responsible for implementing the sandbox preparation, database creation, and sandbox cleanup. PHPChunkit provides a framework for you to hook in to so you can prepare your application environment sandbox.

Parallel Execution Example
--------------------------

[](#parallel-execution-example)

Imagine you have 100 tests and each test takes 1 second. When the tests are ran serially, it will take 100 seconds to complete. But if you split the 100 tests in to 10 even chunks and run the chunks in parallel, it will in theory take only 10 seconds to complete.

Now imagine you have a two node Jenkins cluster. You can spread the run of each chunk across the 2 servers with 5 parallel jobs running on each server:

### Jenkins Server #1 with 5 job workers

[](#jenkins-server-1-with-5-job-workers)

```
phpchunkit --num-chunks=10 --chunk=1 --sandbox --create-dbs
phpchunkit --num-chunks=10 --chunk=2 --sandbox --create-dbs
phpchunkit --num-chunks=10 --chunk=3 --sandbox --create-dbs
phpchunkit --num-chunks=10 --chunk=4 --sandbox --create-dbs
phpchunkit --num-chunks=10 --chunk=5 --sandbox --create-dbs

```

### Jenkins Server #2 with 5 job workers

[](#jenkins-server-2-with-5-job-workers)

```
phpchunkit --num-chunks=10 --chunk=6 --sandbox --create-dbs
phpchunkit --num-chunks=10 --chunk=7 --sandbox --create-dbs
phpchunkit --num-chunks=10 --chunk=8 --sandbox --create-dbs
phpchunkit --num-chunks=10 --chunk=9 --sandbox --create-dbs
phpchunkit --num-chunks=10 --chunk=10 --sandbox --create-dbs

```

Screenshot
----------

[](#screenshot)

[![PHPChunkit Screenshot](https://raw.githubusercontent.com/jwage/PHPChunkit/master/docs/phpchunkit.png?1)](https://raw.githubusercontent.com/jwage/PHPChunkit/master/docs/phpchunkit.png?1)

Installation
------------

[](#installation)

Install in your project with composer:

```
composer require jwage/phpchunkit
./vendor/bin/phpchunkit

```

Install globally with composer:

```
composer global require jwage/phpchunkit
ln -s /home/youruser/.composer/vendor/bin/phpchunkit /usr/local/bin/phpchunkit
cd /path/to/your/project
phpchunkit

```

Install Phar:

```
wget https://github.com/jwage/phpchunkit/raw/master/phpchunkit.phar
chmod +x phpchunkit.phar
sudo mv phpchunkit.phar /usr/local/bin/phpchunkit
cd /path/to/your/project
phpchunkit

```

Setup
-----

[](#setup)

As mentioned above in the introduction, you are responsible for implementing the sandbox preparation, database creation and sandbox cleanup processes by adding [EventDispatcher](http://symfony.com/doc/current/components/event_dispatcher.html)listeners. You can listen for the following events:

- `sandbox.prepare` - Use the `Events::SANDBOX_PREPARE` constant.
- `databases.create` - Use the `Events::DATABASES_CREATE` constant.
- `sandbox.cleanup` - Use the `Events::SANDBOX_CLEANUP` constant.

Take a look at the listeners implemented in this projects test suite for an example:

- [SandboxPrepare.php](https://github.com/jwage/phpchunkit/blob/master/tests/Listener/SandboxPrepare.php)
- [DatabasesCreate.php](https://github.com/jwage/phpchunkit/blob/master/tests/Listener/DatabasesCreate.php)
- [SandboxCleanup.php](https://github.com/jwage/phpchunkit/blob/master/tests/Listener/SandboxCleanup.php)

### Configuration

[](#configuration)

Here is an example `phpchunkit.xml` file. Place this in the root of your project:

```

        ./src
        ./tests

        testdb1
        testdb2

            PHPChunkit\Test\Listener\SandboxPrepare

            PHPChunkit\Test\Listener\SandboxCleanup

            PHPChunkit\Test\Listener\DatabasesCreate

```

The `tests/phpchunkit_bootstrap.php` file is loaded after the XML is loaded and gives you the ability to do more advanced things with the [Configuration](https://github.com/jwage/phpchunkit/blob/master/src/Configuration.php).

Here is an example:

```
