createFailingLoader example

// Prime the cache         $translator = new Translator($locale, null, $this->tmpDir, $debug);
        $translator->addLoader($formatnew ArrayLoader());
        $translator->addResource($format[$msgid => 'OK']$locale);
        $translator->addResource($format[$msgid.'+intl' => 'OK']$locale, 'messages+intl-icu');
        $translator->trans($msgid);
        $translator->trans($msgid.'+intl', [], 'messages+intl-icu');

        // Try again and see we get a valid result whilst no loader can be used         $translator = new Translator($locale, null, $this->tmpDir, $debug);
        $translator->addLoader($format$this->createFailingLoader());
        $translator->addResource($format[$msgid => 'OK']$locale);
        $translator->addResource($format[$msgid.'+intl' => 'OK']$locale, 'messages+intl-icu');
        $this->assertEquals('OK', $translator->trans($msgid), '-> caching does not work in '.($debug ? 'debug' : 'production'));
        $this->assertEquals('OK', $translator->trans($msgid.'+intl', [], 'messages+intl-icu'));
    }

    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. */
Home | Imprint | This part of the site doesn't use cookies.