Skip to content

Commit 1b55b9d

Browse files
committed
Updated the README
1 parent df4afbd commit 1b55b9d

File tree

2 files changed

+48
-105
lines changed

2 files changed

+48
-105
lines changed

README.md

Lines changed: 46 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -17,130 +17,75 @@ functional test suite:
1717
composer install --dev
1818
````
1919

20-
Bootstrapping
21-
-------------
20+
PHPUnit configuration
21+
---------------------
2222

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:
2425

2526
````
26-
$ php vendor/symfony-cmf/testing/bin/generate_functional.php
27+
cp vendor/symfony-cmf/testing/skeleton/phpunit.xml.dist .
2728
````
2829

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.
3032

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+
-------------------------------
5035

51-
Pull in some other files
52-
------------------------
36+
You can include pre-defined configurations from the testing component as
37+
follows:
5338

54-
The following files are also useful:
39+
````php
40+
// YourBundle/Tests/Functional/app/config/config.php
41+
<?php
5542

43+
$loader->import(CMF_TEST_CONFIG_DIR.'/sonata_admin.php');
5644
````
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:
7045

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.
7349

74-
namespace ...
75-
use Symfony\Cmf\Component\Testing\Functional\PhpcrOdmTestCase;
50+
Create the test Kernel
51+
----------------------
7652

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.
8655

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.
8959

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.
9762

98-
There is also a base test case which is storage layer agnostic:
99-
100-
````
63+
````php
64+
// YourBundle/Tests/Functional/app/AppKernel.php
10165
<?php
10266

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;
10569

106-
class MyTest extends PhpcrOdmTestCase
70+
class AppKernel extends TestKernel
10771
{
108-
public function testWhatever()
72+
public function configure()
10973
{
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+
));
11282
}
113-
}
114-
````
115-
11683

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+
}
12589

126-
````
127-
// mytest.php
128-
public static function getKernelClassname()
129-
{
130-
return 'AlternativeKernel';
13190
}
13291
````
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-
````

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "symfony-cmf/testing-bootstrap",
2+
"name": "symfony-cmf/testing",
33
"license": "MIT",
44
"description": "Component for bootstraping functional tests for CMF bundles only.",
55
"authors": [
@@ -18,9 +18,7 @@
1818
"doctrine/phpcr-bundle": "1.0.*",
1919
"doctrine/data-fixtures": "1.0.*",
2020

21-
"jackalope/jackalope-doctrine-dbal": "1.0.*",
22-
23-
"instaclick/base-test-bundle": "dev-master"
21+
"jackalope/jackalope-doctrine-dbal": "1.0.*"
2422
},
2523
"autoload": {
2624
"psr-0": { "Symfony\\Cmf\\Component\\Testing": "src/" }

0 commit comments

Comments
 (0)