Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Controller\BrowserController;
use App\Controller\DashboardController;
use App\Controller\DomCrawlerController;
use App\Controller\ExternalApiController;
use App\Controller\FormController;
use App\Controller\HomeController;
use App\Controller\HttpClientController;
Expand All @@ -17,6 +18,10 @@
->controller(HomeController::class)
->methods(['GET']);

$routes->add('app_external_api', '/external-api')
->controller(ExternalApiController::class)
->methods(['GET']);

$routes->add('app_login', '/login')
->controller([SecurityController::class, 'login'])
->methods(['GET', 'POST']);
Expand Down
3 changes: 3 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@
'entity' => User::class,
'lazy' => true,
]);

$services->set(App\Service\ExternalApiStub::class)
->public();
};
22 changes: 22 additions & 0 deletions src/Controller/ExternalApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Controller;

use App\Service\ExternalApiStub;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

final class ExternalApiController extends AbstractController
{
public function __construct(
private readonly ExternalApiStub $externalApi,
) {
}

public function __invoke(): Response
{
return new Response($this->externalApi->getResponse());
}
}
25 changes: 25 additions & 0 deletions src/Service/ExternalApiStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Service;

/**
* A stand-in for an external API client whose response can be faked at runtime.
*/
final class ExternalApiStub
{
public const REAL_RESPONSE = 'Real API response';

private string $response = self::REAL_RESPONSE;

public function setFakeResponse(string $response): void
{
$this->response = $response;
}

public function getResponse(): string
{
return $this->response;
}
}
18 changes: 18 additions & 0 deletions tests/Functional/IssuesCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Doctrine\FlushCounterListener;
use App\Doctrine\RequestStackListener;
use App\Entity\User;
use App\Service\ExternalApiStub;
use App\Tests\Support\FunctionalTester;
use Doctrine\DBAL\Connection;
use Symfony\Component\Mime\Message;
Expand Down Expand Up @@ -132,4 +133,21 @@ public function ensureMessageObjectsCanBeFetched(FunctionalTester $I)
$I->assertEmailHeaderSame('Subject', 'Text message');
$I->assertInstanceOf(Message::class, $I->grabLastSentEmail());
}

/**
* @see https://github.com/Codeception/module-symfony/issues/130
*/
public function keepConfiguredServiceStateAcrossKernelReboot(FunctionalTester $I)
{
$I->amOnPage('/external-api');
$I->see(ExternalApiStub::REAL_RESPONSE);

/** @var ExternalApiStub $externalApi */
$externalApi = $I->grabService(ExternalApiStub::class);
$externalApi->setFakeResponse('Faked API response');
$I->persistService(ExternalApiStub::class);

$I->amOnPage('/external-api');
$I->see('Faked API response');
}
}