-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
increase test coverage and fix a bug in TagSubscriberPass
- Loading branch information
Showing
14 changed files
with
416 additions
and
11 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
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
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
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
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
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
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
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,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSHttpCacheBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\HttpCacheBundle\Tests\Unit\Command; | ||
|
||
use FOS\HttpCacheBundle\Command\InvalidatePathCommand; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class BaseInvalidateCommandTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testContainerAccess() | ||
{ | ||
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager') | ||
->shouldReceive('invalidatePath')->once()->with('/my/path') | ||
->shouldReceive('invalidatePath')->once()->with('/other/path') | ||
->shouldReceive('invalidatePath')->once()->with('/another') | ||
->getMock() | ||
; | ||
$container = \Mockery::mock('\Symfony\Component\DependencyInjection\ContainerInterface') | ||
->shouldReceive('get')->once()->with('fos_http_cache.cache_manager')->andReturn($invalidator) | ||
->getMock() | ||
; | ||
|
||
$application = new Application(); | ||
$command = new InvalidatePathCommand(); | ||
$command->setContainer($container); | ||
$application->add($command); | ||
|
||
$command = $application->find('fos:httpcache:invalidate:path'); | ||
$commandTester = new CommandTester($command); | ||
$commandTester->execute(array( | ||
'command' => $command->getName(), | ||
'paths' => array('/my/path', '/other/path'), | ||
)); | ||
|
||
// the only output should be generated by the listener in verbose mode | ||
$this->assertEquals('', $commandTester->getDisplay()); | ||
|
||
// the cache manager is only fetched once | ||
$commandTester->execute(array( | ||
'command' => $command->getName(), | ||
'paths' => array('/another'), | ||
)); | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSHttpCacheBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\HttpCacheBundle\Tests\Unit\Configuration; | ||
|
||
use FOS\HttpCacheBundle\Command\InvalidatePathCommand; | ||
use FOS\HttpCacheBundle\Configuration\InvalidateRoute; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
/** | ||
* Test the @InvalidateRoute annotation. | ||
*/ | ||
class InvalidateRouteTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @expectedException \RuntimeException | ||
* @expectedExceptionMessage InvalidateRoute params must be an array | ||
*/ | ||
public function testExecuteInvalidParams() | ||
{ | ||
new InvalidateRoute(array( | ||
'name' => 'test', | ||
'params' => 'foo', | ||
)); | ||
} | ||
|
||
/** | ||
* @expectedException \RuntimeException | ||
* @expectedExceptionMessage InvalidateRoute param id must be string | ||
*/ | ||
public function testExecuteNoExpression() | ||
{ | ||
new InvalidateRoute(array( | ||
'name' => 'test', | ||
'params' => array( | ||
'id' => array( | ||
'this-is-not-expression' => 'something', | ||
) | ||
), | ||
)); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSHttpCacheBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\HttpCacheBundle\Tests\Unit\Configuration; | ||
|
||
use FOS\HttpCacheBundle\Configuration\Tag; | ||
|
||
/** | ||
* Test the @InvalidateRoute annotation. | ||
*/ | ||
class TagTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @expectedException \FOS\HttpCacheBundle\Exception\InvalidTagException | ||
* @expectedExceptionMessage is invalid because it contains , | ||
*/ | ||
public function testExecuteInvalidParams() | ||
{ | ||
new Tag(array( | ||
'tags' => array('foo,bar'), | ||
)); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
Tests/Unit/DependencyInjection/Compiler/HashGeneratorPassTest.php
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,83 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSHttpCacheBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\HttpCacheBundle\Tests\Unit\DependencyInjection\Compiler; | ||
|
||
use FOS\HttpCacheBundle\DependencyInjection\Compiler\HashGeneratorPass; | ||
use FOS\HttpCacheBundle\DependencyInjection\FOSHttpCacheExtension; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\DefinitionDecorator; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; | ||
|
||
class HashGeneratorPassTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var FOSHttpCacheExtension | ||
*/ | ||
private $extension; | ||
|
||
/** | ||
* @var HashGeneratorPass | ||
*/ | ||
private $userContextListenerPass; | ||
|
||
protected function setUp() | ||
{ | ||
$this->extension = new FOSHttpCacheExtension(); | ||
$this->userContextListenerPass = new HashGeneratorPass(); | ||
} | ||
|
||
/** | ||
* Nothing happens when user_context.hash_generator is not enabled | ||
*/ | ||
public function testConfigNoContext() | ||
{ | ||
$container = $this->createContainer(); | ||
$config = $this->getBaseConfig(); | ||
$this->extension->load(array($config), $container); | ||
$this->userContextListenerPass->process($container); | ||
$this->assertCount(9, $container->getDefinitions()); | ||
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException | ||
* @expectedExceptionMessage No user context providers found | ||
*/ | ||
public function testConfigNoProviders() | ||
{ | ||
$container = $this->createContainer(); | ||
$config = $this->getBaseConfig(); | ||
$config['user_context']['enabled'] = true; | ||
$this->extension->load(array($config), $container); | ||
$this->userContextListenerPass->process($container); | ||
} | ||
|
||
protected function createContainer() | ||
{ | ||
return new ContainerBuilder(new ParameterBag(array( | ||
'kernel.debug' => false, | ||
))); | ||
} | ||
|
||
protected function getBaseConfig() | ||
{ | ||
return array( | ||
'proxy_client' => array( | ||
'varnish' => array( | ||
'base_url' => 'my_hostname', | ||
'servers' => array( | ||
'127.0.0.1' | ||
) | ||
) | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.