php-sdk icon indicating copy to clipboard operation
php-sdk copied to clipboard

Define assertions directly from your test

Open pashak09 opened this issue 4 years ago • 2 comments

I want to be able to specify assertions directly in the test itself, not just in the .blackfire.yaml file.

You can see an example of a test below:

class BlackfireTest extends BlackfireTestCase
{
    use TestCaseTrait;

    protected const BLACKFIRE_SCENARIO_AUTO_START = false;

    /**
     * @group Blackfire
     *
     * @requires extension blackfire
     */
    public function testBlackfireSuccessesResponse()
    {
        $configuration = new Configuration();
        $configuration->assert('metrics.sql.queries.count == 1', 'SQL queries');
        $configuration->assert('metrics.http.requests.count == 1', 'HTTP Requests');
        $configuration->setUuid(Uuid::v4()->toRfc4122());

        $client = static::createBlackfiredHttpBrowserClient();
        $client->setConfiguration($configuration);

        $client->request(
            Request::METHOD_GET,
            '/blackfire?username=test',
            [],
            [],
            ['HTTP_ACCEPT' => 'application/json']
        );

        $this->assertBlackfireIsSuccessful($configuration);
    }
}

pashak09 avatar Sep 01 '21 17:09 pashak09

I also need this functionality. I am looking forward to your approval.

poprusha avatar Sep 08 '21 10:09 poprusha

I think it's a good idea to keep assertions and test code in one place.

Desgan avatar Sep 10 '21 11:09 Desgan