Skip to content

Commit

Permalink
Added some GearmanParser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoreram committed Dec 22, 2013
1 parent 577e056 commit 88758b2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 6 deletions.
103 changes: 99 additions & 4 deletions Tests/Service/GearmanParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Mmoreram\GearmanBundle\Tests\Service;

use Mmoreram\GearmanBundle\Module\WorkerCollection;

/**
* Tests JobClassTest class
*/
Expand Down Expand Up @@ -81,7 +83,7 @@ public function testGetFileClassNamespaceSingle()
->setMethods(null)
->getMock();

$this->assertEquals('My\File\Namespace\SingleCleanFile', $gearmanParser->getFileClassNamespace($mockNamespace));
$this->assertEquals('Mmoreram\GearmanBundle\Tests\Service\Mocks\SingleCleanFile', $gearmanParser->getFileClassNamespace($mockNamespace));
}


Expand All @@ -98,7 +100,7 @@ public function testGetFileClassNamespaceCommented()
->setMethods(null)
->getMock();

$this->assertEquals('My\File\Namespace\SingleCommentedFile', $gearmanParser->getFileClassNamespace($mockNamespace));
$this->assertEquals('Mmoreram\GearmanBundle\Tests\Service\Mocks\SingleCommentedFile', $gearmanParser->getFileClassNamespace($mockNamespace));
}


Expand Down Expand Up @@ -210,8 +212,9 @@ public function testLoadNamespaceMapExcludes()
public function testLoadNamespaceMapBoth()
{

$this->bundleMock
->expects($this->any())
$this
->bundleMock
->expects($this->once())
->method('getPath')
->will($this->returnValue($this->bundlePath));

Expand Down Expand Up @@ -247,4 +250,96 @@ public function testLoadNamespaceMapBoth()
'libs',
));
}


/**
* Testing parseNamespaceMap with empty paths
*/
public function testParseNamespaceMapEmptyPaths()
{
$paths = array();
$excludedPaths = array();

$reader = $this
->getMockBuilder('\Doctrine\Common\Annotations\Reader')
->disableOriginalConstructor()
->getMock();

$finder = $this
->getMockBuilder('\Symfony\Component\Finder\Finder')
->disableOriginalConstructor()
->setMethods(array(
'files',
))
->getMock();

$finder
->expects($this->any())
->method('getPath');

$workerCollection = $this
->gearmanParser
->parseNamespaceMap($finder, $reader, $paths, $excludedPaths);

$this->assertEquals($workerCollection, new workerCollection());
}


/**
* Testing parseNamespaceMap with some paths
*/
public function testParseNamespaceMapSomePaths()
{
$this->gearmanParser = $this
->getMockBuilder('\Mmoreram\GearmanBundle\Service\GearmanParser')
->disableOriginalConstructor()
->setMethods(array(
'parseFiles',
))
->getMock();

$paths = array(
dirname(__FILE__) . '/Mocks/',

);
$excludedPaths = array();

$reader = $this
->getMockBuilder('\Doctrine\Common\Annotations\SimpleAnnotationReader')
->setMethods(null)
->getMock();

$finder = $this
->getMockBuilder('\Symfony\Component\Finder\Finder')
->setMethods(null)
->getMock();

$this
->gearmanParser
->expects($this->once())
->method('parseFiles')
->with(
$this->equalTo($finder),
$this->equalTo($reader),
$this->equalTo(new WorkerCollection)
);

$workerCollection = $this
->gearmanParser
->parseNamespaceMap($finder, $reader, $paths, $excludedPaths);

$this->assertEquals($workerCollection, new workerCollection());
}












}
2 changes: 1 addition & 1 deletion Tests/Service/Mocks/SingleCleanFile.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace My\File\Namespace;
namespace Mmoreram\GearmanBundle\Tests\Service\Mocks;

/**
* Doc
Expand Down
2 changes: 1 addition & 1 deletion Tests/Service/Mocks/SingleCommentedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Marc Morera
*/

namespace My\File\Namespace;
namespace Mmoreram\GearmanBundle\Tests\Service\Mocks;

/**
* Some class comments
Expand Down

0 comments on commit 88758b2

Please sign in to comment.