Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5cda1c7

Browse filesBrowse files
committed
feature #3311 Use KernelTestCase instead of WebTestCase for testing code only requiring the Container (johnkary)
This PR was merged into the master branch. Discussion ---------- Use KernelTestCase instead of WebTestCase for testing code only requiring the Container | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes (symfony/symfony#9739) | Applies to | 2.5 | Fixed tickets | none This documents using the new KernelTestCase introduced in symfony/symfony#9739, which was recently merged to master for 2.5-dev. KernelTestCase was extracted from WebTestCase to become a more-focused base class for functional testing code that requires only a container but no client. WebTestCase is then more-focused to be used for tests requiring a client. If you think this needs any kind of version callout in the docs to highlight the base class change we can add that too. :rocket: Previous PR #3244 against the 2.4 branch was closed because the corresponding feature was not merged into 2.4. Commits ------- 6c52b92 [#3311] Use KernelTestCase instead of WebTestCase for tests needing only a Container
2 parents 8903e23 + 6c52b92 commit 5cda1c7
Copy full SHA for 5cda1c7

File tree

Expand file treeCollapse file tree

2 files changed

+16
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-8
lines changed

‎cookbook/console/console_command.rst

Copy file name to clipboardExpand all lines: cookbook/console/console_command.rst
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ instead of
183183

184184
To be able to use the fully set up service container for your console tests
185185
you can extend your test from
186-
:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase`::
186+
:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\KernelTestCase`::
187187

188188
use Symfony\Component\Console\Tester\CommandTester;
189189
use Symfony\Bundle\FrameworkBundle\Console\Application;
190-
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
190+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
191191
use Acme\DemoBundle\Command\GreetCommand;
192192

193-
class ListCommandTest extends WebTestCase
193+
class ListCommandTest extends KernelTestCase
194194
{
195195
public function testExecute()
196196
{
@@ -214,3 +214,12 @@ you can extend your test from
214214
// ...
215215
}
216216
}
217+
218+
.. versionadded:: 2.5
219+
:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\KernelTestCase` was
220+
extracted from :class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase`
221+
in Symfony 2.5, where WebTestCase was made to inherit from KernelTestCase.
222+
The difference being that WebTestCase makes available an instance of
223+
:class:`Symfony\\Bundle\\FrameworkBundle\\Client` via `createClient()`,
224+
while KernelTestCase makes available an instance of
225+
:class:`Symfony\\Component\\HttpKernel\\KernelInterface` via `createKernel()`.

‎cookbook/testing/doctrine.rst

Copy file name to clipboardExpand all lines: cookbook/testing/doctrine.rst
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ Functional Testing
1717
------------------
1818

1919
If you need to actually execute a query, you will need to boot the kernel
20-
to get a valid connection. In this case, you'll extend the ``WebTestCase``,
20+
to get a valid connection. In this case, you'll extend the ``KernelTestCase``,
2121
which makes all of this quite easy::
2222

2323
// src/Acme/StoreBundle/Tests/Entity/ProductRepositoryFunctionalTest.php
2424
namespace Acme\StoreBundle\Tests\Entity;
2525

26-
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
26+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
2727

28-
class ProductRepositoryFunctionalTest extends WebTestCase
28+
class ProductRepositoryFunctionalTest extends KernelTestCase
2929
{
3030
/**
3131
* @var \Doctrine\ORM\EntityManager
@@ -37,8 +37,7 @@ which makes all of this quite easy::
3737
*/
3838
public function setUp()
3939
{
40-
static::$kernel = static::createKernel();
41-
static::$kernel->boot();
40+
self::bootKernel();
4241
$this->em = static::$kernel->getContainer()
4342
->get('doctrine')
4443
->getManager()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.