/** * @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()); }
/** * @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(); }
/** * @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&bar", $addressFormat($address)); }
/** * @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()); }