/** * @test */ public function localizedLiteralsAreCorrectlyReadFromCldr() { $getRawArrayCallback = function () { $args = func_get_args(); $mockDatesCldrData = (require __DIR__ . '/../../Fixtures/MockDatesParsedCldrData.php'); $lastPartOfPath = substr($args[0], strrpos($args[0], '/') + 1); // Eras have different XML structure than other literals so they have to be handled differently if ($lastPartOfPath === 'eras') { return $mockDatesCldrData['eras']; } else { return $mockDatesCldrData[$lastPartOfPath]; } }; $mockModel = $this->getAccessibleMock(I18n\Cldr\CldrModel::class, ['getRawArray'], [[]]); $mockModel->expects($this->exactly(5))->method('getRawArray')->will($this->returnCallback($getRawArrayCallback)); $mockRepository = $this->createMock(I18n\Cldr\CldrRepository::class); $mockRepository->expects($this->once())->method('getModelForLocale')->with($this->sampleLocale)->will($this->returnValue($mockModel)); $mockCache = $this->getMockBuilder(VariableFrontend::class)->disableOriginalConstructor()->getMock(); $this->createCacheExpectations($mockCache); $reader = new I18n\Cldr\Reader\DatesReader(); $reader->injectCldrRepository($mockRepository); $reader->injectCache($mockCache); $reader->initializeObject(); $result = $reader->getLocalizedLiteralsForLocale($this->sampleLocale); $this->assertEquals('January', $result['months']['format']['wide'][1]); $this->assertEquals('Sat', $result['days']['format']['abbreviated']['sat']); $this->assertEquals('1', $result['quarters']['format']['narrow'][1]); $this->assertEquals('a.m.', $result['dayPeriods']['stand-alone']['wide']['am']); $this->assertEquals('Anno Domini', $result['eras']['eraNames'][1]); $reader->shutdownObject(); }