/**
  * @covers ::isValid
  */
 public function testFailureOnRequiredEmptyField()
 {
     $this->addressService->expects($this->once())->method('getFieldsForCountry')->with($this->equalTo('bar'))->will($this->returnValue(['foo' => true]));
     $addressFieldValidator = new AddressFieldValidator($this->addressService, 'foo');
     $this->assertFalse($addressFieldValidator->isValid('', ['countryCode' => 'bar']));
     $this->assertArrayHasKey(AddressFieldValidator::IS_EMPTY, $addressFieldValidator->getMessages());
 }
예제 #2
0
 /**
  * @covers ::getValueOptions
  */
 public function testAddressServiceIsOnlyAskedOnce()
 {
     $this->addressService->expects($this->once())->method('getCountryCodes')->will($this->returnValue([]));
     $countrySelect = new CountrySelect($this->addressService, $this->countryCodeFormatter);
     $countrySelect->getValueOptions();
     $countrySelect->getValueOptions();
 }
예제 #3
0
 /**
  * @covers ::__invoke
  */
 public function testInvokeFormatsForHtml()
 {
     $address = new Address();
     $this->addressService->expects($this->once())->method('formatAddress')->with($this->equalTo($address))->will($this->returnValue(['foo', '&bar']));
     $addressFormat = new AddressFormat($this->addressService);
     $addressFormat->setView(new PhpRenderer());
     $this->assertEquals("foo<br />\n&amp;bar", $addressFormat($address));
 }
예제 #4
0
 /**
  * @covers ::__construct
  * @covers ::hydrate
  */
 public function testHydrateClearsNonRequiredFields()
 {
     $this->addressService->expects($this->once())->method('getFieldsForCountry')->with($this->equalTo('foo'))->will($this->returnValue(['addressLine1' => true, 'addressLine2' => false]));
     $hydrator = new AddressHydrator($this->addressService);
     $address = $hydrator->hydrate(['countryCode' => 'foo', 'addressLine1' => 'bar', 'locality' => 'baz'], new Address());
     $this->assertSame('foo', $address->getCountryCode());
     $this->assertSame('bar', $address->getAddressLine1());
     $this->assertNull($address->getAddressLine2());
     $this->assertNull($address->getLocality());
 }