コード例 #1
0
ファイル: NodeManagerTest.php プロジェクト: clastic/clastic
 public function testLoadNodeWithType()
 {
     $node = new Node();
     $node->setType('nodeType');
     $nodeReferenceEntity = new NodeReferenceEntity();
     $repository = $this->getMockBuilder(ObjectRepository::class)->getMock();
     $repository->expects($this->once())->method('findOneBy')->willReturn($nodeReferenceEntity);
     $registry = $this->getMockBuilder(Registry::class)->disableOriginalConstructor()->getMock();
     $registry->expects($this->once())->method('getRepository')->with(null)->willReturn($repository);
     $dispatcher = $this->getMockBuilder(EventDispatcher::class)->getMock();
     $dispatcher->expects($this->once())->method('dispatch')->willReturnArgument(1);
     $manager = new NodeManager($dispatcher, $registry);
     $this->assertEquals($nodeReferenceEntity, $manager->loadNode(1, 'nodeType'));
 }
コード例 #2
0
ファイル: NodeManager.php プロジェクト: clastic/clastic
 /**
  * @param string $type
  *
  * @return NodeReferenceInterface
  *
  * @throws \Exception
  */
 public function createNode($type)
 {
     $node = new Node();
     $node->setType($type);
     $node->setCreated(new \DateTime());
     $event = new NodeCreateEvent($type, $node);
     $event = $this->dispatcher->dispatch(NodeEvents::CREATE, $event);
     $entity = $event->getEntity();
     if (!$entity) {
         throw new \Exception('Not found.');
     }
     $entity->setNode($event->getNode());
     $entity->getNode()->setPublication(new NodePublication());
     return $entity;
 }