2017 © Pedro Peláez
 

library mocktrine

A trait to make testing code using Doctrine easier

image

firehed/mocktrine

A trait to make testing code using Doctrine easier

  • Thursday, May 31, 2018
  • by Firehed
  • Repository
  • 1 Watchers
  • 0 Stars
  • 17 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Mocktrine

A Doctrine mocking library for testing, (*1)

Latest Stable Version License Test Static analysis Lint, (*2)

Usage

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

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

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

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., (*6)

- $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:, (*7)

$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., (*8)

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., (*9)

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), (*10)

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., (*11)

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, (*12)

The Versions

31/05 2018

dev-modernize

dev-modernize

A trait to make testing code using Doctrine easier

  Sources   Download

MIT

The Development Requires

by Eric Stern

mock testing doctrine mocking

08/10 2015

dev-master

9999999-dev

A trait to make testing code using Doctrine easier

  Sources   Download

MIT

The Development Requires

by Eric Stern

mock testing doctrine mocking

08/10 2015

0.2.0

0.2.0.0

A trait to make testing code using Doctrine easier

  Sources   Download

MIT

The Development Requires

by Eric Stern

mock testing doctrine mocking

08/10 2015

0.1.1

0.1.1.0

A trait to make testing code using Doctrine easier

  Sources   Download

MIT

The Development Requires

by Eric Stern

mock testing doctrine mocking

08/10 2015

0.1.0

0.1.0.0

A trait to make testing code using Doctrine easier

  Sources   Download

MIT

The Development Requires

by Eric Stern

mock testing doctrine mocking