diff --git a/composer.json b/composer.json index 48a8c4f..122e2d2 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "symfony/expression-language": "^2.7" }, "require-dev": { - "phpunit/phpunit": "4.8.*" + "phpunit/phpunit": "4.8.*", + "mikey179/vfsStream": "^1.0" }, "bin": ["bin/deprecation-detector"], "autoload": { diff --git a/composer.lock b/composer.lock index 47f7c65..3124a7c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,55 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "9e6c3b0f18e1265f8887eac427da82fc", - "content-hash": "13a91fb9ffa68f2ba28c400a08e6baed", + "hash": "2fd97b5f4aab66649dd2d818e5d51a5b", + "content-hash": "6e15ef62add11bbfee0cbe056d7f67f0", "packages": [ + { + "name": "mikey179/vfsStream", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/mikey179/vfsStream.git", + "reference": "73bcb605b741a7d5044b47592338c633788b0eb7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/73bcb605b741a7d5044b47592338c633788b0eb7", + "reference": "73bcb605b741a7d5044b47592338c633788b0eb7", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-0": { + "org\\bovigo\\vfs\\": "src/main/php" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Frank Kleine", + "homepage": "http://frankkleine.de/", + "role": "Developer" + } + ], + "description": "Virtual file system to mock the real file system in unit tests.", + "homepage": "http://vfs.bovigo.org/", + "time": "2015-10-06 16:59:57" + }, { "name": "nikic/php-parser", "version": "v1.4.1", diff --git a/tests/RuleSet/Loader/FileLoaderTest.php b/tests/RuleSet/Loader/FileLoaderTest.php index 6a39d08..232e736 100644 --- a/tests/RuleSet/Loader/FileLoaderTest.php +++ b/tests/RuleSet/Loader/FileLoaderTest.php @@ -2,14 +2,14 @@ namespace SensioLabs\DeprecationDetector\Tests\RuleSet\Loader; +use org\bovigo\vfs\vfsStream; +use SensioLabs\DeprecationDetector\RuleSet\RuleSet; + class FileLoaderTest extends \PHPUnit_Framework_TestCase { public function testClassIsInitializable() { - $dispatcher = $this->prophesize('Symfony\Component\EventDispatcher\EventDispatcher'); - $loader = new \SensioLabs\DeprecationDetector\RuleSet\Loader\FileLoader($dispatcher->reveal()); - - $this->assertInstanceOf('SensioLabs\DeprecationDetector\RuleSet\Loader\FileLoader', $loader); + $this->assertInstanceOf('SensioLabs\DeprecationDetector\RuleSet\Loader\FileLoader', $this->getInstance()); } /** @@ -18,15 +18,44 @@ public function testClassIsInitializable() */ public function testLoadingNotExistingFileThrowsAnException() { - $dispatcher = $this->prophesize('Symfony\Component\EventDispatcher\EventDispatcher'); - $loader = new \SensioLabs\DeprecationDetector\RuleSet\Loader\FileLoader($dispatcher->reveal()); - - $loader->loadRuleSet('no_such.file'); + $this->getInstance()->loadRuleSet('no_such.file'); } + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage Rule set file is not valid. + */ public function testLoadRuleSetThrowsExceptionIfCachedIsNotAnInstanceOfRuleset() { - //@TODO: file_get_contents is untestable - $this->markTestSkipped(); + $dummy = 'This is not a RuleSet'; + + $root = vfsStream::setup(); + $virtualFile = vfsStream::newFile('dummy') + ->withContent(serialize($dummy)) + ->at($root); + + $this->getInstance()->loadRuleSet($virtualFile->url()); + } + + public function testLoadRuleSetSuccess() + { + $ruleSet = new RuleSet(); + + $root = vfsStream::setup(); + $virtualFile = vfsStream::newFile('ruleSet') + ->withContent(serialize($ruleSet)) + ->at($root); + + $loader = $this->getInstance(); + + $actualRuleSet = $loader->loadRuleSet($virtualFile->url()); + + $this->assertInstanceOf('\SensioLabs\DeprecationDetector\RuleSet\RuleSet', $actualRuleSet); + } + + protected function getInstance() + { + $dispatcher = $this->prophesize('Symfony\Component\EventDispatcher\EventDispatcher'); + return new \SensioLabs\DeprecationDetector\RuleSet\Loader\FileLoader($dispatcher->reveal()); } }