Skip to content

use class name constants instead of strings for mocks #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions Tests/Functional/Command/InvalidatePathCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Functional\Command;

use FOS\HttpCacheBundle\CacheManager;
use Symfony\Component\Console\Output\OutputInterface;

class InvalidatePathCommandTest extends CommandTestCase
Expand All @@ -20,7 +21,7 @@ public function testExecute()
$client = self::createClient();
$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidatePath')->once()->with('http://example.com/my/path')
Expand All @@ -37,7 +38,7 @@ public function testExecuteVerbose()
$client = self::createClient();
$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidatePath')->once()->with('http://example.com/my/path')
Expand Down
5 changes: 3 additions & 2 deletions Tests/Functional/Command/InvalidateRegexCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Functional\Command;

use FOS\HttpCacheBundle\CacheManager;
use Symfony\Component\Console\Output\OutputInterface;

class InvalidateRegexCommandTest extends CommandTestCase
Expand All @@ -20,7 +21,7 @@ public function testExecute()
$client = self::createClient();
$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidateRegex')->once()->with('/my.*/path')
Expand All @@ -36,7 +37,7 @@ public function testExecuteVerbose()
$client = self::createClient();
$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidateRegex')->once()->with('/my.*/path')
Expand Down
5 changes: 3 additions & 2 deletions Tests/Functional/Command/InvalidateTagCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Functional\Command;

use FOS\HttpCacheBundle\CacheManager;
use Symfony\Component\Console\Output\OutputInterface;

class InvalidateTagCommandTest extends CommandTestCase
Expand All @@ -20,7 +21,7 @@ public function testExecute()
$client = self::createClient();
$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidate')->once()->with(array('X-Cache-Tags' => '(my\\-tag|other\\-tag)(,.+)?$'))
Expand All @@ -36,7 +37,7 @@ public function testExecuteVerbose()
$client = self::createClient();
$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidate')->once()->with(array('X-Cache-Tags' => '(my\\-tag|other\\-tag)(,.+)?$'))
Expand Down
5 changes: 3 additions & 2 deletions Tests/Functional/Command/RefreshPathCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Functional\Command;

use FOS\HttpCacheBundle\CacheManager;
use Symfony\Component\Console\Output\OutputInterface;

class RefreshPathCommandTest extends CommandTestCase
Expand All @@ -20,7 +21,7 @@ public function testExecute()
$client = self::createClient();
$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('refreshPath')->once()->with('http://example.com/my/path')
Expand All @@ -37,7 +38,7 @@ public function testExecuteVerbose()
$client = self::createClient();
$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('refreshPath')->once()->with('http://example.com/my/path')
Expand Down
7 changes: 4 additions & 3 deletions Tests/Functional/EventListener/InvalidationListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Functional\EventListener;

use FOS\HttpCacheBundle\CacheManager;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class InvalidationListenerTest extends WebTestCase
Expand All @@ -21,7 +22,7 @@ public function testInvalidateRoute()

$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidateRoute')->once()->with('test_noncached', array())
Expand All @@ -42,7 +43,7 @@ public function testInvalidatePath($statusCode)

$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidatePath')->once()->with('/cached')
Expand All @@ -61,7 +62,7 @@ public function testErrorIsNotInvalidated()

$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidatePath')->never()
Expand Down
7 changes: 4 additions & 3 deletions Tests/Functional/EventListener/TagListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Functional\EventListener;

use FOS\HttpCacheBundle\CacheManager;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class TagListenerTest extends WebTestCase
Expand All @@ -34,7 +35,7 @@ public function testAnnotationTagsAreInvalidated()

$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidate')->with(array('X-Cache-Tags' => '(all\\-items)(,.+)?$'))
Expand All @@ -51,7 +52,7 @@ public function testErrorIsNotInvalidated()

$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidate')->never()
Expand All @@ -76,7 +77,7 @@ public function testConfigurationTagsAreInvalidated()

$client->getContainer()->mock(
'fos_http_cache.cache_manager',
'\FOS\HttpCacheBundle\CacheManager'
CacheManager::class
)
->shouldReceive('supports')->andReturn(true)
->shouldReceive('invalidate')->once()->with(array('X-Cache-Tags' => '(area|area\\-51)(,.+)?$'))
Expand Down
3 changes: 2 additions & 1 deletion Tests/Functional/Fixtures/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* file that was distributed with this source code.
*/

