-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Labels
Description
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).
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?
trakos, romaricdrigon and pscheitOskarStark