protected function setUp()
 {
     $this->meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->setMethods(['getName'])->getMock();
     $this->meta->expects($this->any())->method('getName')->will($this->returnValue('SR\\Doctrine\\ORM\\Id\\StringUuid4Generator'));
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->setMethods(['getClassMetadata', 'find'])->getMock();
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($this->meta));
     $this->em->expects($this->any())->method('find')->will($this->returnValue(null));
     $this->entity = $this->getMockBuilder('SR\\Doctrine\\ORM\\Mapping\\Entity')->getMock();
 }
 public function testFindOneBy()
 {
     $this->classMetadata->expects($this->once())->method('getFieldNames')->will($this->returnValue([$translatableField = 'translatable_field', $bothField = 'both_field']));
     $this->classMetadata->expects($this->once())->method('getAssociationMapping')->with($this->identicalTo('translations'))->will($this->returnValue(['targetEntity' => $translationClass = TranslationTest::class]));
     $translationClassMetadata = $this->createClassMetadataMock();
     $translationClassMetadata->expects($this->once())->method('getFieldNames')->will($this->returnValue([$translationField = 'translation_field', $bothField]));
     $this->entityManager->expects($this->once())->method('getClassMetadata')->with($this->identicalTo($translationClass))->will($this->returnValue($translationClassMetadata));
     $this->resource->expects($this->once())->method('getName')->will($this->returnValue($name = 'resource'));
     $this->entityManager->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($queryBuilder = $this->createQueryBuilderMock()));
     $queryBuilder->expects($this->once())->method('select')->with($this->identicalTo($name))->will($this->returnSelf());
     $queryBuilder->expects($this->once())->method('from')->with($this->identicalTo($this->class), $this->identicalTo($name), $this->isNull())->will($this->returnSelf());
     $queryBuilder->expects($this->once())->method('addSelect')->with($this->identicalTo('resource_translation'))->will($this->returnSelf());
     $queryBuilder->expects($this->exactly(5))->method('getRootAliases')->will($this->returnValue([$name]));
     $queryBuilder->expects($this->once())->method('leftJoin')->with($this->identicalTo($name . '.translations'), $this->identicalTo($translation = 'resource_translation'), $this->isNull(), $this->isNull(), $this->isNull())->will($this->returnSelf());
     $queryBuilder->expects($this->exactly(3))->method('expr')->will($this->returnValue($expr = $this->createExprMock()));
     $expr->expects($this->at(0))->method('eq')->with($this->identicalTo($name . '.' . $translatableField), $this->matchesRegularExpression('/:' . $name . '_' . $translatableField . '_[a-z0-9]{22}/'))->will($this->returnValue($translatableWhere = 'translatable_where'));
     $expr->expects($this->at(1))->method('eq')->with($this->identicalTo($translation . '.' . $translationField), $this->matchesRegularExpression('/:' . $translation . '_' . $translationField . '_[a-z0-9]{22}/'))->will($this->returnValue($translationWhere = 'translation_where'));
     $expr->expects($this->at(2))->method('eq')->with($this->identicalTo($name . '.' . $bothField), $this->matchesRegularExpression('/:' . $name . '_' . $bothField . '_[a-z0-9]{22}/'))->will($this->returnValue($bothWhere = 'both_where'));
     $queryBuilder->expects($this->exactly(3))->method('andWhere')->will($this->returnValueMap([[$translatableWhere, $queryBuilder], [$translationWhere, $queryBuilder], [$bothWhere, $queryBuilder]]));
     $queryBuilder->expects($this->at(9))->method('setParameter')->with($this->matchesRegularExpression('/' . $name . '_' . $translatableField . '_[a-z0-9]{22}/'), $this->identicalTo($translatableValue = 'translatable_value'), $this->isNull())->will($this->returnSelf());
     $queryBuilder->expects($this->at(13))->method('setParameter')->with($this->matchesRegularExpression('/' . $translation . '_' . $translationField . '_[a-z0-9]{22}/'), $this->identicalTo($translationValue = 'translation_value'), $this->isNull())->will($this->returnSelf());
     $queryBuilder->expects($this->at(17))->method('setParameter')->with($this->matchesRegularExpression('/' . $name . '_' . $bothField . '_[a-z0-9]{22}/'), $this->identicalTo($bothValue = 'both_value'), $this->isNull())->will($this->returnSelf());
     $queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($query = $this->createQueryMock()));
     $query->expects($this->once())->method('getOneOrNullResult')->will($this->returnValue($result = 'result'));
     $this->assertSame($result, $this->translatableRepository->findOneBy([$translatableField => $translatableValue, $translationField => $translationValue, $bothField => $bothValue]));
 }
 public function testTypeIsSetFromAssociation()
 {
     $map = array('fieldName' => 'var1', 'targetEntity' => '\\stdClass');
     $this->classMetadata->expects($this->any())->method('hasField')->will($this->returnValue(false));
     $this->classMetadata->expects($this->any())->method('hasAssociation')->will($this->returnValue(true));
     $this->classMetadata->expects($this->any())->method('getAssociationMapping')->will($this->returnValue($map));
     $meta = $this->object->load($this->testClass);
     $this->assertSame('\\stdClass', $meta['var1']->type);
 }