use FOS\HttpCacheBundle\Tests\Functional\Fixtures\Session\TestSessionStorage;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
Expand Down Expand Up @@ -77,7 +78,7 @@ protected function prepareContainer(\Symfony\Component\DependencyInjection\Conta

$container->setDefinition(
'session.test_storage',
new \Symfony\Component\DependencyInjection\Definition('FOS\HttpCacheBundle\Tests\Functional\Fixtures\Session\TestSessionStorage')
new \Symfony\Component\DependencyInjection\Definition(TestSessionStorage::class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Functional\Security\Http\Logout;

use FOS\HttpCache\ProxyClient\Varnish;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Cookie;

Expand All @@ -21,7 +22,7 @@ public function testLogout()
$client = static::createClient();
$client->getContainer()->mock(
'fos_http_cache.proxy_client.varnish',
'\FOS\HttpCache\ProxyClient\Varnish'
Varnish::class
)
->shouldReceive('ban')->once()->with(array('accept' => 'application/vnd.fos.user-context-hash', 'Cookie' => '.*test.*'))
->shouldReceive('ban')->once()->with(array('accept' => 'application/vnd.fos.user-context-hash', 'Authorization' => '.*test.*'))
Expand Down
3 changes: 2 additions & 1 deletion Tests/Functional/Test/ProxyTestCaseAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Functional\Test;

use FOS\HttpCache\Test\Proxy\VarnishProxy;
use FOS\HttpCacheBundle\Test\ProxyTestCase;

class ProxyTestCaseAnnotationTest extends ProxyTestCase
Expand All @@ -19,7 +20,7 @@ protected function setUp()
{
static::getContainer()->mock(
'fos_http_cache.test.default_proxy_server',
'\FOS\HttpCache\Test\Proxy\VarnishProxy'
VarnishProxy::class
)
->shouldReceive('clear')->once()
;
Expand Down
3 changes: 2 additions & 1 deletion Tests/Functional/Test/ProxyTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Functional\Test;

use FOS\HttpCache\Test\Proxy\VarnishProxy;
use FOS\HttpCacheBundle\Test\ProxyTestCase;

class ProxyTestCaseTest extends ProxyTestCase
Expand All @@ -19,7 +20,7 @@ protected function setUp()
{
static::getContainer()->mock(
'fos_http_cache.test.default_proxy_server',
'\FOS\HttpCache\Test\Proxy\VarnishProxy'
VarnishProxy::class
);

parent::setUp();
Expand Down
14 changes: 9 additions & 5 deletions Tests/Unit/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

namespace FOS\HttpCacheBundle\Tests\Unit;

use FOS\HttpCache\ProxyClient\Invalidation\BanInterface;
use FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface;
use FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface;
use FOS\HttpCache\ProxyClient\ProxyClientInterface;
use FOS\HttpCacheBundle\CacheManager;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
Expand All @@ -21,12 +25,12 @@ class CacheManagerTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->proxyClient = \Mockery::mock('\FOS\HttpCache\ProxyClient\ProxyClientInterface');
$this->proxyClient = \Mockery::mock(ProxyClientInterface::class);
}

public function testInvalidateRoute()
{
$httpCache = \Mockery::mock('\FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface')
$httpCache = \Mockery::mock(PurgeInterface::class)
->shouldReceive('purge')->once()->with('/my/route', array())
->shouldReceive('purge')->once()->with('/route/with/params/id/123', array())
->shouldReceive('purge')->once()->with('/route/with/params/id/123', array('X-Foo' => 'bar'))
Expand All @@ -53,7 +57,7 @@ public function testInvalidateRoute()

public function testRefreshRoute()
{
$httpCache = \Mockery::mock('\FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface')
$httpCache = \Mockery::mock(RefreshInterface::class)
->shouldReceive('refresh')->once()->with('/my/route', null)
->shouldReceive('refresh')->once()->with('/route/with/params/id/123', null)
->shouldReceive('refresh')->once()->with('/route/with/params/id/123', array('X-Foo' => 'bar'))
Expand Down Expand Up @@ -84,8 +88,8 @@ public function testRefreshRoute()
*/
public function testTagResponse()
{
$ban = \Mockery::mock('\FOS\HttpCache\ProxyClient\Invalidation\BanInterface');
$router = \Mockery::mock('\Symfony\Component\Routing\Generator\UrlGeneratorInterface');
$ban = \Mockery::mock(BanInterface::class);
$router = \Mockery::mock(UrlGeneratorInterface::class);

$tags1 = array('post-1', 'posts');
$tags2 = array('post-2');
Expand Down
3 changes: 2 additions & 1 deletion Tests/Unit/Command/BaseInvalidateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Unit\Command;

use FOS\HttpCacheBundle\CacheManager;
use FOS\HttpCacheBundle\Command\InvalidatePathCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
Expand All @@ -19,7 +20,7 @@ class BaseInvalidateCommandTest extends \PHPUnit_Framework_TestCase
{
public function testContainerAccess()
{
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager')
$invalidator = \Mockery::mock(CacheManager::class)
->shouldReceive('invalidatePath')->once()->with('/my/path')
->shouldReceive('invalidatePath')->once()->with('/other/path')
->shouldReceive('invalidatePath')->once()->with('/another')
Expand Down
5 changes: 3 additions & 2 deletions Tests/Unit/Command/InvalidatePathCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Unit\Command;

use FOS\HttpCacheBundle\CacheManager;
use FOS\HttpCacheBundle\Command\InvalidatePathCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
Expand All @@ -22,7 +23,7 @@ class InvalidatePathCommandTest extends \PHPUnit_Framework_TestCase
*/
public function testExecuteMissingParameters()
{
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager');
$invalidator = \Mockery::mock(CacheManager::class);

$application = new Application();
$application->add(new InvalidatePathCommand($invalidator));
Expand All @@ -34,7 +35,7 @@ public function testExecuteMissingParameters()

public function testExecuteParameter()
{
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager')
$invalidator = \Mockery::mock(CacheManager::class)
->shouldReceive('invalidatePath')->once()->with('/my/path')
->shouldReceive('invalidatePath')->once()->with('/other/path')
->getMock()
Expand Down
5 changes: 3 additions & 2 deletions Tests/Unit/Command/InvalidateRegexCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\HttpCacheBundle\Tests\Unit\Command;

use FOS\HttpCacheBundle\CacheManager;
use FOS\HttpCacheBundle\Command\InvalidateRegexCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
Expand All @@ -22,7 +23,7 @@ class InvalidateRegexCommandTest extends \PHPUnit_Framework_TestCase
*/
public function testExecuteNoParameters()
{
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager');
$invalidator = \Mockery::mock(CacheManager::class);

$application = new Application();
$application->add(new InvalidateRegexCommand($invalidator));
Expand All @@ -34,7 +35,7 @@ public function testExecuteNoParameters()

public function testExecuteParameter()
{
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager')
$invalidator = \Mockery::mock(CacheManager::class)
->shouldReceive('invalidateRegex')->once()->with('/my.*/path')
->getMock()
;
Expand Down
5 changes: 3 additions & 2 deletions Tests/Unit/Command/InvalidateTagCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FOS\HttpCacheBundle\Tests\Unit\Command;

use FOS\HttpCacheBundle\Command\InvalidateTagCommand;
use FOS\HttpCacheBundle\Handler\TagHandler;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

Expand All @@ -22,7 +23,7 @@ class InvalidateTagCommandTest extends \PHPUnit_Framework_TestCase
*/
public function testExecuteMissingParameters()
{
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\Handler\TagHandler');
$invalidator = \Mockery::mock(TagHandler::class);

$application = new Application();
$application->add(new InvalidateTagCommand($invalidator));
Expand All @@ -34,7 +35,7 @@ public function testExecuteMissingParameters()

public function testExecuteParameter()
{
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\Handler\TagHandler')
$invalidator = \Mockery::mock(TagHandler::class)
->shouldReceive('invalidateTags')->once()->with(array('my-tag'))
->getMock()
;
Expand Down
Loading