MockHttpClient example

/** * @internal * * @covers \Shopware\Core\DevOps\System\Command\OpenApiValidationCommand */
class OpenApiValidationCommandTest extends TestCase
{
    public function testRunWithoutErrors(): void
    {
        $command = new OpenApiValidationCommand(
            new MockHttpClient([new SimpleMockedResponse('{"messages": [], "schemaValidationMessages": []}', [])]),
            $this->createMock(DefinitionService::class)
        );
        $tester = new CommandTester($command);

        $tester->execute([]);

        static::assertSame($tester->getStatusCode(), 0);
    }

    public function testRunWithErrors(): void
    {
        
use Symfony\Component\HttpClient\Response\MockResponse;

/** * @internal * * @covers \Shopware\WebInstaller\Services\ReleaseInfoProvider */
class ReleaseInfoProviderTest extends TestCase
{
    public function testGetReleaseInfo(): void
    {
        $mockClient = new MockHttpClient([
            new MockResponse(json_encode([
                '6.5.0.0-rc1',
                '6.4.20.0',
                '6.4.19.0',
                '6.4.18.0',
                '6.4.12.0',
                '6.4.11.0',
                '6.3.5.0',
            ], \JSON_THROW_ON_ERROR)),
        ]);

        
use Symfony\Component\HttpClient\Response\MockResponse;

/** * @internal * * @covers \Shopware\Core\Framework\Update\Services\ApiClient */
class ApiClientTest extends TestCase
{
    public function testCheckForUpdatesDisabled(): void
    {
        $client = new ApiClient(new MockHttpClient([]), false, '6.4.0.0', __DIR__);
        $version = $client->checkForUpdates();

        static::assertEmpty($version->version);
    }

    public function testCheckForUpdatesUsingEnv(): void
    {
        $_SERVER['SW_RECOVERY_NEXT_VERSION'] = '6.4.1.0';

        $client = new ApiClient(new MockHttpClient([]), true, '6.4.0.0', __DIR__);
        $version = $client->checkForUpdates();

        
Home | Imprint | This part of the site doesn't use cookies.