我正在使用Liip\FunctionalTestBundle单元测试,它运行得很好.
AppCategoryControllerTest.php:
class AppCategoryControllerTest extends BoEditoAuthWebTestCase
{
public function setUp()
{
parent::setUp();
// It returns an array of class paths
$this->loadFixtures($this->getAllDataFixtures());
}
//...
}
Run Code Online (Sandbox Code Playgroud)
现在我想用Behat测试装置.
怎么可能?
FeatureContext.php:
/**
* @BeforeScenario @createSchema
*
* load my fixtures with Liip\FunctionalTestBundle\Test\WebTestCase
*/
public function createDatabase()
{
// What can I do here?
}
Run Code Online (Sandbox Code Playgroud) 在我的测试中,我调用了一些发送电子邮件的命令.我可以使用以下命令显示发送的电子邮件数量:
$output->writeln(
$spool->flushQueue(
$this->getContainer()->get('swiftmailer.transport.real')
)
);
Run Code Online (Sandbox Code Playgroud)
Symfony2文档解释了如何在Web测试期间使用探查器获取电子邮件内容(此处也在Stack Overflow中进行了解释),但我不知道在没有Web请求时如何执行相同的操作.
我使用了这些链接中提供的代码:
<?php
namespace ACME\MyBundle\Tests\Command;
use Liip\FunctionalTestBundle\Test\WebTestCase;
class EmailTest extends WebTestCase
{
public function tesEmailCommand()
{
// load data fixtures
// http://symfony.com/doc/current/cookbook/email/testing.html
$client = static::createClient();
// Enable the profiler for the next request (it does nothing if the profiler is not available)
$client->enableProfiler();
/** @var \Symfony\Bundle\FrameworkBundle\Console\Application $application */
// inherit from the parent class
$application = clone $this->application;
$application->add(new EmailCommand());
$command = $application->find('acme:emails');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'command' => 'acme:emails' …Run Code Online (Sandbox Code Playgroud) 我试图将@validator注入我的服务,但LiipFunctionalTestBundle在注入时会覆盖该服务.
admin.image_service:
class: AdminBundle\Service\ImageService
arguments: ["@validator", "@doctrine.orm.admin_entity_manager", "@image_storage_filesystem"]
Run Code Online (Sandbox Code Playgroud)
哪会导致错误
必须是Symfony\Component\Validator\Validator\RecursiveValidator的实例,给出Liip\FunctionalTestBundle\Validator\DataCollectingValidator的实例
运行php bin/console debug:容器结果
liip_functional_test.validator:Liip\FunctionalTestBundle\Validator\DataCollectingValidator
验证器:"liip_functional_test.validator"的别名
有没有办法解决这个问题,而不是删除liip并重构我的所有测试?
今天是个好日子,
在过去的几天里,我一直在研究测试驱动开发,并决定我也需要学习它.虽然我无法弄清楚如何准确地做到这一点.
我的项目依赖于Symfony2.1.6框架和Doctrine,所以我有一些需要填充的数据库表.
书(1,n) - (0,n)类型
现在,如果我想插入一个类型记录,我首先需要编写一个测试来确保所有内容都被插入(或者我错了吗?)
现在的问题是我不知道如何访问我的数据库,因为它是由框架管理的.
我唯一能找到的是使用LiipFunctionalTestBundle https://github.com/liip/LiipFunctionalTestBundle,它每次运行测试时都会创建并恢复临时数据库.我按照说明设置了所有内容.
编辑:我的app/config/config_test.yml现在看起来像这样:
imports:
- { resource: config_dev.yml }
framework:
test: ~
session:
storage_id: session.storage.filesystem
liip_functional_test: ~
web_profiler:
toolbar: false
intercept_redirects: false
swiftmailer:
disable_delivery: true
liip_functional_test:
cache_sqlite_db: true
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db
Run Code Online (Sandbox Code Playgroud)
所以现在我有一个GenreTest类:
Liip没有文档所以我只是尝试了这样的方法.
use Liip\FunctionalTestBundle\Test\WebTestCase;
class GenreTest extends WebTestCase {
public function testInsert() {
$container = $this->getContainer();
$registry = $container->get('doctrine');
$em = $registry->getEntityManager(null);
$genre = new Genre();
$genre->setName("testGenre");
$em->persist($genre);
$em->flush();
$result = $em->createQuery("SELECT …Run Code Online (Sandbox Code Playgroud) php doctrine functional-testing symfony-2.1 liipfunctionaltestbundle
symfony ×3
php ×2
behat ×1
doctrine ×1
email ×1
fixtures ×1
swiftmailer ×1
symfony-2.1 ×1
testing ×1