mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 21:02:24 +03:00
Migrated to PHPUnit mocks in RobotsActionTest
This commit is contained in:
parent
4b958e8b87
commit
8cfa0b595c
6 changed files with 13 additions and 14 deletions
2
.github/actions/ci-setup/action.yml
vendored
2
.github/actions/ci-setup/action.yml
vendored
|
@ -41,7 +41,7 @@ runs:
|
|||
extensions: ${{ inputs.php-extensions }}
|
||||
coverage: pcov
|
||||
ini-values: pcov.directory=module
|
||||
- run: echo "::set-output name=composerArgs::${{ inputs.php-version == '8.2' && '--ignore-platform-req=php' || '' }}"
|
||||
- run: echo "::set-output name=composerArgs::${{ inputs.php-version == '8.2' && '--ignore-platform-req=php+' || '' }}"
|
||||
id: composer_args
|
||||
shell: bash
|
||||
- name: Install dependencies
|
||||
|
|
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -52,7 +52,7 @@ jobs:
|
|||
with:
|
||||
php-version: ${{ matrix.php-version }}
|
||||
tools: composer
|
||||
- run: echo "::set-output name=composerArgs::${{ matrix.php-version == '8.2' && '--ignore-platform-req=php' || '' }}"
|
||||
- run: echo "::set-output name=composerArgs::${{ matrix.php-version == '8.2' && '--ignore-platform-req=php+' || '' }}"
|
||||
id: composer_args
|
||||
shell: bash
|
||||
- run: composer install --no-interaction --prefer-dist ${{ steps.composer_args.outputs.composerArgs }}
|
||||
|
|
2
indocker
2
indocker
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Run docker containers if they are not up yet
|
||||
if ! [[ $(docker ps | grep shlink) ]]; then
|
||||
if ! [[ $(docker ps | grep shlink_swoole) ]]; then
|
||||
docker-compose up -d
|
||||
fi
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ use const PHP_EOL;
|
|||
|
||||
class RobotsAction implements RequestHandlerInterface, StatusCodeInterface
|
||||
{
|
||||
public function __construct(private CrawlingHelperInterface $crawlingHelper)
|
||||
public function __construct(private readonly CrawlingHelperInterface $crawlingHelper)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Shlinkio\Shlink\Core\Crawling;
|
|||
interface CrawlingHelperInterface
|
||||
{
|
||||
/**
|
||||
* @return string[]|iterable
|
||||
* @return iterable<string>
|
||||
*/
|
||||
public function listCrawlableShortCodes(): iterable;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue