public function setUp() { $this->storage = new Storage\Stub(); $storageManager = new StorageManager(); $storageManager->register($this->storage); $factoryManager = new FactoryManager(); $factoryManager->set('user', function ($values) { $user = new Fixtures\User(); $user->setUsername($values->get('username', 'John')); return $user; }); $factoryManager->set('article', function ($values) { $article = new Fixtures\Article(); $article->setTitle($values->get('title', 'The article')); $article->setAuthor($values->getRelation('author', 'user')); return $article; }); $this->environment = new Environment($factoryManager, $storageManager); }
public function testCreateCollection() { $users = array($foo = new \stdClass(), $bar = new \stdClass(), $baz = new \stdClass()); $factory = $this->getFactoryMock(); $factory->expects($this->exactly(3))->method('create')->with($this->isInstanceOf('Fixtures\\ValueProvider'))->will($this->onConsecutiveCalls($this->returnValue($foo), $this->returnValue($bar), $this->returnValue($baz))); $manager = new FactoryManager(); $manager->set('user', $factory); $context = new FactoryContext($manager); $this->assertEquals($users, $context->createCollection(3, 'user'), '->createCollection() returns the created fixtures collection'); $this->assertEquals($users, $context->getCreatedFixtures(), '->createCollection() adds all the created fixtures to the created fixtures list'); }
/** * @expectedException InvalidArgumentException */ public function testGetAnUndefinedFactory() { $manager = new FactoryManager(); $manager->set('foo', $this->getFactoryMock()); $manager->get('bar'); }