@@ -17,130 +17,75 @@ functional test suite:
17
17
composer install --dev
18
18
````
19
19
20
- Bootstrapping
21
- -------------
20
+ PHPUnit configuration
21
+ ---------------------
22
22
23
- To generate a skeleton bootstrap:
23
+ Copy the ` phpunit.dist.xml ` file from the testing component to the directory
24
+ root of the bundle:
24
25
25
26
````
26
- $ php vendor/symfony-cmf/testing/bin/generate_functional.php
27
+ cp vendor/symfony-cmf/testing/skeleton/phpunit.xml.dist .
27
28
````
28
29
29
- This generates the following files:
30
+ Note that this file includes the bootstrap file ` bootstrap/bootstrap.php `
31
+ which initializes the autoloader and defines some useful PHP constants.
30
32
31
- ````
32
- ./
33
- ./Tests/Functional/app/AppKernel.php
34
- ./Tests/Functional/app/console
35
- ./Tests/Functional/app/config
36
- ./Tests/Functional/app/config/default.yml
37
- ./Tests/Functional/app/config/parameters.yml.dist
38
- ./Tests/Functional/app/config/dist
39
- ./Tests/Functional/app/config/dist/monolog.yml
40
- ./Tests/Functional/app/config/dist/framework.yml
41
- ./Tests/Functional/app/config/dist/phpcrodm.yml
42
- ./Tests/Functional/app/config/dist/routing.yml
43
- ./Tests/Functional/app/config/dist/doctrine.yml
44
- ./Tests/Functional/app/config/user
45
- ````
46
-
47
- You will need to copy ` parameters.yml.dist ` to ` parameters.yml ` for the kernel
48
- to work, the distribution configuration should work out-of-the-box with
49
- doctrine dbal sqlite.
33
+ Create your configuration class
34
+ -------------------------------
50
35
51
- Pull in some other files
52
- ------------------------
36
+ You can include pre-defined configurations from the testing component as
37
+ follows:
53
38
54
- The following files are also useful:
39
+ ```` php
40
+ // YourBundle/Tests/Functional/app/config/config.php
41
+ <?php
55
42
43
+ $loader->import(CMF_TEST_CONFIG_DIR.'/sonata_admin.php');
56
44
````
57
- cp vendor/symfony-cmf/testing/skeleton/.travis.yml .
58
- cp vendor/symfony-cmf/testing/skeleton/phpunit.dist.xml .
59
- ````
60
-
61
- Writing Functional Test Cases
62
- -----------------------------
63
-
64
- Most of the functional test cases in the CMF currently use PHCR-ODM. This
65
- component provides a base test case which automatically purges and creates
66
- the node ` /test ` . You should place any documents your test will create under
67
- this node.
68
-
69
- Example:
70
45
71
- ````
72
- <?php
46
+ We have to use a PHP file to access the ` CMF_TEST_CONFIG_DIR ` constant
47
+ which is defined in the bootstrap file. Have a look in the
48
+ ` /skeleton/app/config ` directory for all possible options.
73
49
74
- namespace ...
75
- use Symfony\Cmf\Component\Testing\Functional\PhpcrOdmTestCase;
50
+ Create the test Kernel
51
+ ----------------------
76
52
77
- class MyTest extends PhpcrOdmTestCase
78
- {
79
- public function testFooIsCreated()
80
- {
81
- $foo = new FooDocument;
82
- $foo->id = '/test/foo';
83
- $this->getDm()->persist($foo);
84
- $this->getDm()->clear();
85
- $foo = $this->getDm()->find(null, '/test/foo');
53
+ Below is an example test kernel. Note that you extend ` TestKernel ` and need to
54
+ implement the ` configure ` method to register any bundles that you need.
86
55
87
- $this->assertNotNull($foo); // will pass
88
- }
56
+ You should use the ` requireBundleSets ` method to register pre-defined sets of
57
+ bundles, e.g. ` sonata_admin ` will include all the bundles required for a
58
+ standard CMF sonata admin interface.
89
59
90
- public function testFooIsGone()
91
- {
92
- $foo = $this->getDm()->find(null, '/test/foo');
93
- $this->assertNull($foo); // will pass
94
- }
95
- }
96
- ````
60
+ For bundles specific to this test kernel or to the bundle as a whole, use the
61
+ ` addBundles ` method.
97
62
98
- There is also a base test case which is storage layer agnostic:
99
-
100
- ````
63
+ ```` php
64
+ // YourBundle/Tests/Functional/app/AppKernel.php
101
65
<?php
102
66
103
- namespace ...
104
- use Symfony\Cmf\ Component\Testing\Functional\BaseTestCase ;
67
+ use Symfony\Cmf\Component\Testing\HttpKernel\TestKernel;
68
+ use Symfony\Component\Config\Loader\LoaderInterface ;
105
69
106
- class MyTest extends PhpcrOdmTestCase
70
+ class AppKernel extends TestKernel
107
71
{
108
- public function testWhatever ()
72
+ public function configure ()
109
73
{
110
- $myService = $this->getContainer()->get('foo');
111
- $application = $this->getApplication();
74
+ $this->requireBundleSets(array(
75
+ 'default', 'phpcr_odm', 'sonata_admin'
76
+ ));
77
+
78
+ $this->addBundles(array(
79
+ new \Knp\Bundle\MenuBundle\KnpMenuBundle(),
80
+ new \Symfony\Cmf\Bundle\MenuBundle\SymfonyCmfMenuBundle(),
81
+ ));
112
82
}
113
- }
114
- ````
115
-
116
83
117
- Changing the Kernel
118
- -------------------
119
-
120
- You may want to have a test use a different kernel then the default
121
- ` AppKernel ` - for example, you might want to test optional dependencies such
122
- as SonataAdmin.
123
-
124
- To do this simply override ` getKernelClassname ` :
84
+ public function registerContainerConfiguration(LoaderInterface $loader)
85
+ {
86
+ // Load our configuration
87
+ $loader->load(__DIR__.'/config/config.php');
88
+ }
125
89
126
- ````
127
- // mytest.php
128
- public static function getKernelClassname()
129
- {
130
- return 'AlternativeKernel';
131
90
}
132
91
````
133
-
134
- The kernel file ` AlternativeKernel.php ` must live inside the directory
135
- ` Tests/Functional/app ` . We avoid the use of the autoloader to avoid having
136
- to guess the bundles namespace.
137
-
138
- Using the test console
139
- ----------------------
140
-
141
- The test console can be invaluable for debugging tests, you can use it as
142
- follows:
143
-
144
- ````
145
- $ php Tests/Functional/app/console
146
- ````
0 commit comments