承接 firehed/mocktrine 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

firehed/mocktrine

最新稳定版本:0.7.0

Composer 安装命令:

composer require firehed/mocktrine

包简介

PHPUnit Doctrine mocking tools

README 文档

README

A Doctrine mocking library for testing

Latest Stable Version License Test Static analysis Lint

Usage

In your unit tests that need an Entity Manager, use a new \Firehed\Mocktrine\InMemoryEntityManager. Done!

Any object with Doctrine's entity annotations (@Entity, @Id, @Column, etc) should work without modification.

This library aims to provide as much type information as possible, so that static analysis tools (such as PHPStan) work well without additional plugins.

Mapping support

As of version 0.5, any mapping driver supported by Doctrine can be used with this library. The InMemoryEntityManager accepts the driver as an optional parameter.

- $em = new Mocktrine\InMemoryEntityManager();
+ $em = new Mocktrine\InMemoryEntityManager(
+     \Doctrine\ORM\Mapping\Driver\AttributeDriver(['src/Model']),
+ );

You can also grab the value directly from your Doctrine config:

$config = Setup::createAnnotationMetadataDriverConfiguration(...)
$driver = $config->getMetadataDriverImpl();
$em = new Mocktrine\InMemoryEntityManager($driver)

If a driver is not provided, it will default to either SimpleAnnotationReader or AnnotationReader that's used via Setup::createAnnotationMetadataConfiguration. The former will be preferred, but the class has been removed in doctrine/annotations:2.0; if your local dependencies allow that version then the latter will be used.

It is RECOMMENDED to always explicitly provide a driver, as that best matches Doctrine's own setup behavior. Future versions of this library may make this required.

Supported features

The following methods on Doctrine's EntityManagerInterface should all work as expected:

  • find
  • persist
  • remove
  • merge
  • flush
  • getRepository
  • getCache (will always return null)
  • isOpen (will always return true)

All methods on the ObjectRepository (for various findBy operations) should also work, as well as the non-interface count($criteria) method. ObjectRepository also implements the Selectable interface (as EntityRepository does, which is the returned type from EntityManager), so it's also possible to use the matching(Criteria) method.

The following methods are not supported at this time:

  • clear
  • detach
  • refresh
  • getClassMetadata
  • getMetadataFactory
  • initializeObject
  • contains
  • getConnection
  • getExpressionBuilder
  • beginTransaction
  • transactional
  • commit
  • rollback
  • createQuery
  • createNamedQuery
  • createNativeQuery
  • createNamedNativeQuery
  • getReference
  • getPartialReference
  • close
  • copy
  • lock
  • getEventManager
  • getConfiguration
  • getUnitOfWork
  • getHydrator
  • newHydrator
  • getProxyFactory
  • getFilters
  • isFiltersStateClean
  • hasFilters

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-08