Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"pimple/pimple": "~3.0",
"symfony/dependency-injection": "^2.7",
"symfony/config": "^2.7",
"symfony/expression-language": "^2.7"
"symfony/expression-language": "^2.7",
"mikey179/vfsStream": "^1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a dev dependency.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, corrected

},
"require-dev": {
"phpunit/phpunit": "4.8.*"
Expand Down
50 changes: 48 additions & 2 deletions composer.lock

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

49 changes: 39 additions & 10 deletions tests/RuleSet/Loader/FileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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());
}
}