Skip to content

Commit

Permalink
added some BF tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Oct 16, 2015
1 parent 0a526ff commit 42f95a7
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 9 deletions.
78 changes: 78 additions & 0 deletions Sami/Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Sami\Tests;

use Blackfire\Client;
use Blackfire\Profile;
use Sami\Sami;
use Symfony\Component\Filesystem\Filesystem;

class IntegrationTest extends \PHPUnit_Framework_TestCase
{
private $bf;
private $sami;

protected function setUp()
{
$dir = sys_get_temp_dir().'/sami_integ';
$this->clearCache($dir);

$this->sami = new Sami(dirname(__DIR__).'/Console', array(
'build_dir' => $dir.'/build',
'cache_dir' => $dir.'/cache',
));
}

protected function tearDown()
{
$this->clearCache(sys_get_temp_dir().'/sami_integ');
}

/**
* @group blackfire
* @requires extension blackfire
* @dataProvider getStorageData
*/
public function testStorage($primedCache, $writeCalls, $readCalls)
{
$sami = $this->sami;

if ($primedCache) {
// prime the cache
$sami['project']->parse();
}

$config = new Profile\Configuration();
$config
->defineMetric(new Profile\Metric('sami.storage.write_calls', array('=Sami\Store\JsonStore::writeClass')))
->defineMetric(new Profile\Metric('sami.storage.read_calls', array('=Sami\Reflection\ClassReflection::fromArray')))
->assert('metrics.sami.storage.write_calls.count == '.$writeCalls, $writeCalls.' write calls')
// depending on the order in which classes are loaded, we might have an extra call
->assert('metrics.sami.storage.read_calls.count <= '.$readCalls, $readCalls.' read calls')
;

$profile = $this->getBlackfireClient()->assertPhpUnit($this, $config, function () use ($sami) {
$sami['project']->parse();
});
}

public function getStorageData()
{
return array(
array(true, 0, 6),
array(false, 5, 0),
);
}

private function getBlackfireClient()
{
return null !== $this->bf ? $this->bf : $this->bf = new Client();
}

private function clearCache()
{
$dir = sys_get_temp_dir().'/sami_integ';
$fs = new Filesystem();
$fs->remove($dir);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"symfony/filesystem": "~2.1",
"symfony/yaml": "~2.1",
"symfony/process": "~2.1",
"phpdocumentor/reflection-docblock": "~2.0"
"phpdocumentor/reflection-docblock": "~2.0",
"blackfire/php-sdk": "dev-php-sdk-plus"
},
"autoload": {
"psr-4": { "Sami\\": "Sami/" }
Expand Down
75 changes: 67 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 42f95a7

Please sign in to comment.