Skip to content

Commit

Permalink
feat: drop support of php < 7, modernise code and tests, replace trav…
Browse files Browse the repository at this point in the history
…is with github actions (#47)

* feat: drop support of php < 8, modernise code and tests, replace travis with github actions

* feat: drop support of php < 8, modernise code and tests, replace travis with github actions

* feat: drop support of php < 8, modernise code and tests, replace travis with github actions

* feat: drop support of php < 8, modernise code and tests, replace travis with github actions

---------

Co-authored-by: Christopher Georg <christopher.georg@sr-travel.de>
  • Loading branch information
Chris53897 and Chris8934 authored Feb 7, 2023
1 parent 758b829 commit 0405c2b
Show file tree
Hide file tree
Showing 19 changed files with 258 additions and 312 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# .github/workflows/ci.yaml
name: Code_Checks

on: ["push", "pull_request"]

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.0']
stability: [ prefer-stable ]
include:
- php: '8.0'
stability: prefer-lowest
symfony-version: 4.4
- php: '8.0'
symfony-version: 5.4
- php: '8.1'
symfony-version: 5.4
- php: '8.2'
symfony-version: 5.4
- php: '8.2'
symfony-version: 6.2

name: PHP ${{ matrix.php }} - ${{ matrix.stability }} tests
steps:
# basically git clone
- uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

# use PHP of specific version
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pcov
coverage: pcov

- name: Install dependencies
env:
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require --no-progress --no-scripts --no-plugins symfony/flex
composer update --no-interaction --prefer-dist --optimize-autoloader
- name: Execute tests
run: vendor/bin/phpunit -c ./phpunit.xml.dist ./tests --verbose
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ Thumbs.db
#composer related
composer.phar
composer.lock
vendor/
vendor/

.phpunit.result.cache
code-coverage
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Constraint Class for international Zipcode Validation

[![Build Status](https://img.shields.io/travis/barbieswimcrew/zip-code-validator/master.svg?style=flat-square)](https://travis-ci.org/barbieswimcrew/zip-code-validator)
[![Build Status](https://github.com/barbieswimcrew/zip-code-validator/actions/workflows/ci.yaml/badge.svg)](https://github.com/barbieswimcrew/zip-code-validator/actions/workflows/ci.yaml)
[![Downloads](https://img.shields.io/packagist/dt/barbieswimcrew/zip-code-validator.svg?style=flat-square)](https://packagist.org/packages/barbieswimcrew/zip-code-validator)
[![Latest stable version](https://img.shields.io/packagist/v/barbieswimcrew/zip-code-validator.svg?style=flat-square)](https://packagist.org/packages/barbieswimcrew/zip-code-validator)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/barbieswimcrew/zip-code-validator.svg?style=flat-square)](./composer.json)
Expand All @@ -26,14 +26,14 @@ For validating a zip code you need to instantiate a new ZipCode class provided b
<?php
//...
$form = $this->createFormBuilder($address)
->add('zipcode', TextType::class, array(
->add('zipcode', TextType::class, [
'constraints' => array(
new ZipCodeValidator\Constraints\ZipCode(array(
new ZipCodeValidator\Constraints\ZipCode([
'iso' => 'DE'
))
)
])
]
))
->add('save', SubmitType::class, array('label' => 'Create Task'))
->add('save', SubmitType::class, ['label' => 'Create Task'])
->getForm();
```
Expand Down
16 changes: 10 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "barbieswimcrew/zip-code-validator",
"description": "Constraint class for international zipcode validation",
"keywords": ["symfony", "symfony4", "symfony3", "symfony2", "form", "constraints", "constraint", "validator", "zip code", "zipcode", "postal code", "postalcode", "validation"],
"keywords": ["symfony", "form", "constraints", "constraint", "validator", "zip code", "zipcode", "postal code", "postalcode", "validation"],
"license": "MIT",
"authors": [
{
Expand All @@ -11,16 +11,20 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=5.6.0",
"symfony/validator": ">=2.1"
"php": ">=8.0",
"symfony/validator": ">=4.4.40"
},
"require-dev": {
"phpunit/phpunit": "^5"
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
"ZipCodeValidator\\": "src/ZipCodeValidator",
"Tests\\Fixtures\\": "tests/Fixtures"
"ZipCodeValidator\\": "src/ZipCodeValidator"
}
},
"autoload-dev": {
"psr-4": {
"ZipCodeValidator\\Tests\\": "tests/"
}
}
}
31 changes: 13 additions & 18 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<!-- https://phpunit.readthedocs.io/en/9.6/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="unit">
<directory suffix=".php">./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./tests</directory>
</whitelist>
</filter>
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./tests</directory>
</include>
</coverage>
<testsuites>
<testsuite name="unit">
<directory suffix=".php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
47 changes: 25 additions & 22 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<!-- https://phpunit.readthedocs.io/en/9.6/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.7/phpunit.xsd"
backupGlobals="false"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
bootstrap="vendor/autoload.php">

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src/</directory>
</include>
<exclude>
<directory>./tests</directory>
</exclude>
<report>
<html outputDirectory="code-coverage" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>

<php>
<ini name="error_reporting" value="-1"/>
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>Tests</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="Project Test Suite">
<directory>Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./tests/</directory>
</whitelist>
</filter>
<logging/>

<logging>
<log type="coverage-html" target="code-coverage" lowUpperBound="35" highLowerBound="70"/>
</logging>
</phpunit>
39 changes: 7 additions & 32 deletions src/ZipCodeValidator/Constraints/ZipCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,19 @@
use Symfony\Component\Validator\Exception\MissingOptionsException;

/**
* Class ZipCode
* @Annotation
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
* @author Martin Schindler
* @package ZipCodeValidator\Constraints
*/
class ZipCode extends Constraint
{
/**
* @var string
*/
public $message = 'This value is not a valid ZIP code.';
public string $message = 'This value is not a valid ZIP code.';
public ?string $iso = null;
public ?string $getter = null;
public bool $strict = true;
public bool $caseSensitiveCheck = true;

/**
* @var string
*/
public $iso;

/**
* @var string
*/
public $getter;

/**
* @var bool
*/
public $strict = true;

/**
* @var bool
*/
public $caseSensitiveCheck = true;

/**
* ZipCode constructor.
* @param mixed $options
*/
public function __construct($options = null)
public function __construct(mixed $options = null)
{
if (null !== $options && !is_array($options)) {
$options = array(
Expand All @@ -54,7 +29,7 @@ public function __construct($options = null)
parent::__construct($options);

if (null === $this->iso && null === $this->getter) {
throw new MissingOptionsException(sprintf('Either the option "iso" or "getter" must be given for constraint %s', __CLASS__), array('iso', 'getter'));
throw new MissingOptionsException(sprintf('Either the option "iso" or "getter" must be given for constraint %s', __CLASS__), ['iso', 'getter']);
}
}

Expand Down
15 changes: 6 additions & 9 deletions src/ZipCodeValidator/Constraints/ZipCodeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
* Class ZipCodeValidator
* @author Martin Schindler
* @package ZipCodeValidator\Constraints
*/
class ZipCodeValidator extends ConstraintValidator
{

/**
* ZipCode patterns from http://i18napis.appspot.com (updated: 2015-05-08)
*
Expand All @@ -30,7 +27,7 @@ class ZipCodeValidator extends ConstraintValidator
* var_export($patterns);
* </code>
*/
private $patterns = array(
private array $patterns = [
'AC' => 'ASCN 1ZZ',
'AD' => 'AD[1-7]0\\d',
'AF' => '\\d{4}',
Expand Down Expand Up @@ -213,15 +210,15 @@ class ZipCodeValidator extends ConstraintValidator
'YT' => '976\\d{2}',
'ZA' => '\\d{4}',
'ZM' => '\\d{5}',
);
];

/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
public function validate($value, Constraint $constraint): void
{
if (!$constraint instanceof ZipCode) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\ZipCode');
throw new UnexpectedTypeException($constraint, ZipCode::class);
}

if (null === $value || '' === $value) {
Expand Down Expand Up @@ -249,9 +246,9 @@ public function validate($value, Constraint $constraint)
if (!isset($this->patterns[$iso])) {
if ($constraint->strict) {
throw new ConstraintDefinitionException(sprintf('Invalid iso code "%s" for validation', $iso));
} else {
return;
}

return;
}

$pattern = $this->patterns[$iso];
Expand Down
Loading

0 comments on commit 0405c2b

Please sign in to comment.