Skip to content

Commit 181a03f

Browse files
authored
Merge pull request #320 from FriendsOfSymfony/class-constants
use class name constants instead of strings for mocks
2 parents 536c735 + 73dbf61 commit 181a03f

22 files changed

+85
-61
lines changed

Tests/Functional/Command/InvalidatePathCommandTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Functional\Command;
1313

14+
use FOS\HttpCacheBundle\CacheManager;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

1617
class InvalidatePathCommandTest extends CommandTestCase
@@ -20,7 +21,7 @@ public function testExecute()
2021
$client = self::createClient();
2122
$client->getContainer()->mock(
2223
'fos_http_cache.cache_manager',
23-
'\FOS\HttpCacheBundle\CacheManager'
24+
CacheManager::class
2425
)
2526
->shouldReceive('supports')->andReturn(true)
2627
->shouldReceive('invalidatePath')->once()->with('http://example.com/my/path')
@@ -37,7 +38,7 @@ public function testExecuteVerbose()
3738
$client = self::createClient();
3839
$client->getContainer()->mock(
3940
'fos_http_cache.cache_manager',
40-
'\FOS\HttpCacheBundle\CacheManager'
41+
CacheManager::class
4142
)
4243
->shouldReceive('supports')->andReturn(true)
4344
->shouldReceive('invalidatePath')->once()->with('http://example.com/my/path')

Tests/Functional/Command/InvalidateRegexCommandTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Functional\Command;
1313

14+
use FOS\HttpCacheBundle\CacheManager;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

1617
class InvalidateRegexCommandTest extends CommandTestCase
@@ -20,7 +21,7 @@ public function testExecute()
2021
$client = self::createClient();
2122
$client->getContainer()->mock(
2223
'fos_http_cache.cache_manager',
23-
'\FOS\HttpCacheBundle\CacheManager'
24+
CacheManager::class
2425
)
2526
->shouldReceive('supports')->andReturn(true)
2627
->shouldReceive('invalidateRegex')->once()->with('/my.*/path')
@@ -36,7 +37,7 @@ public function testExecuteVerbose()
3637
$client = self::createClient();
3738
$client->getContainer()->mock(
3839
'fos_http_cache.cache_manager',
39-
'\FOS\HttpCacheBundle\CacheManager'
40+
CacheManager::class
4041
)
4142
->shouldReceive('supports')->andReturn(true)
4243
->shouldReceive('invalidateRegex')->once()->with('/my.*/path')

Tests/Functional/Command/InvalidateTagCommandTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Functional\Command;
1313

14+
use FOS\HttpCacheBundle\CacheManager;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

1617
class InvalidateTagCommandTest extends CommandTestCase
@@ -20,7 +21,7 @@ public function testExecute()
2021
$client = self::createClient();
2122
$client->getContainer()->mock(
2223
'fos_http_cache.cache_manager',
23-
'\FOS\HttpCacheBundle\CacheManager'
24+
CacheManager::class
2425
)
2526
->shouldReceive('supports')->andReturn(true)
2627
->shouldReceive('invalidate')->once()->with(array('X-Cache-Tags' => '(my\\-tag|other\\-tag)(,.+)?$'))
@@ -36,7 +37,7 @@ public function testExecuteVerbose()
3637
$client = self::createClient();
3738
$client->getContainer()->mock(
3839
'fos_http_cache.cache_manager',
39-
'\FOS\HttpCacheBundle\CacheManager'
40+
CacheManager::class
4041
)
4142
->shouldReceive('supports')->andReturn(true)
4243
->shouldReceive('invalidate')->once()->with(array('X-Cache-Tags' => '(my\\-tag|other\\-tag)(,.+)?$'))

Tests/Functional/Command/RefreshPathCommandTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Functional\Command;
1313

14+
use FOS\HttpCacheBundle\CacheManager;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

1617
class RefreshPathCommandTest extends CommandTestCase
@@ -20,7 +21,7 @@ public function testExecute()
2021
$client = self::createClient();
2122
$client->getContainer()->mock(
2223
'fos_http_cache.cache_manager',
23-
'\FOS\HttpCacheBundle\CacheManager'
24+
CacheManager::class
2425
)
2526
->shouldReceive('supports')->andReturn(true)
2627
->shouldReceive('refreshPath')->once()->with('http://example.com/my/path')
@@ -37,7 +38,7 @@ public function testExecuteVerbose()
3738
$client = self::createClient();
3839
$client->getContainer()->mock(
3940
'fos_http_cache.cache_manager',
40-
'\FOS\HttpCacheBundle\CacheManager'
41+
CacheManager::class
4142
)
4243
->shouldReceive('supports')->andReturn(true)
4344
->shouldReceive('refreshPath')->once()->with('http://example.com/my/path')

Tests/Functional/EventListener/InvalidationListenerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Functional\EventListener;
1313

14+
use FOS\HttpCacheBundle\CacheManager;
1415
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1516

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

