Skip to content

Commit

Permalink
Drop support of php < 7.3, upgrade to phunit 9 (#166)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Georg <[email protected]>
  • Loading branch information
Chris53897 and Chris8934 authored Feb 28, 2022
1 parent 32fba7d commit 39f10c4
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
composer.lock
.phpunit.result.cache
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ sudo: false
language: php

php:
- 8.1
- 8.0
- 7.4
- 7.3
- 7.2
- 7.1

install:
- composer self-update
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ addressing

[![Build Status](https://travis-ci.org/commerceguys/addressing.svg?branch=master)](https://travis-ci.org/commerceguys/addressing)

A PHP 7.1+ addressing library, powered by CLDR and Google's address data.
A PHP 7.3+ addressing library, powered by CLDR and Google's address data.

Manipulates postal addresses, meant to identify a precise recipient location for shipping or billing purposes.

Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"keywords": ["postal", "address", "internationalization", "localization"],
"license": "MIT",
"require": {
"php": ">=7.1.3",
"php": ">=7.3",
"doctrine/collections": "~1.0"
},
"require-dev": {
"symfony/validator": "^4.4",
"phpunit/phpunit": "^7.5",
"symfony/validator": "^4.4 || ^5.4",
"phpunit/phpunit": "^9.5",
"mikey179/vfsstream": "1.*",
"squizlabs/php_codesniffer": "3.*"
"squizlabs/php_codesniffer": "3.*",
"ext-json": "*"
},
"suggest": {
"symfony/validator": "to validate addresses"
Expand Down
17 changes: 8 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="CommerceGuys Addressing Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>
10 changes: 4 additions & 6 deletions tests/AbstractEnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,21 @@ public function testExists()

/**
* @covers ::assertExists
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage "invalid" is not a valid PatternType value.
*/
public function testAssertExists()
{
$this->expectExceptionMessage("\"invalid\" is not a valid PatternType value.");
$this->expectException(\InvalidArgumentException::class);
$result = PatternType::assertExists('invalid');
}

/**
* @covers ::assertAllExist
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage "invalid" is not a valid PatternType value.
*/
public function testAssertAllExist()
{
$this->expectExceptionMessage("\"invalid\" is not a valid PatternType value.");
$this->expectException(\InvalidArgumentException::class);
$result = PatternType::assertAllExist(['start', 'invalid']);
}
}
6 changes: 4 additions & 2 deletions tests/AddressFormat/AddressFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ final class AddressFormatTest extends TestCase
/**
* @covers ::__construct
*
* @expectedException \InvalidArgumentException
*
*/
public function testMissingProperty()
{
$this->expectException(\InvalidArgumentException::class);
$definition = [
'country_code' => 'US',
];
Expand All @@ -31,10 +32,11 @@ public function testMissingProperty()
/**
* @covers ::__construct
*
* @expectedException \InvalidArgumentException
*
*/
public function testInvalidSubdivision()
{
$this->expectException(\InvalidArgumentException::class);
$definition = [
'country_code' => 'US',
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%dependentLocality",
Expand Down
6 changes: 4 additions & 2 deletions tests/AddressFormat/FieldOverridesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ final class FieldOverridesTest extends TestCase
/**
* @covers ::__construct
*
* @expectedException \InvalidArgumentException
*
*/
public function testInvalidField()
{
$this->expectException(\InvalidArgumentException::class);
$definition = [
'INVALID_FIELD' => FieldOverride::HIDDEN,
];
Expand All @@ -28,10 +29,11 @@ public function testInvalidField()
/**
* @covers ::__construct
*
* @expectedException \InvalidArgumentException
*
*/
public function testInvalidOverride()
{
$this->expectException(\InvalidArgumentException::class);
$definition = [
AddressField::POSTAL_CODE => 'INVALID',
];
Expand Down
8 changes: 6 additions & 2 deletions tests/Country/CountryRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public function testConstructor()
// Instantiate the country repository and confirm that the definition path
// was properly set.
$countryRepository = new CountryRepository('de', 'en', 'vfs://resources/country/');
$definitionPath = $this->getObjectAttribute($countryRepository, 'definitionPath');

$reflected_constraint = (new \ReflectionObject($countryRepository))->getProperty('definitionPath');
$reflected_constraint->setAccessible(TRUE);
$definitionPath = $reflected_constraint->getValue($countryRepository);
$this->assertEquals('vfs://resources/country/', $definitionPath);

return $countryRepository;
Expand Down Expand Up @@ -92,11 +95,12 @@ public function testGet($countryRepository)
* @covers ::loadDefinitions
*
* @uses \CommerceGuys\Addressing\Locale
* @expectedException \CommerceGuys\Addressing\Exception\UnknownCountryException
*
* @depends testConstructor
*/
public function testGetInvalidCountry($countryRepository)
{
$this->expectException(\CommerceGuys\Addressing\Exception\UnknownCountryException::class);
$countryRepository->get('INVALID');
}

Expand Down
34 changes: 23 additions & 11 deletions tests/Formatter/DefaultFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use CommerceGuys\Addressing\Address;
use CommerceGuys\Addressing\AddressFormat\AddressFormatRepository;
use CommerceGuys\Addressing\AddressFormat\AddressFormatRepositoryInterface;
use CommerceGuys\Addressing\Country\CountryRepository;
use CommerceGuys\Addressing\Country\CountryRepositoryInterface;
use CommerceGuys\Addressing\Formatter\DefaultFormatter;
use CommerceGuys\Addressing\Subdivision\SubdivisionRepository;
use CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -45,7 +48,7 @@ final class DefaultFormatterTest extends TestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->addressFormatRepository = new AddressFormatRepository();
$this->countryRepository = new CountryRepository();
Expand All @@ -56,29 +59,41 @@ protected function setUp()
/**
* @covers ::__construct
*/
public function testConstructor()
public function testConstructor(): void
{
$formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository);
$this->assertEquals($this->addressFormatRepository, $this->getObjectAttribute($formatter, 'addressFormatRepository'));
$this->assertEquals($this->countryRepository, $this->getObjectAttribute($formatter, 'countryRepository'));
$this->assertEquals($this->subdivisionRepository, $this->getObjectAttribute($formatter, '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
* @expectedException \InvalidArgumentException
*/
public function testUnrecognizedOption()
{
$this->expectException(\InvalidArgumentException::class);
$formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository, ['unrecognized' => '123']);
}

/**
* @covers ::__construct
* @expectedException \InvalidArgumentException
*/
public function testInvalidOption()
{
$this->expectException(\InvalidArgumentException::class);
$formatter = new DefaultFormatter($this->addressFormatRepository, $this->countryRepository, $this->subdivisionRepository, ['html' => 'INVALID']);
}

Expand Down Expand Up @@ -272,11 +287,8 @@ public function testUnitedStatesIncompleteAddress()

/**
* Asserts that the formatted address is valid.
*
* @param array $expectedLines
* @param string $formattedAddress
*/
protected function assertFormattedAddress(array $expectedLines, $formattedAddress)
protected function assertFormattedAddress(array $expectedLines, string $formattedAddress)
{
$expectedLines = implode("\n", $expectedLines);
$this->assertEquals($expectedLines, $formattedAddress);
Expand Down
5 changes: 3 additions & 2 deletions tests/Formatter/PostalLabelFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class PostalLabelFormatterTest extends TestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->addressFormatRepository = new AddressFormatRepository();
$this->countryRepository = new CountryRepository();
Expand All @@ -56,10 +56,11 @@ protected function setUp()
/**
* @covers ::format
*
* @expectedException \InvalidArgumentException
*
*/
public function testMissingOriginCountryCode()
{
$this->expectException(\InvalidArgumentException::class);
$address = new Address();
$this->formatter->format($address);
}
Expand Down
7 changes: 5 additions & 2 deletions tests/Subdivision/LazySubdivisionCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class LazySubdivisionCollectionTest extends TestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->collection = new LazySubdivisionCollection(['BR', 'Porto Acre']);
}
Expand All @@ -29,7 +29,10 @@ protected function setUp()
public function testConstructor()
{
$collection = new LazySubdivisionCollection(['BR', 'Porto Acre']);
$this->assertEquals(['BR', 'Porto Acre'], $this->getObjectAttribute($collection, 'parents'));

$reflected_constraint = (new \ReflectionObject($collection))->getProperty('parents');
$reflected_constraint->setAccessible(TRUE);
$this->assertEquals(['BR', 'Porto Acre'], $reflected_constraint->getValue($collection));
}

/**
Expand Down
11 changes: 7 additions & 4 deletions tests/Subdivision/SubdivisionRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public function testConstructor()
// Instantiate the subdivision repository and confirm that the
// definition path was properly set.
$subdivisionRepository = new SubdivisionRepository(null, 'vfs://resources/subdivision/');
$definitionPath = $this->getObjectAttribute($subdivisionRepository, 'definitionPath');

$reflected_constraint = (new \ReflectionObject($subdivisionRepository))->getProperty('definitionPath');
$reflected_constraint->setAccessible(TRUE);
$definitionPath = $reflected_constraint->getValue($subdivisionRepository);
$this->assertEquals('vfs://resources/subdivision/', $definitionPath);

return $subdivisionRepository;
Expand Down Expand Up @@ -149,13 +152,13 @@ public function testGetAll($subdivisionRepository)
$this->assertCount(2, $subdivisions);
$this->assertArrayHasKey('SC', $subdivisions);
$this->assertArrayHasKey('SP', $subdivisions);
$this->assertEquals($subdivisions['SC']->getCode(), 'SC');
$this->assertEquals($subdivisions['SP']->getCode(), 'SP');
$this->assertEquals('SC', $subdivisions['SC']->getCode());
$this->assertEquals('SP', $subdivisions['SP']->getCode());

$subdivisions = $subdivisionRepository->getAll(['BR', 'SC']);
$this->assertCount(1, $subdivisions);
$this->assertArrayHasKey('Abelardo Luz', $subdivisions);
$this->assertEquals($subdivisions['Abelardo Luz']->getCode(), 'Abelardo Luz');
$this->assertEquals('Abelardo Luz', $subdivisions['Abelardo Luz']->getCode());
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/Subdivision/SubdivisionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ final class SubdivisionTest extends TestCase
{
/**
* @covers ::__construct
*
* @expectedException \InvalidArgumentException
*/
public function testMissingProperty()
{
$this->expectException(\InvalidArgumentException::class);
$definition = [
'country_code' => 'US',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class AddressFormatConstraintValidatorTest extends ConstraintValidatorTest
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->constraint = new AddressFormatConstraint();

Expand All @@ -48,11 +48,10 @@ protected function createValidator()

/**
* @covers \CommerceGuys\Addressing\Validator\Constraints\AddressFormatConstraintValidator
*
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
*/
public function testInvalidValueType()
{
$this->expectException(\Symfony\Component\Validator\Exception\UnexpectedTypeException::class);
$this->validator->validate(new \stdClass(), $this->constraint);
}

Expand Down Expand Up @@ -379,7 +378,7 @@ public function testStreetVerification()
}

/**
* @covers CommerceGuys\Addressing\Validator\Constraints\AddressFormatConstraintValidator
* @covers \CommerceGuys\Addressing\Validator\Constraints\AddressFormatConstraintValidator
*/
public function testJapan()
{
Expand Down
Loading

0 comments on commit 39f10c4

Please sign in to comment.