Skip to content

Commit

Permalink
[Solr] fixed, console progress bar output during phpunit command
Browse files Browse the repository at this point in the history
  • Loading branch information
kilip committed Jul 6, 2016
1 parent 66b391f commit 58cb095
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
7 changes: 6 additions & 1 deletion module/Solr/src/Solr/Controller/ConsoleController.php
Expand Up @@ -40,7 +40,7 @@ public function activeJobIndexAction()
$jobs = $jobRepo->findActiveJob();
$count = $jobs->count();

$progressBar = new ProgressBar($count);
$progressBar = $this->createProgressBar($count);
$i = 1;
foreach($jobs as $job){
/* @var Job $job */
Expand All @@ -51,4 +51,9 @@ public function activeJobIndexAction()

return PHP_EOL;
}

protected function createProgressBar($count)
{
return new ProgressBar($count);
}
}
22 changes: 18 additions & 4 deletions module/Solr/test/SolrTest/Controller/ConsoleControllerTest.php
Expand Up @@ -9,6 +9,7 @@

namespace SolrTest\Controller;

use Core\Console\ProgressBar;
use Core\Repository\RepositoryService;
use Doctrine\MongoDB\CursorInterface;
use Jobs\Repository\Job;
Expand All @@ -26,9 +27,6 @@
*/
class ConsoleControllerTest extends \PHPUnit_Framework_TestCase
{
/**
* @outputBuffering enabled
*/
public function testActiveJobIndexAction()
{
$repositories = $this->getMockBuilder(RepositoryService::class)
Expand Down Expand Up @@ -82,8 +80,24 @@ public function testActiveJobIndexAction()
$jobSubscriber->expects($this->exactly(2))
->method('consoleIndex')
;
$progressBar = $this->getMockBuilder(ProgressBar::class)
->disableOriginalConstructor()
->getMock()
;
$progressBar->expects($this->exactly(2))
->method('update')
->withConsecutive([1, 'Job 1 / 2'],[2, 'Job 2 / 2'])
;

$target = new ConsoleController();
$target = $this->getMockBuilder(ConsoleController::class)
->setMethods(['createProgressBar'])
->getMock()
;
$target->expects($this->once())
->method('createProgressBar')
->with(2)
->willReturn($progressBar)
;
$target->setServiceLocator($sl);
$target->activeJobIndexAction();
}
Expand Down

0 comments on commit 58cb095

Please sign in to comment.