blackfireio / php-sdk

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

Add assert builder #60

Closed pashak09 closed 1 year ago

pashak09 commented 3 years ago

I think it would be nice to be able to set asserts using methods such as:

->sqlQueriesCountGreaterThanOrEqual(3)
->httpRequestsCountEquals(1)

In this PR I have implemented some of this functionality, if you think that this is a good idea that is worthy of attention, let me know, I will try to add an implementation for all possible assertions.

Usage example:

$configuration = new Configuration();
$assertBuilder = $configuration->getAssertBuilder();
$assertBuilder
    ->sqlQueriesCountGreaterThanOrEqual(1, 'test')
    ->httpRequestsCountEquals(1);

At the moment I have implemented the following assertions:

 for sql
 sqlQueriesCountGreaterThanOrEqual(int $expected, string|null $name = null)
 sqlQueriesCountLessThanOrEqual(int $expected, string|null $name = null)
 sqlQueriesCountGreaterThan(int $expected, string|null $name = null)
 sqlQueriesCountCountLessThan(int $expected, string|null $name = null)
 sqlQueriesCountNotEquals(int $expected, string|null $name = null)
 sqlQueriesCountEquals(int $expected, string|null $name = null)
 for http
 httpRequestsCountGreaterThanOrEqual(int $expected, string|null $name = null)
 httpRequestsCountLessThanOrEqual(int $expected, string|null $name = null)
 httpRequestsCountGreaterThan(int $expected, string|null $name = null)
 httpRequestsCountCountLessThan(int $expected, string|null $name = null)
 httpRequestsCountNotEquals(int $expected, string|null $name = null)
 httpRequestsCountEquals(int $expected, string|null $name = null)