airmedia/phpunit-doctrine-extension 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

airmedia/phpunit-doctrine-extension

Composer 安装命令:

composer require --dev airmedia/phpunit-doctrine-extension

包简介

Provides the base TestCase for functional ORM/DB tests.

README 文档

README

Provides the base TestCase for functional ORM\DB tests.

Works with RDBMS:

  • PostgreSQL > 9.4
  • SQLite

Installation

$ composer require airmedia\phpunit-doctrine-extension --dev

Support PostgreSQL

For work with PostgreSQL you need to modify your configuration file (phpunit.xml) for PHPUnit. Add some variables to configure connection to PostgreSQL server. For example:

    <php>
        <var name="db_type" value="pdo_pgsql" />
        <var name="db_host" value="localhost" />
        <var name="db_username" value="postgres" />
        <var name="db_password" value="" />
        <var name="db_name" value="my_database_tests" />
        <var name="db_port" value="5432" />
    </php>

If these options are missing then will be used driver for SQLite as the fallback.

Usage

You must inherit from AirMedia\Test\OrmTestCase and implement createMappingDriver to provide configured mapping driver.

Also you may override the static field $customTypes to define the custom types for Doctrine.

Example:

<?php

use AirMedia\Test\ORMTestCase;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\ORM\Configuration;
use Ramsey\Uuid\Doctrine\UuidType;

class RepositoryTestCase extends ORMTestCase
{
    static protected $customTypes = [
        UuidType::NAME => UuidType::class,
    ];
    
    public function testAnything()
    {
        $repository = $this->em->getRepository('Acme\Entity\User');
        
        // Action and asserts...
    }
    
    protected function createMappingDriver(Configuration $config): MappingDriver
    {
        $annotationDriver = $config->newDefaultAnnotationDriver([
            realpath(__DIR__ . '/../src/Entity'),
        ], false);
        
        $driver = new MappingDriverChain();
        $driver->addDriver($annotationDriver, 'Acme\Entity');

        return $driver;
    }
}

Doctrine Data Fixtures Extension

You may populate your database throught the data fixtures using trait AirMedia\Test\Helper\DataFixturesTrait.

<?php

use AirMedia\Test\ORMTestCase;
use AirMedia\Test\Helper\DataFixturesTrait;

class FooTestCase extends ORMTestCase
{
    use DataFixturesTrait;
    
    protected function setUp()
    {
        parent::setUp();
        
        $this->loadFixtures([
            new \Acme\DataFixtures\UserFixture(),
            'Acme\DataFixtures\GroupFixture', // or class name
        ]);
    }
}

License

This package is licensed using the MIT License.

统计信息

  • 总下载量: 1.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固