forked from FriendsOfPHP/Sami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
147 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.