mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 08:56:42 -06:00
Migrated ShlinkTableTest to use PHPUnit mocks
This commit is contained in:
parent
4cb44be9a0
commit
32417e40cb
@ -40,7 +40,7 @@ class ProcessRunnerTest extends TestCase
|
||||
$this->output->expects($this->exactly(2))->method('isVeryVerbose')->with()->willReturn(false);
|
||||
$this->output->expects($this->once())->method('isDebug')->with()->willReturn(false);
|
||||
$this->output->expects($this->never())->method('write');
|
||||
$this->process->expects($this->once())->method('mustRun')->withAnyParameters()->willReturn($this->process);
|
||||
$this->process->expects($this->once())->method('mustRun')->withAnyParameters()->willReturnSelf();
|
||||
$this->process->expects($this->never())->method('isSuccessful');
|
||||
$this->process->expects($this->never())->method('getCommandLine');
|
||||
$this->helper->expects($this->never())->method('wrapCallback');
|
||||
@ -56,7 +56,7 @@ class ProcessRunnerTest extends TestCase
|
||||
$this->output->expects($this->exactly(2))->method('isVeryVerbose')->with()->willReturn(true);
|
||||
$this->output->expects($this->once())->method('isDebug')->with()->willReturn(false);
|
||||
$this->output->expects($this->exactly(2))->method('write')->withAnyParameters();
|
||||
$this->process->expects($this->once())->method('mustRun')->withAnyParameters()->willReturn($this->process);
|
||||
$this->process->expects($this->once())->method('mustRun')->withAnyParameters()->willReturnSelf();
|
||||
$this->process->expects($this->exactly(2))->method('isSuccessful')->with()->willReturn(true);
|
||||
$this->process->expects($this->once())->method('getCommandLine')->with()->willReturn('true');
|
||||
$this->formatter->expects($this->once())->method('start')->withAnyParameters()->willReturn('');
|
||||
@ -72,7 +72,7 @@ class ProcessRunnerTest extends TestCase
|
||||
$this->output->expects($this->exactly(2))->method('isVeryVerbose')->with()->willReturn(false);
|
||||
$this->output->expects($this->once())->method('isDebug')->with()->willReturn(true);
|
||||
$this->output->expects($this->never())->method('write');
|
||||
$this->process->expects($this->once())->method('mustRun')->withAnyParameters()->willReturn($this->process);
|
||||
$this->process->expects($this->once())->method('mustRun')->withAnyParameters()->willReturnSelf();
|
||||
$this->process->expects($this->never())->method('isSuccessful');
|
||||
$this->process->expects($this->never())->method('getCommandLine');
|
||||
$this->helper->expects($this->once())->method('wrapCallback')->withAnyParameters()->willReturn(
|
||||
|
@ -4,10 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\CLI\Util;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use ReflectionObject;
|
||||
use Shlinkio\Shlink\CLI\Util\ShlinkTable;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
@ -16,15 +14,13 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ShlinkTableTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
private ShlinkTable $shlinkTable;
|
||||
private ObjectProphecy $baseTable;
|
||||
private MockObject $baseTable;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->baseTable = $this->prophesize(Table::class);
|
||||
$this->shlinkTable = ShlinkTable::fromBaseTable($this->baseTable->reveal());
|
||||
$this->baseTable = $this->createMock(Table::class);
|
||||
$this->shlinkTable = ShlinkTable::fromBaseTable($this->baseTable);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@ -35,29 +31,28 @@ class ShlinkTableTest extends TestCase
|
||||
$headerTitle = 'Header';
|
||||
$footerTitle = 'Footer';
|
||||
|
||||
$setStyle = $this->baseTable->setStyle(Argument::type(TableStyle::class))->willReturn(
|
||||
$this->baseTable->reveal(),
|
||||
);
|
||||
$setHeaders = $this->baseTable->setHeaders($headers)->willReturn($this->baseTable->reveal());
|
||||
$setRows = $this->baseTable->setRows($rows)->willReturn($this->baseTable->reveal());
|
||||
$setFooterTitle = $this->baseTable->setFooterTitle($footerTitle)->willReturn($this->baseTable->reveal());
|
||||
$setHeaderTitle = $this->baseTable->setHeaderTitle($headerTitle)->willReturn($this->baseTable->reveal());
|
||||
$render = $this->baseTable->render()->willReturn($this->baseTable->reveal());
|
||||
$this->baseTable->expects($this->once())->method('setStyle')->with(
|
||||
$this->isInstanceOf(TableStyle::class)
|
||||
)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setHeaders')->with(
|
||||
$this->equalTo($headers),
|
||||
)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setRows')->with($this->equalTo($rows))->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setFooterTitle')->with(
|
||||
$this->equalTo($footerTitle),
|
||||
)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('setHeaderTitle')->with(
|
||||
$this->equalTo($headerTitle),
|
||||
)->willReturnSelf();
|
||||
$this->baseTable->expects($this->once())->method('render')->with()->willReturnSelf();
|
||||
|
||||
$this->shlinkTable->render($headers, $rows, $footerTitle, $headerTitle);
|
||||
|
||||
$setStyle->shouldHaveBeenCalledOnce();
|
||||
$setHeaders->shouldHaveBeenCalledOnce();
|
||||
$setRows->shouldHaveBeenCalledOnce();
|
||||
$setFooterTitle->shouldHaveBeenCalledOnce();
|
||||
$setHeaderTitle->shouldHaveBeenCalledOnce();
|
||||
$render->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function newTableIsCreatedForFactoryMethod(): void
|
||||
{
|
||||
$instance = ShlinkTable::default($this->prophesize(OutputInterface::class)->reveal());
|
||||
$instance = ShlinkTable::default($this->createMock(OutputInterface::class));
|
||||
|
||||
$ref = new ReflectionObject($instance);
|
||||
$baseTable = $ref->getProperty('baseTable');
|
||||
|
Loading…
Reference in New Issue
Block a user