blackfireio / php-sdk

The Blackfire PHP SDK
https://blackfire.io
MIT License
150 stars 22 forks source link

Define assertions directly from your test #59

Closed pashak09 closed 1 year ago

pashak09 commented 3 years ago

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);
    }
}
poprusha commented 3 years ago

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

Desgan commented 3 years ago

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