addressFormatRepository = new AddressFormatRepository(); $this->countryRepository = new CountryRepository(); $this->subdivisionRepository = new SubdivisionRepository(); $this->formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository); } /** * @covers ::__construct */ public function testConstructor(): void { $formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository); $reflected_constraint = (new \ReflectionObject($formatter))->getProperty('addressFormatRepository'); $reflected_constraint->setAccessible(TRUE); $constraint = $reflected_constraint->getValue($formatter); $this->assertInstanceOf(AddressFormatRepository::class, $constraint); $reflected_constraint = (new \ReflectionObject($formatter))->getProperty('countryRepository'); $reflected_constraint->setAccessible(TRUE); $constraint = $reflected_constraint->getValue($formatter); $this->assertInstanceOf(CountryRepository::class, $constraint); $reflected_constraint = (new \ReflectionObject($formatter))->getProperty('subdivisionRepository'); $reflected_constraint->setAccessible(TRUE); $constraint = $reflected_constraint->getValue($formatter); $this->assertInstanceOf(SubdivisionRepository::class, $constraint); } /** * @covers ::__construct */ public function testUnrecognizedOption() { $this->expectException(\InvalidArgumentException::class); $formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository, ['unrecognized' => '123']); } /** * @covers ::__construct */ public function testInvalidOption() { $this->expectException(\InvalidArgumentException::class); $formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository, ['html' => 'INVALID']); } /** * @covers \CommerceGuys\Addressing\Formatter\DefaultFormatter */ public function testAndorraAddress() { $address = new Address(); $address = $address ->withCountryCode('AD') ->withLocality("Parròquia d'Andorra la Vella") ->withPostalCode('AD500') ->withAddressLine1('C. Prat de la Creu, 62-64'); // Andorra has no predefined administrative areas, but it does have // predefined localities, which must be shown. $expectedTextLines = [ 'C. Prat de la Creu, 62-64', "AD500 Parròquia d'Andorra la Vella", 'Andorra', ]; $textAddress = $this->formatter->format($address, ['html' => false]); $this->assertFormattedAddress($expectedTextLines, $textAddress); } /** * @covers \CommerceGuys\Addressing\Formatter\DefaultFormatter */ public function testElSalvadorAddress() { $address = new Address(); $address = $address ->withCountryCode('SV') ->withAdministrativeArea('Ahuachapán') ->withLocality('Ahuachapán') ->withAddressLine1('Some Street 12'); $expectedHtmlLines = [ '
',
'Some Street 12
',
'Ahuachapán
',
'Ahuachapán
',
'El Salvador',
'
',
'Some Street 12
',
'CP 2101-Ahuachapán
',
'Ahuachapán
',
'El Salvador',
'
',
'台灣
',
'106
',
'台北市大安區
',
'Sec. 3 Hsin-yi Rd.
',
'Giant <h2>Bike</h2> Store
',
'Liu Te-Chiang',
'
',
'1098 Alta Ave
',
'CA 94043
',
'United States',
'
',
'1098 Alta Ave
',
'Mountain View, 94043
',
'United States',
'