|
@@ -2,16 +2,13 @@
|
|
|
namespace App\Tests\Service\Cron\UI;
|
|
namespace App\Tests\Service\Cron\UI;
|
|
|
|
|
|
|
|
use App\Service\Cron\UI\ConsoleUI;
|
|
use App\Service\Cron\UI\ConsoleUI;
|
|
|
|
|
+use PHPUnit\Framework\MockObject\MockObject;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
-
|
|
|
|
|
-class MockableProgressBar {
|
|
|
|
|
- public function setProgress(int $step): void {}
|
|
|
|
|
- public function setMaxSteps(int $max): void {}
|
|
|
|
|
-}
|
|
|
|
|
|
|
+use Symfony\Component\Console\Helper\ProgressBar;
|
|
|
|
|
|
|
|
class TestableConsoleUI extends ConsoleUI {
|
|
class TestableConsoleUI extends ConsoleUI {
|
|
|
- public function setProgressBar(MockableProgressBar $progressBar): void
|
|
|
|
|
|
|
+ public function setProgressBar(ProgressBar $progressBar): void
|
|
|
{
|
|
{
|
|
|
$this->progressBar = $progressBar;
|
|
$this->progressBar = $progressBar;
|
|
|
}
|
|
}
|
|
@@ -23,15 +20,24 @@ class ConsoleUITest extends TestCase
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
public function setUp(): void
|
|
|
{
|
|
{
|
|
|
|
|
+ \DG\BypassFinals::enable();
|
|
|
$this->output = $this->getMockBuilder(OutputInterface::class)->disableOriginalConstructor()->getMock();
|
|
$this->output = $this->getMockBuilder(OutputInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function testPrint(): void
|
|
|
|
|
- {
|
|
|
|
|
- $consoleUI = $this->getMockBuilder(ConsoleUI::class)
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param list<string> $methodNames
|
|
|
|
|
+ * @return TestableConsoleUI | MockObject
|
|
|
|
|
+ */
|
|
|
|
|
+ private function getConsoleUiMockFor(array $methodNames): TestableConsoleUI | MockObject {
|
|
|
|
|
+ return $this->getMockBuilder(TestableConsoleUI::class)
|
|
|
->setConstructorArgs([$this->output])
|
|
->setConstructorArgs([$this->output])
|
|
|
- ->setMethodsExcept(['print'])
|
|
|
|
|
|
|
+ ->setMethodsExcept($methodNames)
|
|
|
->getMock();
|
|
->getMock();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function testPrint(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $consoleUI = $this->getConsoleUiMockFor(['print']);
|
|
|
|
|
|
|
|
$this->output->expects(self::once())->method('writeln')->with('foo');
|
|
$this->output->expects(self::once())->method('writeln')->with('foo');
|
|
|
|
|
|
|
@@ -39,7 +45,8 @@ class ConsoleUITest extends TestCase
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function testProgress(): void {
|
|
public function testProgress(): void {
|
|
|
- $progressBar = $this->getMockBuilder(MockableProgressBar::class)->getMock();
|
|
|
|
|
|
|
+ /** @var ProgressBar | MockObject $progressBar */
|
|
|
|
|
+ $progressBar = $this->getMockBuilder(ProgressBar::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
$consoleUI = $this->getMockBuilder(TestableConsoleUI::class)
|
|
$consoleUI = $this->getMockBuilder(TestableConsoleUI::class)
|
|
|
->setConstructorArgs([$this->output])
|
|
->setConstructorArgs([$this->output])
|
|
@@ -58,12 +65,11 @@ class ConsoleUITest extends TestCase
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function testProgressEnd(): void {
|
|
public function testProgressEnd(): void {
|
|
|
- $progressBar = $this->getMockBuilder(MockableProgressBar::class)->getMock();
|
|
|
|
|
|
|
+ /** @var ProgressBar | MockObject $progressBar */
|
|
|
|
|
+ $progressBar = $this->getMockBuilder(ProgressBar::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+
|
|
|
|
|
+ $consoleUI = $this->getConsoleUiMockFor(['progress', 'setProgressBar']);
|
|
|
|
|
|
|
|
- $consoleUI = $this->getMockBuilder(TestableConsoleUI::class)
|
|
|
|
|
- ->setConstructorArgs([$this->output])
|
|
|
|
|
- ->setMethodsExcept(['progress', 'setProgressBar'])
|
|
|
|
|
- ->getMock();
|
|
|
|
|
$consoleUI->setProgressBar($progressBar);
|
|
$consoleUI->setProgressBar($progressBar);
|
|
|
|
|
|
|
|
$progressBar->expects(self::once())
|
|
$progressBar->expects(self::once())
|