rob-revisited/ide/tests/fixtures/test-wizard-expected/unit.php

63 lines
1.6 KiB
PHP

<?php
namespace App\Tests\Service;
use App\Service\Greeter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
final class GreeterTest extends TestCase
{
private MockObject&LoggerInterface $logger;
private Greeter $subject;
protected function setUp(): void
{
$this->logger = $this->createMock(LoggerInterface::class);
$this->subject = new Greeter($this->logger, 'greeting', 1);
}
public function testGreet(): void
{
// Arrange
$name = 'name';
$shout = true;
$this->logger->method('info')->willReturn(null);
// Act
$result = $this->subject->greet($name, $shout);
// Assert
self::assertSame('Hello Ada', $result);
}
#[DataProvider('greetShoutProvider')]
public function testGreetShout(string $name, bool $shout, mixed $expected): void
{
// Act
$result = $this->subject->greet($name, $shout);
// Assert
// TODO: assert what the method returned
self::assertSame($expected, $result);
}
public static function greetShoutProvider(): iterable
{
yield 'a case' => ['name', true, null];
}
public function testReset(): void
{
$this->expectException(\InvalidArgumentException::class);
// Act
$this->subject->reset();
}
public function testVersion(): void
{
// Act
$result = Greeter::version();
// Assert
self::assertSame(1, $result);
}
}