Eko\FeedBundle\Service\FeedDumpService::dump PHP Method

dump() public method

Dumps a feed from an entity or feed items using Filesystem component.
public dump ( )
    public function dump()
    {
        if (!method_exists($this->filesystem, 'dumpFile')) {
            throw new \RuntimeException('Method dumpFile() is not available on your Filesystem component version, you should upgrade it.');
        }
        $this->initDirection();
        $feed = $this->feedManager->get($this->name);
        if ($this->entity) {
            $repository = $this->em->getRepository($this->entity);
            $items = $repository->findBy([], $this->orderBy, $this->limit);
            $feed->addFromArray($items);
        } elseif ($feed->hasItems()) {
            throw new \LogicException(sprintf('An entity should be set OR you should use setItems() first'));
        }
        $dump = $feed->render($this->format);
        $filepath = $this->rootDir . $this->filename;
        $this->filesystem->dumpFile($filepath, $dump);
    }

Usage Example

Beispiel #1
0
 /**
  * Tests the dump() method without any items or entity set.
  */
 public function testDumpWithoutItemsOrEntity()
 {
     if (!method_exists($this->filesystem, 'dumpFile')) {
         $this->markTestSkipped('Test skipped as Filesystem::dumpFile() is not available in this version.');
     }
     $this->setExpectedException('\\LogicException', 'An entity should be set OR you should use setItems() first');
     // Given
     $this->service->setRootDir('/unit/test/');
     $this->service->setFilename('feed.rss');
     $this->service->setDirection('ASC');
     $feed = $this->getMockBuilder('Eko\\FeedBundle\\Feed\\Feed')->disableOriginalConstructor()->getMock();
     $feed->expects($this->once())->method('hasItems')->will($this->returnValue(true));
     $this->feedManager->expects($this->once())->method('get')->will($this->returnValue($feed));
     // When - Expects exception
     $this->service->dump();
 }