AddressPostalUtilsTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Test\Service\Access;
  3. use App\Entity\Core\AddressPostal;
  4. use App\Service\Core\AddressPostalUtils;
  5. use PHPUnit\Framework\TestCase;
  6. class AddressPostalUtilsTest extends TestCase
  7. {
  8. public function testGetFullStreetAddress(): void {
  9. $addressPostalUtils = new AddressPostalUtils(); // Cf. bug when SUT has only one method, can't be mocked
  10. $addressPostal = $this->getMockBuilder(AddressPostal::class)->getMock();
  11. $addressPostal->method('getStreetAddress')->willReturn('Abc');
  12. $addressPostal->method('getStreetAddressSecond')->willReturn('Def ');
  13. $addressPostal->method('getStreetAddressThird')->willReturn(' Ghi ');
  14. $this->assertEqualsCanonicalizing(
  15. "Abc\nDef\nGhi",
  16. $addressPostalUtils->getFullStreetAddress($addressPostal)
  17. );
  18. $this->assertEqualsCanonicalizing(
  19. "Abc Def Ghi",
  20. $addressPostalUtils->getFullStreetAddress($addressPostal, ' ')
  21. );
  22. }
  23. public function testGetFullStreetAddressWithMissing(): void {
  24. $addressPostalUtils = new AddressPostalUtils(); // Cf. bug when SUT has only one method, can't be mocked
  25. $addressPostal = $this->getMockBuilder(AddressPostal::class)->getMock();
  26. $addressPostal->method('getStreetAddress')->willReturn('Abc');
  27. $addressPostal->method('getStreetAddressSecond')->willReturn('');
  28. $addressPostal->method('getStreetAddressThird')->willReturn(' Def');
  29. $this->assertEqualsCanonicalizing(
  30. "Abc\nDef",
  31. $addressPostalUtils->getFullStreetAddress($addressPostal)
  32. );
  33. }
  34. }