Skip to content

Commit 5bd802c

Browse files
committed
Added readme
1 parent d0b5933 commit 5bd802c

File tree

1 file changed

+94
-5
lines changed

1 file changed

+94
-5
lines changed

Readme.md

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# Symfony Bundle Test
22

3-
[![Latest Version](https://img.shields.io/github/release/nyholm/symfony-bundle-test.svg?style=flat-square)](https://github.com/nyholm/symfony-bundle-test/releases)
4-
[![Build Status](https://img.shields.io/travis/nyholm/symfony-bundle-test.svg?style=flat-square)](https://travis-ci.org/nyholm/symfony-bundle-test)
5-
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/nyholm/symfony-bundle-test.svg?style=flat-square)](https://scrutinizer-ci.com/g/nyholm/symfony-bundle-test)
6-
[![Quality Score](https://img.shields.io/scrutinizer/g/nyholm/symfony-bundle-test.svg?style=flat-square)](https://scrutinizer-ci.com/g/nyholm/symfony-bundle-test)
3+
[![Latest Version](https://img.shields.io/github/release/Nyholm/symfony-bundle-test.svg?style=flat-square)](https://github.com/Nyholm/symfony-bundle-test/releases)
4+
[![Build Status](https://img.shields.io/travis/Nyholm/symfony-bundle-test.svg?style=flat-square)](https://travis-ci.org/Nyholm/symfony-bundle-test)
5+
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Nyholm/symfony-bundle-test.svg?style=flat-square)](https://scrutinizer-ci.com/g/Nyholm/symfony-bundle-test)
6+
[![Quality Score](https://img.shields.io/scrutinizer/g/Nyholm/symfony-bundle-test.svg?style=flat-square)](https://scrutinizer-ci.com/g/Nyholm/symfony-bundle-test)
77
[![Total Downloads](https://img.shields.io/packagist/dt/nyholm/symfony-bundle-test.svg?style=flat-square)](https://packagist.org/packages/nyholm/symfony-bundle-test)
88

99
**Test if your bundle is compatible with different Symfony versions**
1010

11+
When you want to make sure that your bundle works with different versions of Symfony
12+
you need to create a custom `AppKernel` and load your bundle and configuration.
13+
14+
Using this bundle test together with Matthias Nobacks's
15+
[SymfonyDependencyInjectionTest](https://github.com/matthiasnoback/SymfonyDependencyInjectionTest)
16+
will give you a good base for testing a Symfony bundle.
17+
1118
## Install
1219

1320
Via Composer
@@ -16,4 +23,86 @@ Via Composer
1623
$ composer require nyholm/symfony-bundle-test
1724
```
1825

19-
https://github.com/matthiasnoback/SymfonyDependencyInjectionTest
26+
## Write a test
27+
28+
```php
29+
30+
use Nyholm\BundleTest\BaseBundleTestCase;
31+
use Acme\AcmeFooBundle;
32+
use Acme\Service\Foo;
33+
34+
class BundleInitializationTest extends BaseBundleTestCase
35+
{
36+
protected function getBundleClass()
37+
{
38+
return AcmeFooBundle::class;
39+
}
40+
41+
public function testInitBundle()
42+
{
43+
// Boot the kernel.
44+
$this->bootKernel();
45+
46+
// Get the containter
47+
$container = $this->getContainer();
48+
49+
// Test if you services exists
50+
$this->assertTrue($container->has('acme.foo'));
51+
$service = $container->get('acme.foo');
52+
$this->assertInstanceOf(Foo::class, $service);
53+
}
54+
55+
public function testBundleWithDifferentConfiguration()
56+
{
57+
// Create a new Kernel
58+
$kernel = $this->createKernel();
59+
60+
// Add some configuration
61+
$kernel->addConfigFile(__DIR__.'/config.yml');
62+
63+
// Add some other bundles we depend on
64+
$kernel->addBundle(OtherBundle::class);
65+
66+
// Boot the kernel as normal ...
67+
$this->bootKernel();
68+
69+
// ...
70+
}
71+
}
72+
73+
```
74+
75+
## Configure travis
76+
77+
You want travis to run the highest version of Symfony you support and the lowest
78+
version. Same with PHP version. There is no need for testing for version in between
79+
because both Symfony and PHP follow Semver.
80+
81+
```yaml
82+
language: php
83+
84+
php:
85+
- 5.5
86+
- 7.1
87+
- hhvm
88+
env:
89+
global:
90+
- TEST_COMMAND="vendor/bin/phpunit"
91+
matrix:
92+
- SYMFONY_VERSION=3.2.*
93+
- SYMFONY_VERSION=2.7.*
94+
95+
matrix:
96+
fast_finish: true
97+
include:
98+
- php: 5.5
99+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_VERSION=2.7.* TEST_COMMAND="vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
100+
101+
install:
102+
- composer require symfony/symfony:${SYMFONY_VERSION} --no-update
103+
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
104+
105+
script:
106+
- $TEST_COMMAND
107+
```
108+

0 commit comments

Comments
 (0)