enlitepro/enlite-test

测试辅助工具

dev-master 2013-09-03 13:01 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:13:16 UTC


README

修改 TestConfig.php.dist 文件,并将全局路径选项更改为

'config_glob_paths' => array(
    'config/autoload/{,*.}{global,local}.php',
    __DIR__ . "/global.php"
)

test 目录附近创建文件 glob.php,并包含如下选项

<?php

return array(
    'doctrine' => array(
        'connection' => array(
            'orm_default' => array(
                'driverClass' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver',
                'params' => array(
                    'memory' => true
                ),
            )
        ),
    ),
);

现在在你的测试中可以使用真实数据库

<?php

class SomeTest extends \PHPUnit_Framework_TestCase
{
    use \EnliteTest\DatabaseFixtureTrait;

    public function testSave()
    {
        $entity = new Some();
        $entity->setTitle('hello');

        $em = $this->getEntityManager();
        $em->persist($entity);
        $em->flush();

        $this->assertSame($entity, $em->getRepository('Some')->find($entity->getId()));
    }

}