コード例 #1
0
 public function testFixtureName()
 {
     $model = new Post();
     $model->setId(22);
     $metadata = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
     $metadata->expects($this->once())->method('getName')->will($this->returnValue('Acme\\Demo\\Entity\\Post'));
     $result = $this->namingStrategy->fixtureName($metadata);
     $this->assertEquals('LoadPostData', $result);
 }
コード例 #2
0
 public function testGenerate()
 {
     $author = new Author();
     $author->setId(2);
     $author->setUsername('Username');
     $post1 = new Post();
     $post1->setId(10);
     $post1->setDescription('Description');
     $post1->setTitle('Title');
     $post1->setCreated(new \DateTime("2012-12-12 12:12:12"));
     $post1->setAuthor($author);
     $post2 = new Post();
     $post2->setId(11);
     $post2->setDescription('Description2');
     $post2->setTitle('Title2');
     $post2->setCreated(new \DateTime("2012-12-12 12:12:12"));
     $post2->setAuthor($author);
     $models = array($post1, $post2);
     $fieldNames = array('description', 'title', 'created');
     $associationNames = array('author');
     $classMetadata = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
     $classMetadata->expects($this->any())->method('getName')->will($this->returnValue('Sp\\FixtureDumper\\Tests\\Fixture\\Post'));
     $classMetadata->expects($this->any())->method('getFieldNames')->will($this->returnValue($fieldNames));
     $classMetadata->expects($this->any())->method('isSingleValuedAssociation')->will($this->returnValue(true));
     $classMetadata->expects($this->any())->method('getAssociationNames')->will($this->returnValue($associationNames));
     $classMetadata->expects($this->any())->method('getAssociationTargetClass')->with($this->equalTo('author'))->will($this->returnValue('Sp\\FixtureDumper\\Tests\\Generator\\Fixture\\Author'));
     $classMetadata->expects($this->any())->method('getIdentifierValues')->will($this->returnCallback(function ($model) {
         return array('id' => $model->getId());
     }));
     $authorClassMetadata = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
     $authorClassMetadata->expects($this->any())->method('getName')->will($this->returnValue('Sp\\FixtureDumper\\Tests\\Generator\\Fixture\\Author'));
     $authorClassMetadata->expects($this->any())->method('getIdentifierValues')->will($this->returnCallback(function ($model) {
         return array('id' => $model->getId());
     }));
     $this->repository->expects($this->once())->method('findAll')->will($this->returnValue($models));
     $this->manager->expects($this->once())->method('getRepository')->will($this->returnValue($this->repository));
     $this->manager->expects($this->any())->method('getClassMetadata')->with($this->equalTo('Sp\\FixtureDumper\\Tests\\Generator\\Fixture\\Author'))->will($this->returnValue($authorClassMetadata));
     $output = $this->generator->generate($classMetadata, null, $this->getOptions());
     $this->assertEquals($this->getContent('post_data'), $output);
 }