Symfony2 PHPUnit Clock Mocking not working
<p>I'm testing my Symfony2 project using PHPUnit. I want to mock the server's clock when doing some functional test.</p>

<p><strong>AuthUserRepositoryTest.php</strong></p>

<pre><code>&lt;?php
namespace AppBundle\Tests\Entity;
use AppBundle\Entity\AuthUserRepository;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use \Symfony\Bridge\PhpUnit\ClockMock;
/**
 * @group time-sensitive
 */
class AuthUserRepositoryTest extends WebTestCase
{
    /**
     * @var AuthUserRepository
     */
    private $AuthUserRepository;

    public function setUp()
    {
        $kernel = static::createKernel();
        $kernel-&gt;boot();
        $this-&gt;AuthUserRepository = $kernel-&gt;getContainer()
            -&gt;get('doctrine.orm.entity_manager')
            -&gt;getRepository('AppBundle:auth_user');
        ClockMock::register(__CLASS__);
    }

    /**
     * @group time-sensitive
     */
    public function test()
    {
        ClockMock::withClockMock(true);

        // Other tests ...

        // Check whether clock mock was successful
        $time = $this-&gt;AuthUserRepository-&gt;getApparentTime();
        $this-&gt;assertEquals("2016-11-05 01:00:00",$time);
    }

    /**
     * Override time() in current namespace for testing
     *
     * @return int
     */
    public static function time()
    {
        return "2016-11-05 01:00:00";
    }
    ?&gt;
</code></pre>

<p><strong>AuthUserRepository.php</strong></p>

<pre><code>&lt;?php
namespace AppBundle\Entity;
use Doctrine\ORM\EntityRepository;

class AuthUserRepository extends EntityRepository{

    private function getTimeStamp()
    {
        return \DateTime::createFromFormat('U', time())-&gt;setTimezone(new \DateTimeZone('Asia/Colombo'))-&gt;format('Y-m-d H:i:s');
    }

    public function getApparentTime()
    {
        return $this-&gt;getTimeStamp();
    }

    // Functions to be tested are reduced.
}
?&gt;
</code></pre>

<p>If the clock mocking was successful, <code>assertEquals</code> should passed. But it doesn't pass and actual time remains same.
Failed asserting that two strings are equal.</p>

<pre><code>--- Expected
+++ Actual
@@ @@
-'2016-11-05 01:00:00'
+'2016-05-29 16:44:49'

FAILURES!
Tests: 9, Assertions: 16, Failures: 1.
</code></pre>

<p>Any suggestions to achieve desire functionality is appreciated.</p>

<p>I'm following <a href="http://symfony.com/doc/current/components/phpunit_bridge.html" rel="nofollow">this</a> tutorial.</p>