Skip to content

Commit d5793ac

Browse files
authored
[Tests] Added ClockMock to make time-sensitive tests more robust (#134)
1 parent 0d9b6b7 commit d5793ac

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"phpspec/phpspec": "^5.1.2",
2222
"ezsystems/ezplatform-code-style": "^0.1.0",
2323
"friendsofphp/php-cs-fixer": "^2.16.1",
24-
"memio/spec-gen": "^0.9.0"
24+
"memio/spec-gen": "^0.9.0",
25+
"symfony/phpunit-bridge": "^5.1"
2526
},
2627
"autoload": {
2728
"psr-4": {

phpunit.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
>
1010
<php>
1111
<ini name="error_reporting" value="-1" />
12+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled=1"/>
1213
</php>
1314
<testsuites>
1415
<testsuite name="default"><directory>tests</directory></testsuite>
1516
</testsuites>
17+
<listeners>
18+
<listener class="\Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
19+
</listeners>
1620
</phpunit>

tests/PurgeClient/LocalPurgeClientTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,23 @@
44
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7-
namespace EzSystems\PlatformHttpCacheBundle\Tests\PurgeClient;
8-
9-
/**
10-
* Avoid test failure caused by time passing between generating expected & actual object.
11-
*
12-
* @return int
13-
*/
14-
function time()
15-
{
16-
return 1417624982;
17-
}
18-
197
namespace eZ\Publish\Core\MVC\Symfony\Cache\Tests;
208

219
use EzSystems\PlatformHttpCacheBundle\RequestAwarePurger;
2210
use EzSystems\PlatformHttpCacheBundle\PurgeClient\LocalPurgeClient;
2311
use PHPUnit\Framework\TestCase;
2412
use Symfony\Component\HttpFoundation\Request;
13+
use Symfony\Bridge\PhpUnit\ClockMock;
2514

2615
class LocalPurgeClientTest extends TestCase
2716
{
17+
/**
18+
* @group time-sensitive
19+
*/
2820
public function testPurge()
2921
{
22+
ClockMock::register(Request::class);
23+
3024
$locationIds = [123, 456, 789];
3125
$expectedBanRequest = Request::create('http://localhost', 'PURGE');
3226
$expectedBanRequest->headers->set('key', 'l123 l456 l789');

0 commit comments

Comments
 (0)