Skip to content

Commit

Permalink
Merge pull request #73 from WeareJH/symfony-progressbar-helper
Browse files Browse the repository at this point in the history
Use Symfony 2.5 ProgressBar Helper + allow option to set verbosity
  • Loading branch information
ddeboer committed Jun 2, 2014
2 parents d47ca9a + 33d485a commit 82697ee
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"phpoffice/phpexcel": "*",
"doctrine/dbal": "*",
"doctrine/orm": "*",
"symfony/console": ">=2.2,<2.5",
"symfony/console": "~2.5.0",
"symfony/validator": "~2.3.0"
},
"suggest": {
Expand Down
19 changes: 13 additions & 6 deletions src/Ddeboer/DataImport/Writer/ConsoleProgressWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Ddeboer\DataImport\Reader\ReaderInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\ProgressHelper;
use Symfony\Component\Console\Helper\ProgressBar;

/**
* Writes output to the Symfony2 console
Expand All @@ -16,16 +16,18 @@ class ConsoleProgressWriter extends AbstractWriter
protected $progress;
protected $workflow;

public function __construct(OutputInterface $output, ReaderInterface $reader)
public function __construct(OutputInterface $output, ReaderInterface $reader, $verbosity = 'debug')
{
$this->output = $output;
$this->progress = new ProgressHelper();
$this->reader = $reader;
$this->output = $output;
$this->reader = $reader;
$this->verbosity = $verbosity;
}

public function prepare()
{
$this->progress->start($this->output, $this->reader->count());
$this->progress = new ProgressBar($this->output, $this->reader->count());
$this->progress->setFormat($this->verbosity);
$this->progress->start();
}

public function writeItem(array $item)
Expand All @@ -37,4 +39,9 @@ public function finish()
{
$this->progress->finish();
}

public function getVerbosity()
{
return $this->verbosity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,26 @@ public function testWrite()
);
$reader = new ArrayReader($data);

$output = $this->getMockBuilder('\Symfony\Component\Console\Output\ConsoleOutput')
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
->getMock();

$outputFormatter = $this->getMock('Symfony\Component\Console\Formatter\OutputFormatterInterface');
$output->expects($this->once())
->method('isDecorated')
->will($this->returnValue(true));

$output->expects($this->atLeastOnce())
->method('getFormatter')
->will($this->returnValue($outputFormatter));

$output->expects($this->atLeastOnce())
->method('write');
$writer = new ConsoleProgressWriter($output, $reader);

$workflow = new Workflow($reader);
$workflow->addWriter($writer)
->process();

$this->assertEquals('debug', $writer->getVerbosity());
}
}

0 comments on commit 82697ee

Please sign in to comment.