2223
$client->getContainer()->mock(
2324
'fos_http_cache.cache_manager',
24-
'\FOS\HttpCacheBundle\CacheManager'
25+
CacheManager::class
2526
)
2627
->shouldReceive('supports')->andReturn(true)
2728
->shouldReceive('invalidateRoute')->once()->with('test_noncached', array())
@@ -42,7 +43,7 @@ public function testInvalidatePath($statusCode)
4243

4344
$client->getContainer()->mock(
4445
'fos_http_cache.cache_manager',
45-
'\FOS\HttpCacheBundle\CacheManager'
46+
CacheManager::class
4647
)
4748
->shouldReceive('supports')->andReturn(true)
4849
->shouldReceive('invalidatePath')->once()->with('/cached')
@@ -61,7 +62,7 @@ public function testErrorIsNotInvalidated()
6162

6263
$client->getContainer()->mock(
6364
'fos_http_cache.cache_manager',
64-
'\FOS\HttpCacheBundle\CacheManager'
65+
CacheManager::class
6566
)
6667
->shouldReceive('supports')->andReturn(true)
6768
->shouldReceive('invalidatePath')->never()

Tests/Functional/EventListener/TagListenerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Functional\EventListener;
1313

14+
use FOS\HttpCacheBundle\CacheManager;
1415
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1516

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

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

5253
$client->getContainer()->mock(
5354
'fos_http_cache.cache_manager',
54-
'\FOS\HttpCacheBundle\CacheManager'
55+
CacheManager::class
5556
)
5657
->shouldReceive('supports')->andReturn(true)
5758
->shouldReceive('invalidate')->never()
@@ -76,7 +77,7 @@ public function testConfigurationTagsAreInvalidated()
7677

7778
$client->getContainer()->mock(
7879
'fos_http_cache.cache_manager',
79-
'\FOS\HttpCacheBundle\CacheManager'
80+
CacheManager::class
8081
)
8182
->shouldReceive('supports')->andReturn(true)
8283
->shouldReceive('invalidate')->once()->with(array('X-Cache-Tags' => '(area|area\\-51)(,.+)?$'))

Tests/Functional/Fixtures/app/AppKernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12+
use FOS\HttpCacheBundle\Tests\Functional\Fixtures\Session\TestSessionStorage;
1213
use Symfony\Component\Config\Loader\LoaderInterface;
1314
use Symfony\Component\DependencyInjection\ContainerBuilder;
1415
use Symfony\Component\HttpKernel\Kernel;
@@ -77,7 +78,7 @@ protected function prepareContainer(\Symfony\Component\DependencyInjection\Conta
7778

7879
$container->setDefinition(
7980
'session.test_storage',
80-
new \Symfony\Component\DependencyInjection\Definition('FOS\HttpCacheBundle\Tests\Functional\Fixtures\Session\TestSessionStorage')
81+
new \Symfony\Component\DependencyInjection\Definition(TestSessionStorage::class)
8182
);
8283
}
8384
}

Tests/Functional/Security/Http/Logout/ContextInvalidationLogoutHandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

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

14+
use FOS\HttpCache\ProxyClient\Varnish;
1415
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1516
use Symfony\Component\BrowserKit\Cookie;
1617

@@ -21,7 +22,7 @@ public function testLogout()
2122
$client = static::createClient();
2223
$client->getContainer()->mock(
2324
'fos_http_cache.proxy_client.varnish',
24-
'\FOS\HttpCache\ProxyClient\Varnish'
25+
Varnish::class
2526
)
2627
->shouldReceive('ban')->once()->with(array('accept' => 'application/vnd.fos.user-context-hash', 'Cookie' => '.*test.*'))
2728
->shouldReceive('ban')->once()->with(array('accept' => 'application/vnd.fos.user-context-hash', 'Authorization' => '.*test.*'))

Tests/Functional/Test/ProxyTestCaseAnnotationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Functional\Test;
1313

14+
use FOS\HttpCache\Test\Proxy\VarnishProxy;
1415
use FOS\HttpCacheBundle\Test\ProxyTestCase;
1516

