/** * @dataProvider data_resolverStyle */ public function test_resolverStyle($str, ResolverStyle $style, $expectedEx, $year, $month, $day) { $builder = new DateTimeFormatterBuilder(); $builder->appendValue(ChronoField::YEAR_OF_ERA()); $builder->appendLiteral("/"); $builder->appendValue(ChronoField::MONTH_OF_YEAR()); $builder->appendLiteral("/"); $builder->appendValue(ChronoField::DAY_OF_MONTH()); $eraMap = [1 => "CE", 0 => "BCE"]; $optionalFormatter = (new DateTimeFormatterBuilder())->appendLiteral(" ")->appendText3(ChronoField::ERA(), $eraMap)->toFormatter(); $formatter = $builder->appendOptional($optionalFormatter)->toFormatter(); $formatter = $formatter->withResolverStyle($style); if ($expectedEx == null) { $accessor = $formatter->parse($str); $this->assertEquals($accessor->get(ChronoField::YEAR_OF_ERA()), $year); $this->assertEquals($accessor->get(ChronoField::MONTH_OF_YEAR()), $month); $this->assertEquals($accessor->get(ChronoField::DAY_OF_MONTH()), $day); } else { try { $formatter->parse($str); $this->fail(); } catch (\Exception $ex) { $this->assertInstanceOf($expectedEx, $ex); } } }