1
1
# Symfony Bundle Test
2
2
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 )
7
7
[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/nyholm/symfony-bundle-test.svg?style=flat-square )] ( https://packagist.org/packages/nyholm/symfony-bundle-test )
8
8
9
9
** Test if your bundle is compatible with different Symfony versions**
10
10
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
+
11
18
## Install
12
19
13
20
Via Composer
@@ -16,4 +23,86 @@ Via Composer
16
23
$ composer require nyholm/symfony-bundle-test
17
24
```
18
25
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