1617
class ProxyTestCaseAnnotationTest extends ProxyTestCase
@@ -19,7 +20,7 @@ protected function setUp()
1920
{
2021
static::getContainer()->mock(
2122
'fos_http_cache.test.default_proxy_server',
22-
'\FOS\HttpCache\Test\Proxy\VarnishProxy'
23+
VarnishProxy::class
2324
)
2425
->shouldReceive('clear')->once()
2526
;

Tests/Functional/Test/ProxyTestCaseTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Functional\Test;
1313

14+
use FOS\HttpCache\Test\Proxy\VarnishProxy;
1415
use FOS\HttpCacheBundle\Test\ProxyTestCase;
1516

1617
class ProxyTestCaseTest extends ProxyTestCase
@@ -19,7 +20,7 @@ protected function setUp()
1920
{
2021
static::getContainer()->mock(
2122
'fos_http_cache.test.default_proxy_server',
22-
'\FOS\HttpCache\Test\Proxy\VarnishProxy'
23+
VarnishProxy::class
2324
);
2425

2526
parent::setUp();

Tests/Unit/CacheManagerTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Unit;
1313

14+
use FOS\HttpCache\ProxyClient\Invalidation\BanInterface;
15+
use FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface;
16+
use FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface;
17+
use FOS\HttpCache\ProxyClient\ProxyClientInterface;
1418
use FOS\HttpCacheBundle\CacheManager;
1519
use Symfony\Component\HttpFoundation\Response;
1620
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -21,12 +25,12 @@ class CacheManagerTest extends \PHPUnit_Framework_TestCase
2125

2226
public function setUp()
2327
{
24-
$this->proxyClient = \Mockery::mock('\FOS\HttpCache\ProxyClient\ProxyClientInterface');
28+
$this->proxyClient = \Mockery::mock(ProxyClientInterface::class);
2529
}
2630

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

5458
public function testRefreshRoute()
5559
{
56-
$httpCache = \Mockery::mock('\FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface')
60+
$httpCache = \Mockery::mock(RefreshInterface::class)
5761
->shouldReceive('refresh')->once()->with('/my/route', null)
5862
->shouldReceive('refresh')->once()->with('/route/with/params/id/123', null)
5963
->shouldReceive('refresh')->once()->with('/route/with/params/id/123', array('X-Foo' => 'bar'))
@@ -84,8 +88,8 @@ public function testRefreshRoute()
8488
*/
8589
public function testTagResponse()
8690
{
87-
$ban = \Mockery::mock('\FOS\HttpCache\ProxyClient\Invalidation\BanInterface');
88-
$router = \Mockery::mock('\Symfony\Component\Routing\Generator\UrlGeneratorInterface');
91+
$ban = \Mockery::mock(BanInterface::class);
92+
$router = \Mockery::mock(UrlGeneratorInterface::class);
8993

9094
$tags1 = array('post-1', 'posts');
9195
$tags2 = array('post-2');

Tests/Unit/Command/BaseInvalidateCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Unit\Command;
1313

14+
use FOS\HttpCacheBundle\CacheManager;
1415
use FOS\HttpCacheBundle\Command\InvalidatePathCommand;
1516
use Symfony\Component\Console\Application;
1617
use Symfony\Component\Console\Tester\CommandTester;
@@ -19,7 +20,7 @@ class BaseInvalidateCommandTest extends \PHPUnit_Framework_TestCase
1920
{
2021
public function testContainerAccess()
2122
{
22-
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager')
23+
$invalidator = \Mockery::mock(CacheManager::class)
2324
->shouldReceive('invalidatePath')->once()->with('/my/path')
2425
->shouldReceive('invalidatePath')->once()->with('/other/path')
2526
->shouldReceive('invalidatePath')->once()->with('/another')

Tests/Unit/Command/InvalidatePathCommandTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Unit\Command;
1313

14+
use FOS\HttpCacheBundle\CacheManager;
1415
use FOS\HttpCacheBundle\Command\InvalidatePathCommand;
1516
use Symfony\Component\Console\Application;
1617
use Symfony\Component\Console\Tester\CommandTester;
@@ -22,7 +23,7 @@ class InvalidatePathCommandTest extends \PHPUnit_Framework_TestCase
2223
*/
2324
public function testExecuteMissingParameters()
2425
{
25-
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager');
26+
$invalidator = \Mockery::mock(CacheManager::class);
2627

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

3536
public function testExecuteParameter()
3637
{
37-
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager')
38+
$invalidator = \Mockery::mock(CacheManager::class)
3839
->shouldReceive('invalidatePath')->once()->with('/my/path')
3940
->shouldReceive('invalidatePath')->once()->with('/other/path')
4041
->getMock()

Tests/Unit/Command/InvalidateRegexCommandTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle\Tests\Unit\Command;
1313

14+
use FOS\HttpCacheBundle\CacheManager;
1415
use FOS\HttpCacheBundle\Command\InvalidateRegexCommand;
1516
use Symfony\Component\Console\Application;
1617
use Symfony\Component\Console\Tester\CommandTester;
@@ -22,7 +23,7 @@ class InvalidateRegexCommandTest extends \PHPUnit_Framework_TestCase
2223
*/
2324
public function testExecuteNoParameters()
2425
{
25-
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager');
26+
$invalidator = \Mockery::mock(CacheManager::class);
2627

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

3536
public function testExecuteParameter()
3637
{
37-
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager')
38+
$invalidator = \Mockery::mock(CacheManager::class)
3839
->shouldReceive('invalidateRegex')->once()->with('/my.*/path')
3940
->getMock()
4041
;

Tests/Unit/Command/InvalidateTagCommandTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace FOS\HttpCacheBundle\Tests\Unit\Command;
1313

1414
use FOS\HttpCacheBundle\Command\InvalidateTagCommand;
15+
use FOS\HttpCacheBundle\Handler\TagHandler;
1516
use Symfony\Component\Console\Application;
1617
use Symfony\Component\Console\Tester\CommandTester;
1718

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

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

3536
public function testExecuteParameter()
3637
{
37-
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\Handler\TagHandler')
38+
$invalidator = \Mockery::mock(TagHandler::class)
3839
->shouldReceive('invalidateTags')->once()->with(array('my-tag'))
3940
->getMock()
4041
;

0 commit comments

Comments
 (0)