Skip to content

Commit

Permalink
Adds methods 'loadAll' and 'store' to the LoadCrawler plugin
Browse files Browse the repository at this point in the history
(refs #14)
  • Loading branch information
TiSiE committed Oct 17, 2018
1 parent 5355703 commit 2ffcdbc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/Controller/Plugin/LoadCrawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use Zend\Mvc\Controller\Plugin\AbstractPlugin;

/**
* Plugin to load a crawler entity according to route parameters.
* Plugin to load all crawlers or one crawler entity according to route parameters.
*
* Provide a method to store a modified crawler.
*
* @author Mathias Gelhausen <[email protected]>
*/
Expand Down Expand Up @@ -62,4 +64,24 @@ public function __invoke()

return $crawler;
}

/**
* Loads all crawler entities.
*
* @return array|\SimpleImport\Entity\Crawler[]
*/
public function loadAll()
{
return $this->repository->findAll();
}

/**
* Stores a crawler entity
*
* @param \SimpleImport\Entity\Crawler $crawler
*/
public function store(\SimpleImport\Entity\Crawler $crawler)
{
$this->repository->store($crawler);
}
}
18 changes: 17 additions & 1 deletion test/SimpleImportTest/Controller/Plugin/LoadCrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function targetArgs()
{
$repository = $this->getMockBuilder(CrawlerRepository::class)
->disableOriginalConstructor()
->setMethods(['find', 'findOneByName'])
->setMethods(['find', 'findOneByName', 'findAll', 'store'])
->getMock();

$this->crawlerRepositoryMock = $repository;
Expand Down Expand Up @@ -132,4 +132,20 @@ public function testLoadsCrawler($name, $byId)

$this->assertSame($expected, $crawler);
}

public function testLoadsAllCrawler()
{
$this->crawlerRepositoryMock->expects($this->once())->method('findAll');

$this->target->loadAll();
}

public function testStoresACrawler()
{
$crawler = new Crawler();

$this->crawlerRepositoryMock->expects($this->once())->method('store')->with($crawler);

$this->target->store($crawler);
}
}

0 comments on commit 2ffcdbc

Please sign in to comment.