Skip to content

Commit

Permalink
PHPUnit as dev dependency (#32)
Browse files Browse the repository at this point in the history
PHPUnit as dev dependency
  • Loading branch information
dmaicher committed Jul 25, 2017
1 parent 0e28572 commit 5a49c47
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: php

php:
- '5.6'
- '7.0'
- '7.1'

env:
- SYMFONY_VERSION="2.7.*"
- SYMFONY_VERSION="2.8.*"
- SYMFONY_VERSION="3.2.*"
- SYMFONY_VERSION="3.3.*"

Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.0.0] - 2017-07-XX
### Changed
- made `phpunit/phpunit` a `dev` dependency only
- removed separation of two different branches/releases for PHPUnit < 6 (`1.x`) and >= 6 (`master`/`2.x`)
- renamed phpunit listener class

### Fixed
- compatibility with `symfony/phpunit-bridge`
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,30 @@ It also includes a `StaticArrayCache` that will be automatically configured as m
}
```

3. Add the PHPUnit test listener in your xml config (e.g. `app/phpunit.xml`)
3. Add the PHPUnit test listener in your xml config (e.g. `app/phpunit.xml`) depending on your PHPUnit version

PHPUnit < 6:
```xml
<phpunit>
...
<listeners>
<listener class="\DAMA\DoctrineTestBundle\PHPUnit\PHPUnitStaticDbConnectionListener" />
<listener class="\DAMA\DoctrineTestBundle\PHPUnit\LegacyPHPUnitListener" />
</listeners>
</phpunit>
```

PHPUnit >= 6:
```xml
<phpunit>
...
<listeners>
<listener class="\DAMA\DoctrineTestBundle\PHPUnit\PHPUnitListener" />
</listeners>
</phpunit>
```
4. Make sure you also have `phpunit/phpunit` available as a `dev` dependency to run your tests. Alternatively this bundle is also compatible with `symfony/phpunit-bridge` and its `simple-phpunit` script.

4. That's it! From now on whatever changes you do to the database within each single testcase (be it a `WebTestCase` or a `KernelTestCase` or any custom test) are automatically rolled back for you :blush:
5. That's it! From now on whatever changes you do to the database within each single testcase (be it a `WebTestCase` or a `KernelTestCase` or any custom test) are automatically rolled back for you :blush:

### Configuration

Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
}
],
"require": {
"php": "^7.0",
"php": ">=5.5.0",
"symfony/symfony": "~2.3|~3.0",
"doctrine/dbal": "~2.5",
"doctrine/doctrine-bundle": "~1.4",
"phpunit/phpunit": "^6.0"
"doctrine/doctrine-bundle": "~1.4"
},
"require-dev": {
"phpunit/phpunit": "~5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -27,7 +29,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
"dev-master": "3.1.x-dev"
}
}
}
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
init_composer:
curl -s https://getcomposer.org/installer | php
php composer.phar install --prefer-dist -o
php composer.phar install --prefer-dist -o --dev

test:
vendor/bin/phpunit -c tests/ tests/
Expand Down
33 changes: 33 additions & 0 deletions src/DAMA/DoctrineTestBundle/PHPUnit/LegacyPHPUnitListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace DAMA\DoctrineTestBundle\PHPUnit;

use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;

class LegacyPHPUnitListener extends \PHPUnit_Framework_BaseTestListener
{
/**
* @param \PHPUnit_Framework_Test $test
*/
public function startTest(\PHPUnit_Framework_Test $test)
{
StaticDriver::beginTransaction();
}

/**
* @param \PHPUnit_Framework_Test $test
* @param $time
*/
public function endTest(\PHPUnit_Framework_Test $test, $time)
{
StaticDriver::rollBack();
}

/**
* @param \PHPUnit_Framework_TestSuite $suite
*/
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
{
StaticDriver::setKeepStaticConnections(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestSuite;

class PHPUnitStaticDbConnectionListener extends BaseTestListener
class PHPUnitListener extends BaseTestListener
{
/**
* @param Test $test
Expand Down

0 comments on commit 5a49c47

Please sign in to comment.