コード例 #1
0
 /**
  * @param array $options
  * @dataProvider executeDataProvider
  */
 public function testExecute(array $options)
 {
     $context = new ItemStub(array());
     $attributeName = (string) $options['attribute'];
     $this->action->initialize($options);
     $this->action->execute($context);
     $this->assertNotNull($context->{$attributeName});
     $this->assertInstanceOf($options['class'], $context->{$attributeName});
     if ($context->{$attributeName} instanceof ItemStub) {
         /** @var ItemStub $entity */
         $entity = $context->{$attributeName};
         $expectedData = !empty($options['data']) ? $options['data'] : array();
         $this->assertInstanceOf($options['class'], $entity);
         $this->assertEquals($expectedData, $entity->getData());
     }
 }
コード例 #2
0
ファイル: CreateEntity.php プロジェクト: Maksold/platform
 /**
  * {@inheritdoc}
  */
 protected function createObject($context)
 {
     $entityClassName = $this->getObjectClassName();
     /** @var EntityManager $entityManager */
     $entityManager = $this->registry->getManagerForClass($entityClassName);
     if (!$entityManager) {
         throw new NotManageableEntityException($entityClassName);
     }
     $entity = parent::createObject($context);
     try {
         $entityManager->persist($entity);
         if ($this->doFlush()) {
             $entityManager->flush($entity);
         }
     } catch (\Exception $e) {
         throw new ActionException(sprintf('Can\'t create entity %s. %s', $entityClassName, $e->getMessage()));
     }
     return $entity;
 }