Inheritance: extends Neos\Flow\Persistence\Repository
 /**
  * @test
  */
 public function embeddablesInsideClonedProxiedEntitiesAreCorrectlyLoaded()
 {
     $this->markTestSkipped('This is possibly a bug of Doctrine');
     $entity = new Fixtures\TestEntity();
     $entity->setName('Andi');
     $relatedEntity = new Fixtures\TestEntity();
     $relatedEntity->setName('Robert');
     $embedded = new Fixtures\TestEmbeddable('Foo');
     $relatedEntity->setEmbedded($embedded);
     $valueObject = new Fixtures\TestValueObject('Bar');
     $relatedEntity->setRelatedValueObject($valueObject);
     $entity->setRelatedEntity($relatedEntity);
     $clonedRelatedEntity = clone $entity->getRelatedEntity();
     $this->assertNotNull($clonedRelatedEntity->getEmbedded(), 'Unproxied clone embedded is null');
     $this->testEntityRepository->add($entity);
     $this->testEntityRepository->add($relatedEntity);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $entityIdentifier = $this->persistenceManager->getIdentifierByObject($entity);
     $loadedEntity = $this->testEntityRepository->findByIdentifier($entityIdentifier);
     $clonedRelatedEntity = clone $loadedEntity->getRelatedEntity();
     $this->assertNotNull($clonedRelatedEntity->getRelatedValueObject(), 'Proxied clone value object is null');
     $this->assertNotNull($clonedRelatedEntity->getEmbedded(), 'Proxied clone embedded is null');
     $this->assertEquals('Foo', $clonedRelatedEntity->getEmbedded()->getValue());
 }
Beispiel #2
0
 /**
  * @test
  */
 public function aopIsCorrectlyInitializedEvenIfADoctrineProxyGetsInitializedOnTheFlyFromTheOutside()
 {
     $entity = new Fixtures\TestEntity();
     $entity->setName('Andi');
     $relatedEntity = new Fixtures\TestEntity();
     $relatedEntity->setName('Robert');
     $entity->setRelatedEntity($relatedEntity);
     $this->testEntityRepository->add($entity);
     $this->testEntityRepository->add($relatedEntity);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $entityIdentifier = $this->persistenceManager->getIdentifierByObject($entity);
     $loadedEntity = $this->testEntityRepository->findByIdentifier($entityIdentifier);
     $this->testEntityRepository->findOneByName('Robert');
     $loadedRelatedEntity = $loadedEntity->getRelatedEntity();
     $this->assertEquals($loadedRelatedEntity->sayHello(), 'Hello Andi!');
 }
 /**
  * @test
  */
 public function doctrineEmbeddablesAreActuallyEmbedded()
 {
     /* @var $entityManager ObjectManager */
     $entityManager = $this->objectManager->get(ObjectManager::class);
     $schemaTool = new SchemaTool($entityManager);
     $metaData = $entityManager->getClassMetadata(Fixtures\TestEntity::class);
     $this->assertTrue($metaData->hasField('embedded.value'), 'ClassMetadata does not contain embedded value');
     $schema = $schemaTool->getSchemaFromMetadata(array($metaData));
     $this->assertTrue($schema->getTable('persistence_testentity')->hasColumn('embedded_value'), 'Database schema does not contain embedded value field');
     $embeddable = new Fixtures\TestEmbeddable('someValue');
     $testEntity = new Fixtures\TestEntity();
     $testEntity->setEmbedded($embeddable);
     $this->testEntityRepository->add($testEntity);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     /* @var $testEntity Fixtures\TestEntity */
     $testEntity = $this->testEntityRepository->findAll()->getFirst();
     $this->assertEquals('someValue', $testEntity->getEmbedded()->getValue());
 }
 /**
  * @test
  */
 public function validationIsStoppedAtAggregateBoundaries()
 {
     $relatedEntity = new TestEntity();
     $relatedEntity->setName('Spy');
     $this->testEntityRepository->add($relatedEntity);
     $entity = new TestEntity();
     $entity->setName('Some Name');
     $entity->setRelatedEntity($relatedEntity);
     $this->testEntityRepository->add($entity);
     $this->persistenceManager->persistAll();
     $entityIdentifier = $this->persistenceManager->getIdentifierByObject($relatedEntity);
     /* @var $entityManager \Doctrine\ORM\EntityManagerInterface */
     $entityManager = ObjectAccess::getProperty($this->persistenceManager, 'entityManager', true);
     $dql = 'UPDATE ' . TestEntity::class . " e SET e.name = 'xx' WHERE e.Persistence_Object_Identifier = '{$entityIdentifier}'";
     $query = $entityManager->createQuery($dql);
     $query->getScalarResult();
     $this->persistenceManager->clearState();
     $entityIdentifier = $this->persistenceManager->getIdentifierByObject($entity);
     $invalidArguments = array('entity' => array('__identity' => $entityIdentifier, 'name' => 'Some other Name'));
     $response = $this->browser->request('http://localhost/test/validation/entity/update', 'POST', $invalidArguments);
     $this->assertNotSame('An error occurred while trying to call Neos\\Flow\\Tests\\Functional\\Mvc\\Fixtures\\Controller\\EntityController->updateAction().' . PHP_EOL . 'Error for entity.relatedEntity.name:  This field must contain at least 3 characters.' . PHP_EOL, $response->getContent());
     $this->assertSame(200, $response->getStatusCode());
 }
 /**
  * @param TestEntity $entity
  * @return string
  */
 public function updateAction(TestEntity $entity)
 {
     $this->testEntityRepository->update($entity);
     return sprintf('Entity "%s" updated', $entity->getName());
 }
 /**
  * @test
  */
 public function distinctQueryOnlyReturnsDistinctEntities()
 {
     $testEntityRepository = new Fixtures\TestEntityRepository();
     $testEntityRepository->removeAll();
     $testEntity = new Fixtures\TestEntity();
     $testEntity->setName('Flow');
     $subEntity1 = new Fixtures\SubEntity();
     $subEntity1->setContent('value');
     $subEntity1->setParentEntity($testEntity);
     $testEntity->addSubEntity($subEntity1);
     $this->persistenceManager->add($subEntity1);
     $subEntity2 = new Fixtures\SubEntity();
     $subEntity2->setContent('value');
     $subEntity2->setParentEntity($testEntity);
     $testEntity->addSubEntity($subEntity2);
     $this->persistenceManager->add($subEntity2);
     $testEntityRepository->add($testEntity);
     $testEntity2 = new Fixtures\TestEntity();
     $testEntity2->setName('Flow');
     $subEntity3 = new Fixtures\SubEntity();
     $subEntity3->setContent('value');
     $subEntity3->setParentEntity($testEntity2);
     $testEntity2->addSubEntity($subEntity3);
     $this->persistenceManager->add($subEntity3);
     $testEntityRepository->add($testEntity2);
     $this->persistenceManager->persistAll();
     $query = new Query(Fixtures\TestEntity::class);
     $entities = $query->matching($query->equals('subEntities.content', 'value'))->setDistinct()->setLimit(2)->execute()->toArray();
     $this->assertEquals(2, count($entities));
 }