Skip to content

Client of WebTestCase throw error by test path like two slash '//' or more #46900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gorenstein opened this issue Jul 11, 2022 · 5 comments
Closed

Comments

@gorenstein
Copy link

gorenstein commented Jul 11, 2022

Symfony version(s) affected

4.4

Description

Client of WebTestCase throw error by test path like two slash '//' or more:
$client->request('GET', '//');

Error messages
php 7.4: array_replace(): Expected parameter 2 to be an array, bool given
php 8.1: TypeError: array_replace(): Argument #2 must be of type array, bool given

Example console output on php 8.1

$ bin/phpunit 
PHPUnit 9.5.21 #StandWithUkraine

Testing 
E                                                                   1 / 1 (100%)

Time: 00:00.113, Memory: 20.00 MB

There was 1 error:

1) App\Tests\BugTest::testSomething
TypeError: array_replace(): Argument #2 must be of type array, bool given

/home/xxxxxxx/sf44_full/vendor/symfony/browser-kit/CookieJar.php:185
/home/xxxxxxx/sf44_full/vendor/symfony/browser-kit/Client.php:393
/home/xxxxxxx/sf44_full/tests/BugTest.php:12

How to reproduce

<?php

namespace App\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class BugTest extends WebTestCase
{
    public function testSomething(): void
    {
        $client = static::createClient();
        $client->request('GET', '//');

        self::assertResponseStatusCodeSame(404);
    }
}

Possible Solution

No response

Additional Context

No response

@xabbuh
Copy link
Member

xabbuh commented Jul 11, 2022

see #46905 for a fix

@gorenstein
Copy link
Author

see #46905 for a fix
case with 3 or more slash is not covered by check on '//' !== $uri

  • $client->request('GET', '///'); throw error too

@alexislefebvre
Copy link
Contributor

Is $client->request('GET', '//'); a valid call? What behaviour is tested there? What is the expected result?

I would use $client->request('GET', '/'); to check the root of a website.

@gorenstein
Copy link
Author

gorenstein commented Jul 13, 2022

Is $client->request('GET', '//'); a valid call? What behaviour is tested there? What is the expected result?

I would use $client->request('GET', '/'); to check the root of a website.

What is the expected result?

As a Tester, I expect the Client of WebTestCase to return the same Response as the Browser receives from the App.

What behaviour is tested there?

As a Developer, I prefer not to use query parameters but rather use the ability for the Symfony Routing component to put data into the url path as a slug (/{slug1}/{slug2}/{slug3}/{slugN}).
Of course, it is possible that one or all Slugs are empty. The Symfony Routing component handles this situation correctly.
Of course, I want to write a unit-test for such a situation, but the Client of WebTestCase throw exception.

@xabbuh
Copy link
Member

xabbuh commented Jul 13, 2022

$client->request('GET', '///'); throw error too

addressed now too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants