blackfireio / php-sdk

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

PHPUnit integration is broken #34

Closed jakzal closed 6 years ago

jakzal commented 6 years ago

I followed https://blackfire.io/docs/integrations/phpunit to write a simple integration tests. I'm getting 0 tests failures out of 0 error back:

F

Time: 1.43 seconds, Memory: 4.00MB

There was 1 failure:

1) Zalas\Injector\Tests\Integration\ProfilerTest::testSomething
Failed asserting that Blackfire tests pass.
0 tests failures out of 0.

More information at https://blackfire.io/profiles/96353bf7-098f-4656-9d73-fef676ae5b91/graph?settings%5BtabPane%5D=assertions.

/project/vendor/blackfire/php-sdk/src/Blackfire/Bridge/PhpUnit/TestConstraint.php:60
/project/vendor/blackfire/php-sdk/src/Blackfire/Bridge/PhpUnit/TestConstraint.php:76
/project/vendor/blackfire/php-sdk/src/Blackfire/Bridge/PhpUnit/TestCaseTrait.php:49
/project/tests/Integration/ProfilerTest.php:46

FAILURES!
Tests: 1, Assertions: 3, Failures: 1.

Seems that Profile::$data is not populated with some needed details. For example, the report key is null:

array(12) {                                                                        [71/1913]
  ["id"]=>
  string(36) "4bc52e29-d578-49c3-8040-38c4ae173d0a"
  ["label"]=>
  string(0) ""
  ["created_at"]=>
  string(24) "2018-06-27T09:44:19+0000"
  ["updated_at"]=>
  string(24) "2018-06-27T09:44:20+0000"
  ["status"]=>
  array(4) {
    ["name"]=>
    string(8) "finished"
    ["code"]=>
    int(64)
    ["failure_reason"]=>
    NULL
    ["updated_at"]=>
    string(24) "2018-06-27T09:44:20+0000"
  }
  ["arguments"]=>
  NULL
  ["layers"]=>
  NULL
  ["report"]=>
  NULL
  ["recommendations"]=>
  NULL
  ["store"]=>
  array(0) {
  }
  ["_links"]=> { 
   // ...
  }

while Profile::isSuccessful() expects it:

    public function isSuccessful()
    {
        // ...

        return isset($this->data['report']['state']) && 'successful' === $this->data['report']['state'];
    }
composer show blackfire/php-sdk
name     : blackfire/php-sdk
versions : * v1.15.0
FROM php:7.2-cli

RUN  curl -A "Docker" -L https://packages.blackfire.io/binaries/blackfire-agent/1.17.1/blackfire-cli-linux_amd64 -o /usr/bin/blackfire \
    && chmod +x /usr/bin/blackfire \
    && curl -A "Docker" -L https://packages.blackfire.io/binaries/blackfire-php/1.21.0/blackfire-php-linux_amd64-php-72.so -o /tmp/blackfire.so \
    && mv /tmp/blackfire.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
    && printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini
iamluc commented 6 years ago

@jakzal thanks for your report. Could you share your phpunit test ?

I can reproduce the same output only if I comment all Blackfire assert:

    public function testSomething()
    {
        $config = new Profile\Configuration();

        // define some assertions
//        $config
//            ->assert('metrics.sql.queries.count < 1', 'SQL queries')
//            ->assert('metrics.twig.render.count < 3', 'Rendered Twig templates')
//            ->assert('metrics.twig.compile.count == 0', 'Twig compilation')
//        ;

        $profile = $this->assertBlackfire($config, function () {
            echo "done !";
        });
    }
jakzal commented 6 years ago

Indeed I haven't registered any assertions in my test as:

  1. I only have a free account at the moment.
  2. I only want to trigger profiling when this specific test is executed.
romainneutron commented 6 years ago

Hello, thanks again for reporting this. It has been fixed in latest release