|
1 |
| -[WIP] Symfony CMF Testing Component |
2 |
| -=================================== |
| 1 | +# Symfony CMF Testing Component |
3 | 2 |
|
4 | 3 | **NOTE**: This is an internal tool and is not intended to be used outside of
|
5 |
| -the context of the CMF! |
| 4 | +the context of the CMF. |
6 | 5 |
|
7 | 6 | This is a testing library created to aid the development of functional tests
|
8 |
| -for the Symfony CMF Bundle suite. |
| 7 | +for the Symfony CMF. |
9 | 8 |
|
10 |
| -Install the Dependencies |
11 |
| ------------------------- |
12 |
| - |
13 |
| -Use composer to install the dependencies required to be able to run the |
14 |
| -functional test suite: |
15 |
| - |
16 |
| -```` |
17 |
| -composer install --dev |
18 |
| -```` |
19 |
| - |
20 |
| -PHPUnit configuration |
21 |
| ---------------------- |
22 |
| - |
23 |
| -Copy the `phpunit.dist.xml` file from the testing component to the directory |
24 |
| -root of the bundle: |
25 |
| - |
26 |
| -```` |
27 |
| -cp vendor/symfony-cmf/testing/skeleton/phpunit.xml.dist . |
28 |
| -```` |
29 |
| - |
30 |
| -Note that this file includes the bootstrap file `bootstrap/bootstrap.php` |
31 |
| -which initializes the autoloader and defines some useful PHP constants. |
32 |
| - |
33 |
| -Create your configuration class |
34 |
| -------------------------------- |
35 |
| - |
36 |
| -You can include pre-defined configurations from the testing component as |
37 |
| -follows: |
38 |
| - |
39 |
| -````php |
40 |
| -// YourBundle/Tests/Functional/app/config/config.php |
41 |
| -<?php |
42 |
| - |
43 |
| -$loader->import(CMF_TEST_CONFIG_DIR.'/sonata_admin.php'); |
44 |
| -```` |
45 |
| - |
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. |
49 |
| - |
50 |
| -Create the test Kernel |
51 |
| ----------------------- |
52 |
| - |
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. |
55 |
| - |
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. |
59 |
| - |
60 |
| -For bundles specific to this test kernel or to the bundle as a whole, use the |
61 |
| -`addBundles` method. |
62 |
| - |
63 |
| -````php |
64 |
| -// YourBundle/Tests/Functional/app/AppKernel.php |
65 |
| -<?php |
66 |
| - |
67 |
| -use Symfony\Cmf\Component\Testing\HttpKernel\TestKernel; |
68 |
| -use Symfony\Component\Config\Loader\LoaderInterface; |
69 |
| - |
70 |
| -class AppKernel extends TestKernel |
71 |
| -{ |
72 |
| - public function configure() |
73 |
| - { |
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 |
| - )); |
82 |
| - } |
83 |
| - |
84 |
| - public function registerContainerConfiguration(LoaderInterface $loader) |
85 |
| - { |
86 |
| - // Load our configuration |
87 |
| - $loader->load(__DIR__.'/config/config.php'); |
88 |
| - } |
89 |
| - |
90 |
| -} |
91 |
| -```` |
92 |
| - |
93 |
| -Performing functional tests |
94 |
| ---------------------------- |
95 |
| - |
96 |
| -The testing component provides a base test class which makes it easy |
97 |
| -to load DataFixtures and access different types of object managers. |
98 |
| - |
99 |
| - |
100 |
| -````php |
101 |
| -<?php |
102 |
| - |
103 |
| -namespace Symfony\Cmf\Bundle\MenuBundle\Tests\Functional\Admin\MenuNodeAdminTest; |
104 |
| - |
105 |
| -use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; |
106 |
| - |
107 |
| -class MenuNodeAdminTest extends BaseTestCase |
108 |
| -{ |
109 |
| - public function setUp() |
110 |
| - { |
111 |
| - $this->db('PHPCR')->loadFixtures(array( |
112 |
| - 'Symfony\Cmf\Bundle\MenuBundle\Tests\Functional\DataFixtures\PHPCR\LoadMenuData', |
113 |
| - )); |
114 |
| - $this->client = $this->createClient(); |
115 |
| - } |
116 |
| - |
117 |
| - public function testDashboard() |
118 |
| - { |
119 |
| - $crawler = $this->client->request('GET', '/admin/dashboard'); |
120 |
| - $res = $this->client->getResponse(); |
121 |
| - $this->assertEquals(200, $res->getStatusCode()); |
122 |
| - $this->assertCount(1, $crawler->filter('html:contains("dashboard.label_menu_node")')); |
123 |
| - |
124 |
| - $this->db('PHPCR')->getOm(); // get the document/entity (or object) manager |
125 |
| - } |
126 |
| -} |
127 |
| -```` |
| 9 | +See the [official documentation](http://symfony.com/doc/master/cmf/components/testing.html) |
0 commit comments