Skip to content
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

[Tests] Added ClockMock to make time-sensitive tests more robust #134

Merged
merged 1 commit into from
Sep 14, 2020
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"phpspec/phpspec": "^5.1.2",
"ezsystems/ezplatform-code-style": "^0.1.0",
"friendsofphp/php-cs-fixer": "^2.16.1",
"memio/spec-gen": "^0.9.0"
"memio/spec-gen": "^0.9.0",
"symfony/phpunit-bridge": "^5.1"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
>
<php>
<ini name="error_reporting" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled=1"/>
</php>
<testsuites>
<testsuite name="default"><directory>tests</directory></testsuite>
</testsuites>
<listeners>
<listener class="\Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
18 changes: 6 additions & 12 deletions tests/PurgeClient/LocalPurgeClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\PlatformHttpCacheBundle\Tests\PurgeClient;

/**
* Avoid test failure caused by time passing between generating expected & actual object.
*
* @return int
*/
function time()
{
return 1417624982;
}

namespace eZ\Publish\Core\MVC\Symfony\Cache\Tests;

use EzSystems\PlatformHttpCacheBundle\RequestAwarePurger;
use EzSystems\PlatformHttpCacheBundle\PurgeClient\LocalPurgeClient;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bridge\PhpUnit\ClockMock;

class LocalPurgeClientTest extends TestCase
{
/**
* @group time-sensitive
*/
public function testPurge()
{
ClockMock::register(Request::class);

$locationIds = [123, 456, 789];
$expectedBanRequest = Request::create('http://localhost', 'PURGE');
$expectedBanRequest->headers->set('key', 'l123 l456 l789');
Expand Down