You are here

public function TranslatorCacheTest::testCatalogueIsReloadedWhenResourcesAreNoLongerFresh in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/translation/Tests/TranslatorCacheTest.php \Symfony\Component\Translation\Tests\TranslatorCacheTest::testCatalogueIsReloadedWhenResourcesAreNoLongerFresh()

File

vendor/symfony/translation/Tests/TranslatorCacheTest.php, line 77

Class

TranslatorCacheTest

Namespace

Symfony\Component\Translation\Tests

Code

public function testCatalogueIsReloadedWhenResourcesAreNoLongerFresh() {

  /*
   * The testThatACacheIsUsed() test showed that we don't need the loader as long as the cache
   * is fresh.
   *
   * Now we add a Resource that is never fresh and make sure that the
   * cache is discarded (the loader is called twice).
   *
   * We need to run this for debug=true only because in production the cache
   * will never be revalidated.
   */
  $locale = 'any_locale';
  $format = 'some_format';
  $msgid = 'test';
  $catalogue = new MessageCatalogue($locale, array());
  $catalogue
    ->addResource(new StaleResource());

  // better use a helper class than a mock, because it gets serialized in the cache and re-loaded

  /** @var LoaderInterface|\PHPUnit_Framework_MockObject_MockObject $loader */
  $loader = $this
    ->getMock('Symfony\\Component\\Translation\\Loader\\LoaderInterface');
  $loader
    ->expects($this
    ->exactly(2))
    ->method('load')
    ->will($this
    ->returnValue($catalogue));

  // 1st pass
  $translator = new Translator($locale, null, $this->tmpDir, true);
  $translator
    ->addLoader($format, $loader);
  $translator
    ->addResource($format, null, $locale);
  $translator
    ->trans($msgid);

  // 2nd pass
  $translator = new Translator($locale, null, $this->tmpDir, true);
  $translator
    ->addLoader($format, $loader);
  $translator
    ->addResource($format, null, $locale);
  $translator
    ->trans($msgid);
}