Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Use KernelTestCase instead of WebTestCase for testing code only requiring the Container#3311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
weaverryan merged 1 commit intosymfony:masterfromjohnkary:kernelTestCase
Mar 5, 2014
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletionscookbook/console/console_command.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -183,14 +183,14 @@ instead of

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

use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Acme\DemoBundle\Command\GreetCommand;

class ListCommandTest extendsWebTestCase
class ListCommandTest extendsKernelTestCase
{
public function testExecute()
{
Expand All@@ -214,3 +214,12 @@ you can extend your test from
// ...
}
}

.. versionadded:: 2.5
:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\KernelTestCase` was
extracted from :class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase`
in Symfony 2.5, where WebTestCase was made to inherit from KernelTestCase.
The difference being that WebTestCase makes available an instance of
:class:`Symfony\\Bundle\\FrameworkBundle\\Client` via `createClient()`,
while KernelTestCase makes available an instance of
:class:`Symfony\\Component\\HttpKernel\\KernelInterface` via `createKernel()`.
9 changes: 4 additions & 5 deletionscookbook/testing/doctrine.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,15 +17,15 @@ Functional Testing
------------------

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

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

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class ProductRepositoryFunctionalTest extendsWebTestCase
class ProductRepositoryFunctionalTest extendsKernelTestCase
{
/**
* @var \Doctrine\ORM\EntityManager
Expand All@@ -37,8 +37,7 @@ which makes all of this quite easy::
*/
public function setUp()
{
static::$kernel = static::createKernel();
static::$kernel->boot();
self::bootKernel();
$this->em = static::$kernel->getContainer()
->get('doctrine')
->getManager()
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp