mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 15:23:12 +08:00
Migrated to PHPUnit mocks in RobotsActionTest
This commit is contained in:
@@ -5,23 +5,20 @@ declare(strict_types=1);
|
||||
namespace ShlinkioTest\Shlink\Core\Action;
|
||||
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\Core\Action\RobotsAction;
|
||||
use Shlinkio\Shlink\Core\Crawling\CrawlingHelperInterface;
|
||||
|
||||
class RobotsActionTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
private RobotsAction $action;
|
||||
private ObjectProphecy $helper;
|
||||
private MockObject $helper;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->helper = $this->prophesize(CrawlingHelperInterface::class);
|
||||
$this->action = new RobotsAction($this->helper->reveal());
|
||||
$this->helper = $this->createMock(CrawlingHelperInterface::class);
|
||||
$this->action = new RobotsAction($this->helper);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,14 +27,16 @@ class RobotsActionTest extends TestCase
|
||||
*/
|
||||
public function buildsRobotsLinesFromCrawlableShortCodes(array $shortCodes, string $expected): void
|
||||
{
|
||||
$getShortCodes = $this->helper->listCrawlableShortCodes()->willReturn($shortCodes);
|
||||
$this->helper
|
||||
->expects($this->once())
|
||||
->method('listCrawlableShortCodes')
|
||||
->willReturn($shortCodes);
|
||||
|
||||
$response = $this->action->handle(ServerRequestFactory::fromGlobals());
|
||||
|
||||
self::assertEquals(200, $response->getStatusCode());
|
||||
self::assertEquals($expected, $response->getBody()->__toString());
|
||||
self::assertEquals('text/plain', $response->getHeaderLine('Content-Type'));
|
||||
$getShortCodes->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
public function provideShortCodes(): iterable
|
||||
|
||||
Reference in New Issue
Block a user