Skip to content

[FrameworkBundle] Proposal: make BrowserKitAssertionsTrait::getClient/getRequest/getResponse protected #40817

@mmarton

Description

@mmarton

Description
I would like to create my own set of assertions and phpunit constraints like BrowserKitAssertionsTrait does.
For this it would be nice to have access from my testcase (wich extends WebTestCase) to the getClient/getRequest/getResponse methods (which are currently privates).

https://github.com/symfony/symfony/blob/5.x/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php#L149

That way I wouldn't have to pass the $kernelBrowser to the assertions.

Example

class XYControllerTest extends WebTestCase
{
    use ProfilerAssertionTrait;

    public function testIndex(): void
    {
        $client = static::createClient();
        $client->enableProfiler();
        $client->request('GET', '/index');

        self::assertResponseIsSuccessful(); // inherited, has access to getClient
        self::assertNoMissingTranslation($client); // no access here, have to pass $client
    }
}

trait ProfilerAssertionTrait
{
    public static function assertNoMissingTranslation(KernelBrowser $client, string $message = ''): void
    {
        $translationCollector = $client->getProfile()->getCollector('translation');

        self::assertEquals(0, $translationCollector->getCountMissings());
    }
    
    public static function assertNoMissingTranslationIfIHadAccessToClient(string $message = ''): void
    {
        $translationCollector = self::getClient()->getProfile()->getCollector('translation');

        self::assertEquals(0, $translationCollector->getCountMissings());
    }
}

WDYT?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions