Skip to content

Commit

Permalink
Merge pull request #13 from Toflar/feature/sf2-autoload-unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Oct 29, 2014
2 parents 32163bb + 8711857 commit 6d86c86
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 21 deletions.
16 changes: 16 additions & 0 deletions tests/Test/Autoload/BundleAutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,21 @@ public function testInstanceOf()

$this->assertInstanceOf('Contao\Bundle\CoreBundle\Autoload\BundleAutoloader', $bundleLoader);
}

public function testLoad()
{
$bundleLoader = new BundleAutoloader(
__DIR__ . '/../../fixtures/Autoload/BundleAutoLoader/dummyRootDirName',
'all'
);

$this->assertSame(
[
'ContaoCoreBundle' => 'Contao\Bundle\CoreBundle\ContaoCoreBundle',
'legacy-module' => null
],
$bundleLoader->load()
);
}
}

81 changes: 60 additions & 21 deletions tests/Test/Autoload/JsonParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,75 @@ public function testInstanceOf()
$this->assertInstanceOf('Contao\Bundle\CoreBundle\Autoload\ParserInterface', $parser);
}

public function testParse()
public function testDefaultAutoload()
{
$parser = new JsonParser();
$normalized = [
$file = new SplFileInfo(
__DIR__ . '/../../fixtures/Autoload/JsonParser/regular/autoload.json'
, 'relativePath',
'relativePathName'
);

$this->assertSame([
'bundles' => [
'Contao\Bundle\CoreBundle\ContaoCoreBundle' => [
'class' => 'Contao\Bundle\CoreBundle\ContaoCoreBundle',
'name' => 'ContaoCoreBundle',
'replace' => [],
'environments' => ['all'],
'load-after' => []
]]
];
'class' => 'Contao\Bundle\CoreBundle\ContaoCoreBundle',
'name' => 'ContaoCoreBundle',
'replace' => [],
'environments' => ['all'],
'load-after' => []
]]
], $parser->parse($file));
}
public function testNoKeysDefinedAutoload()
{
$parser = new JsonParser();
$file = new SplFileInfo(
__DIR__ . '/../../fixtures/Autoload/JsonParser/no-keys-defined/autoload.json'
, 'relativePath',
'relativePathName'
);

$fileMock = $this->getMockBuilder('\Symfony\Component\Finder\SplFileInfo')
->setConstructorArgs([
'dummy', 'relativePath', 'relativePathName'
])
->getMock();
$this->assertSame([
'bundles' => [
'Contao\Bundle\CoreBundle\ContaoCoreBundle' => [
'class' => 'Contao\Bundle\CoreBundle\ContaoCoreBundle',
'name' => 'ContaoCoreBundle',
'replace' => [],
'environments' => ['all'],
'load-after' => []
]]
], $parser->parse($file));
}

$fileMock->expects($this->once())
->method('isFile')
->will($this->returnValue(true));
/**
* @expectedException \RuntimeException
*/
public function testInvalidJsonWillThrowException()
{
$parser = new JsonParser();
$file = new SplFileInfo(
__DIR__ . '/../../fixtures/Autoload/JsonParser/invalid/autoload.json'
, 'relativePath',
'relativePathName'
);

$fileMock->expects($this->once())
->method('getContents')
->will($this->returnValue(json_encode($normalized, true)));
$parser->parse($file);
}

/**
* @expectedException \RuntimeException
*/
public function testNoBundlesKeyInJsonWillThrowException()
{
$parser = new JsonParser();
$file = new SplFileInfo(
__DIR__ . '/../../fixtures/Autoload/JsonParser/no-bundles-key/autoload.json'
, 'relativePath',
'relativePathName'
);

$this->assertSame($normalized, $parser->parse($fileMock));
$parser->parse($file);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
requires[] = "core"
requires[] = "news"
requires[] = "*calendar"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"bundles": {
"Contao\\Bundle\\CoreBundle\\ContaoCoreBundle": {
"class": "Contao\\Bundle\\CoreBundle\\ContaoCoreBundle",
"name": "ContaoCoreBundle",
"replace": [],
"environments": ["all"],
"load-after" :[]
}
}
}
4 changes: 4 additions & 0 deletions tests/fixtures/Autoload/JsonParser/invalid/autoload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"bundles": {
"Contao\\Bundle\\CoreBundle\\ContaoCoreBundle": {
"I am invalid JSON
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"hey-there-is-no-bundles-key": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"bundles": {
"Contao\\Bundle\\CoreBundle\\ContaoCoreBundle": {
"class": "Contao\\Bundle\\CoreBundle\\ContaoCoreBundle",
"name": "ContaoCoreBundle"
}
}
}
11 changes: 11 additions & 0 deletions tests/fixtures/Autoload/JsonParser/regular/autoload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"bundles": {
"Contao\\Bundle\\CoreBundle\\ContaoCoreBundle": {
"class": "Contao\\Bundle\\CoreBundle\\ContaoCoreBundle",
"name": "ContaoCoreBundle",
"replace": [],
"environments": ["all"],
"load-after" :[]
}
}
}

0 comments on commit 6d86c86

Please sign in to comment.