2017 © Pedro Peláez
 

library factory

Provides object creation that makes mocking and good unit testing easy.

image

third-engine/factory

Provides object creation that makes mocking and good unit testing easy.

  • Saturday, November 21, 2015
  • by tonyvance
  • Repository
  • 2 Watchers
  • 0 Stars
  • 93 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

factory

Factory is used to create objects in a standard way that allow for easy replacement with test double from unit tests. This has only been tested with phpunit, but there isn't a reason it should not be able to work with other unit testing frameworks., (*1)

// This is equivalent to $newObject = new NewObjectClass(); in your normal code execution $newObject = Factory::createNewObject(NewObjectClass::class); $newObject->standardOperations();, (*2)

Then when you are in a unit test, there is a simple method to replace $newObject with a test double., (*3)

// $newObjectMock is already a mock object, and you want it to take the place of $newObject Factory::injectObject(NewObjectClass::class, $newObjectMock);, (*4)

In many cases, your constructors will take parameters. With Factory, it is simple to pass parameters to object constructors., (*5)

// This is equivalent to $newObject = new NewObjectClass($someOtherObject); $newObject = Factory::createNewObject(NewObjectClass::class, [$someOtherObject]); $newObject->standardOperations();, (*6)

Then when you are in a unit test, everything works the same way. $newObjectMock is already a mock object. Factory::injectObject(NewObjectClass::class, $newObjectMock);, (*7)

Factory also supports being able to create different instances of the same object. Many times you will need to create the same object in multiple methods., (*8)

$newObject1 = Factory::createNewObject(NewObjectClass::class);, (*9)

// a little while later 4newObject2 = Factory::createNewObject(NewObjectClass::class);, (*10)

// In your test, assuming $newObject1Mock and $newObject2Mock are mock objects already. Use a zero-based index // to order the injections you want. Factory::injectObject(NewObjectClass::class, $newObject1Mock, 0); Factory::injectObject(NewObjectClass::class, $newObject2Mock, 1);, (*11)

The Versions

21/11 2015

dev-master

9999999-dev https://github.com/ThirdEngine/Factory

Provides object creation that makes mocking and good unit testing easy.

  Sources   Download

MIT

The Requires

 

unit factory

21/11 2015

1.0.0

1.0.0.0 https://github.com/ThirdEngine/Factory

Provides object creation that makes mocking and good unit testing easy.

  Sources   Download

MIT

The Requires

 

unit factory