From 8e644743869312b06229c802820e17528519e797 Mon Sep 17 00:00:00 2001 From: Johan Date: Mon, 1 Oct 2018 11:11:00 +0200 Subject: [PATCH] init from original repo --- .gitignore | 4 + .travis.yml | 9 + README.md | 2 - composer.json | 25 + composer.lock | 1333 +++++++++++++++++ phpunit.xml.dist | 27 + readme.md | 52 + .../LicensePlate/AbstractLicensePlate.php | 41 + .../LicensePlate/BelgianLicensePlate.php | 83 + .../LicensePlate/DutchLicensePlate.php | 136 ++ .../LicensePlate/FrenchLicensePlate.php | 101 ++ .../LicensePlate/GermanLicensePlate.php | 311 ++++ .../LicensePlate/IsraeliLicensePlate.php | 79 + .../LicensePlate/LicensePlateInterface.php | 11 + .../LuxembourgianLicensePlate.php | 88 ++ .../LicensePlate/SpanishLicensePlate.php | 97 ++ .../LicensePlate/UKLicensePlate.php | 125 ++ tests/BelgianLicensePlateFormatTest.php | 32 + tests/BelgianLicensePlateSidecodeTest.php | 45 + tests/DutchLicensePlateFormatTest.php | 50 + tests/DutchLicensePlateSidecodeTest.php | 154 ++ tests/FrenchLicensePlateFormatTest.php | 44 + tests/FrenchLicensePlateSidecodeTest.php | 37 + tests/GermanLicensePlateFormatTest.php | 223 +++ tests/GermanLicensePlateSidecodeTest.php | 160 ++ tests/IsraeliLicensePlateFormatTest.php | 32 + tests/IsraeliLicensePlateSidecodeTest.php | 33 + tests/LuxembourgianLicensePlateFormatTest.php | 20 + .../LuxembourgianLicensePlateSidecodeTest.php | 26 + tests/SpanishLicensePlateFormatTest.php | 36 + tests/SpanishLicensePlateSidecodeTest.php | 40 + tests/UKLicensePlateFormatTest.php | 56 + tests/UKLicensePlateSidecodeTest.php | 85 ++ 33 files changed, 3595 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .travis.yml delete mode 100644 README.md create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 phpunit.xml.dist create mode 100644 readme.md create mode 100644 src/Intrepidity/LicensePlate/AbstractLicensePlate.php create mode 100644 src/Intrepidity/LicensePlate/BelgianLicensePlate.php create mode 100644 src/Intrepidity/LicensePlate/DutchLicensePlate.php create mode 100644 src/Intrepidity/LicensePlate/FrenchLicensePlate.php create mode 100644 src/Intrepidity/LicensePlate/GermanLicensePlate.php create mode 100644 src/Intrepidity/LicensePlate/IsraeliLicensePlate.php create mode 100644 src/Intrepidity/LicensePlate/LicensePlateInterface.php create mode 100644 src/Intrepidity/LicensePlate/LuxembourgianLicensePlate.php create mode 100644 src/Intrepidity/LicensePlate/SpanishLicensePlate.php create mode 100644 src/Intrepidity/LicensePlate/UKLicensePlate.php create mode 100644 tests/BelgianLicensePlateFormatTest.php create mode 100644 tests/BelgianLicensePlateSidecodeTest.php create mode 100644 tests/DutchLicensePlateFormatTest.php create mode 100644 tests/DutchLicensePlateSidecodeTest.php create mode 100644 tests/FrenchLicensePlateFormatTest.php create mode 100644 tests/FrenchLicensePlateSidecodeTest.php create mode 100644 tests/GermanLicensePlateFormatTest.php create mode 100644 tests/GermanLicensePlateSidecodeTest.php create mode 100644 tests/IsraeliLicensePlateFormatTest.php create mode 100644 tests/IsraeliLicensePlateSidecodeTest.php create mode 100644 tests/LuxembourgianLicensePlateFormatTest.php create mode 100644 tests/LuxembourgianLicensePlateSidecodeTest.php create mode 100644 tests/SpanishLicensePlateFormatTest.php create mode 100644 tests/SpanishLicensePlateSidecodeTest.php create mode 100644 tests/UKLicensePlateFormatTest.php create mode 100644 tests/UKLicensePlateSidecodeTest.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcff4e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea +vendor +coverage +phpunit.xml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..140bad5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: php +php: + - 5.6.30 + - 7.0.15 + - 7.1.1 + +before_script: + - curl -s http://getcomposer.org/installer | php + - php composer.phar install \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 322316d..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# license-plate -A copy of the now deleted intrepidity/license-plate repository. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..7747bc3 --- /dev/null +++ b/composer.json @@ -0,0 +1,25 @@ +{ + "name": "intrepidity/license-plate", + "description": "PHP library to validate and format license plate numbers.", + "keywords": ["PHP","License plate"], + "homepage": "http://github.com/Intrepidity/LicensePlate.git", + "type": "library", + "license": "LGPL", + "authors": [ + { + "name": "Bart Guliker", + "email": "bart1987@gmail.com" + } + ], + "require": { + "php": ">=5.6.0" + }, + "require-dev": { + "phpunit/phpunit": "~5.7" + }, + "autoload": { + "psr-0": { + "": "src/" + } + } +} \ No newline at end of file diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..1d5bcfe --- /dev/null +++ b/composer.lock @@ -0,0 +1,1333 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "515fb5935a6dc46cefb92a13ced81544", + "packages": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-06-14T21:17:01+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/8e6e04167378abf1ddb4d3522d8755c5fd90d102", + "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "doctrine/collections": "1.*", + "phpunit/phpunit": "~4.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "homepage": "https://github.com/myclabs/DeepCopy", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2017-04-12T18:52:22+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27T11:43:31+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "3.2.2", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "4aada1f93c72c35e22fb1383b47fee43b8f1d157" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/4aada1f93c72c35e22fb1383b47fee43b8f1d157", + "reference": "4aada1f93c72c35e22fb1383b47fee43b8f1d157", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.3.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2017-08-08T06:39:58+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.3.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fb3933512008d8162b3cdf9e18dba9309b7c3773", + "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773", + "shasum": "" + }, + "require": { + "php": "^5.5 || ^7.0", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2017-06-03T08:32:36+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "v1.7.2", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", + "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "sebastian/comparator": "^1.1|^2.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8 || ^5.6.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2017-09-04T11:05:03+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "4.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^5.6 || ^7.0", + "phpunit/php-file-iterator": "^1.3", + "phpunit/php-text-template": "^1.2", + "phpunit/php-token-stream": "^1.4.2 || ^2.0", + "sebastian/code-unit-reverse-lookup": "^1.0", + "sebastian/environment": "^1.3.2 || ^2.0", + "sebastian/version": "^1.0 || ^2.0" + }, + "require-dev": { + "ext-xdebug": "^2.1.4", + "phpunit/phpunit": "^5.7" + }, + "suggest": { + "ext-xdebug": "^2.5.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2017-04-02T07:44:40+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2016-10-03T07:40:28+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2017-02-26T11:10:40+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.11", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2017-02-27T10:12:30+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "5.7.21", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "3b91adfb64264ddec5a2dee9851f354aa66327db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3b91adfb64264ddec5a2dee9851f354aa66327db", + "reference": "3b91adfb64264ddec5a2dee9851f354aa66327db", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "~1.3", + "php": "^5.6 || ^7.0", + "phpspec/prophecy": "^1.6.2", + "phpunit/php-code-coverage": "^4.0.4", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "^1.0.6", + "phpunit/phpunit-mock-objects": "^3.2", + "sebastian/comparator": "^1.2.4", + "sebastian/diff": "^1.4.3", + "sebastian/environment": "^1.3.4 || ^2.0", + "sebastian/exporter": "~2.0", + "sebastian/global-state": "^1.1", + "sebastian/object-enumerator": "~2.0", + "sebastian/resource-operations": "~1.0", + "sebastian/version": "~1.0.3|~2.0", + "symfony/yaml": "~2.1|~3.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-xdebug": "*", + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.7.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2017-06-21T08:11:54+00:00" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "3.4.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "a23b761686d50a560cc56233b9ecf49597cc9118" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/a23b761686d50a560cc56233b9ecf49597cc9118", + "reference": "a23b761686d50a560cc56233b9ecf49597cc9118", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.6 || ^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^1.2 || ^2.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2017-06-30T09:13:00+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" + }, + { + "name": "sebastian/comparator", + "version": "1.2.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2 || ~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2017-01-29T09:50:25+00:00" + }, + { + "name": "sebastian/diff", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2017-05-22T07:24:03+00:00" + }, + { + "name": "sebastian/environment", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2016-11-26T07:53:53+00:00" + }, + { + "name": "sebastian/exporter", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2016-11-19T08:54:04+00:00" + }, + { + "name": "sebastian/global-state", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2015-10-12T03:26:01+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/1311872ac850040a79c3c058bea3e22d0f09cbb7", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-02-18T15:18:39+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2016-11-19T07:33:16+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28T20:34:47+00:00" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "symfony/yaml", + "version": "v3.3.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "1d8c2a99c80862bdc3af94c1781bf70f86bccac0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/1d8c2a99c80862bdc3af94c1781bf70f86bccac0", + "reference": "1d8c2a99c80862bdc3af94c1781bf70f86bccac0", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "require-dev": { + "symfony/console": "~2.8|~3.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2017-07-29T21:54:42+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2016-11-23T20:04:58+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.6.0" + }, + "platform-dev": [] +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..3d2e042 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,27 @@ + + + + + + + + tests + + + + + + src + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..9e4d1ba --- /dev/null +++ b/readme.md @@ -0,0 +1,52 @@ +# Note +## This repository has been copied because the original has been deleted. + +License plate validator and formatter +===================================== + +[![Build Status](https://secure.travis-ci.org/Intrepidity/LicensePlate.svg)](http://travis-ci.org/Intrepidity/LicensePlate) + +This library can be used to validate and format license plate numbers. +Countries currently supported: + +* Belgium (1971-now) +* France (1976-now) +* German (unknown-now) +* Israel (unknown date-now) +* Netherlands (1951-now) +* Spain (1900-now) +* United Kingdom (1903-now) + +Other countries will be added in the future + +How to install +============== + +Add the following to your composer.json: + +``` json +{ + "require": { + "intrepidity/license-plate": "^1.0.0" + } +} +``` + +How to use +========== + +Call the constructor of the license plate class of your choice with the user input as the first parameter: + +``` php +isValid()) +{ + echo $licenseplate->format(); // Outputs 08-TT-NP in this case +} +``` + +Since the license plate classes for each country implement the LicensePlateInterface, they expose isValid() and format() methods. +Country-specific methods may also be available. Please check the code of the specific class to get the complete picture. + +Please note that this library does not check if a license plate actually exists, nor does it exclude combinations that aren't allowed. diff --git a/src/Intrepidity/LicensePlate/AbstractLicensePlate.php b/src/Intrepidity/LicensePlate/AbstractLicensePlate.php new file mode 100644 index 0000000..2a157e6 --- /dev/null +++ b/src/Intrepidity/LicensePlate/AbstractLicensePlate.php @@ -0,0 +1,41 @@ +licenseplate = str_replace(' ', '', $licenseplate); + } + + /** + * Check an array of regex patterns against the license plate string and give back the matching key if any + * + * @param array $patterns Array of regex patterns + * @param string $licenseplate License plate string + * @return bool|int|string Key for matching regex in the array, or false if none matches. + */ + protected function checkPatterns(array $patterns, $licenseplate) + { + foreach($patterns as $key => $pattern) + { + if(preg_match($pattern, $licenseplate)) + { + return $key; + } + } + + return false; + } +} \ No newline at end of file diff --git a/src/Intrepidity/LicensePlate/BelgianLicensePlate.php b/src/Intrepidity/LicensePlate/BelgianLicensePlate.php new file mode 100644 index 0000000..22c7056 --- /dev/null +++ b/src/Intrepidity/LicensePlate/BelgianLicensePlate.php @@ -0,0 +1,83 @@ +licenseplate)); + $sidecodes = array(); + $sidecodes[1] = '/^[a-zA-Z0-9]{1}[\d]{3}[a-zA-Z]{1}$/'; // 4 X.999.X and 9.999.X (1971-1973) + $sidecodes[2] = '/^[a-zA-Z]{3}[\d]{3}$/'; // 5 XXX-999 (1973-2008) + $sidecodes[3] = '/^[\d]{3}[a-zA-Z]{3}$/'; // 6 999-XXX (2008-2010) + $sidecodes[4] = '/^[\d]{1}[a-zA-Z]{3}[\d]{3}$/';// 7 9-XXX-999 (2010-current) + $sidecodes[5] = '/^[\d]{4}[a-zA-Z]{3}$/'; // 8 9-999-XXX (2010-current) + + return $this->checkPatterns($sidecodes, $licenseplate); + } + + /** + * Tests if the license plate is valid + * The license plate is valid if the sidecode can be determined + * + * @return bool + */ + public function isValid() + { + return $this->getSidecode() != false; + } + + /** + * Format the license plate + * + * Example: will output 196-BTD for input of 196btd + * + * @param int $sidecode Optional input of sidecode. Automatically determined if omitted + * @return string Formatted license plate + */ + public function format($sidecode = 0) + { + if($sidecode === 0) + { + $sidecode = $this->getSidecode(); + } + + if(false === $sidecode) + { + return false; + } + + $licenseplate = strtoupper(str_replace(array('-', '.'), '', $this->licenseplate)); + + switch($sidecode) + { + case 1: + return substr($licenseplate, 0, 1) . "." . substr($licenseplate, 1, 3) . "." . substr($licenseplate, 4, 1); + + case 2: + case 3: + return substr($licenseplate, 0, 3) . "-" . substr($licenseplate, 3, 3); + + case 4: + case 5: + return substr($licenseplate, 0, 1) . "-" . substr($licenseplate, 1, 3) . "-" . substr($licenseplate, 4, 3); + } + } + + public function getTwoLetterISO() + { + return 'BE'; + } + + public function getThreeLetterISO() + { + return 'BEL'; + } +} \ No newline at end of file diff --git a/src/Intrepidity/LicensePlate/DutchLicensePlate.php b/src/Intrepidity/LicensePlate/DutchLicensePlate.php new file mode 100644 index 0000000..a0e4fac --- /dev/null +++ b/src/Intrepidity/LicensePlate/DutchLicensePlate.php @@ -0,0 +1,136 @@ +licenseplate)); + $sidecodes = array(); + + // Special sidecodes + $sidecodes['CD'] = '/^CD[\d]{2,4}$/'; // Corps diplomatique license plates + $sidecodes['CDJ'] = '/^CDJ[\d]{2,3}$/'; // Judges of the international courts of justice + $sidecodes['AA'] = '/^AA[\d]{2,3}$/'; // Members of the royal family + + // Normal sidecodes + $sidecodes[1] = '/^[a-zA-Z]{2}[\d]{2}[\d]{2}$/'; // 1 XX-99-99 + $sidecodes[2] = '/^[\d]{2}[\d]{2}[a-zA-Z]{2}$/'; // 2 99-99-XX + $sidecodes[3] = '/^[\d]{2}[a-zA-Z]{2}[\d]{2}$/'; // 3 99-XX-99 + $sidecodes[4] = '/^[a-zA-Z]{2}[\d]{2}[a-zA-Z]{2}$/'; // 4 XX-99-XX + $sidecodes[5] = '/^[a-zA-Z]{2}[a-zA-Z]{2}[\d]{2}$/'; // 5 XX-XX-99 + $sidecodes[6] = '/^[\d]{2}[a-zA-Z]{2}[a-zA-Z]{2}$/'; // 6 99-XX-XX + $sidecodes[7] = '/^[\d]{2}[a-zA-Z]{3}[\d]{1}$/'; // 7 99-XXX-9 + $sidecodes[8] = '/^[\d]{1}[a-zA-Z]{3}[\d]{2}$/'; // 8 9-XXX-99 + $sidecodes[9] = '/^[a-zA-Z]{2}[\d]{3}[a-zA-Z]{1}$/'; // 9 XX-999-X + $sidecodes[10] = '/^[a-zA-Z]{1}[\d]{3}[a-zA-Z]{2}$/'; // 10 X-999-XX + $sidecodes[11] = '/^[a-zA-Z]{3}[\d]{2}[a-zA-Z]{1}$/'; // 11 XXX-99-X + $sidecodes[12] = '/^[a-zA-Z]{1}[\d]{2}[a-zA-Z]{3}$/'; // 12 X-99-XXX + $sidecodes[13] = '/^[\d]{1}[a-zA-Z]{2}[\d]{3}$/'; // 13 9-XX-999 + $sidecodes[14] = '/^[\d]{3}[a-zA-Z]{2}[\d]{1}$/'; // 14 999-XX-9 + + return $this->checkPatterns($sidecodes, $licenseplate); + } + + /** + * Format the license plate + * + * Example: will output 08-TT-NP for input of 08ttnp + * + * @param int $sidecode Optional input of sidecode. Automatically determined if omitted + * @return string Formatted license plate + */ + public function format($sidecode = 0) + { + if($sidecode === 0) + { + $sidecode = $this->getSidecode(); + } + + if(false === $sidecode) + { + return false; + } + + $licenseplate = strtoupper(str_replace('-', '', $this->licenseplate)); + + switch($sidecode) + { + case 'CD': + if(strlen($licenseplate) < 6) + { + return 'CD-' . substr($licenseplate, 2); + } + else + { + return 'CD-' . substr($licenseplate, 2, 2) . "-" . substr($licenseplate, 4, 2); + } + + case 'CDJ': + return 'CDJ-' . substr($licenseplate, 3); + + case 'AA': + return 'AA-' . substr($licenseplate, 2); + + case 7: + case 9: + // XX-XXX-X + return substr($licenseplate, 0, 2) . '-' . substr($licenseplate, 2, 3) .'-' . substr($licenseplate, 5, 1); + + case 8: + case 10: + // X-XXX-XX + return substr($licenseplate, 0, 1) . '-' . substr($licenseplate, 1, 3) . '-' . substr($licenseplate, 4, 2); + + case 11: + case 14: + // XXX-XX-X + return substr($licenseplate, 0, 3) . '-' . substr($licenseplate, 3, 2) . '-' . substr($licenseplate, 5, 1); + + case 12: + case 13: + // X-XX-XXX + return substr($licenseplate, 0, 1) . '-' . substr($licenseplate, 1, 2) . '-' . substr($licenseplate, 3, 3); + + default: + // Sidecodes 1-6: XX-XX-XX + return substr($licenseplate, 0, 2) . '-' . substr($licenseplate, 2, 2) . '-' . substr($licenseplate, 4, 2); + } + } + + /** + * Tests if the license plate is valid + * The license plate is valid if the sidecode can be determined + * + * @return bool + */ + public function isValid() + { + return $this->getSidecode() != false; + } + + public function getTwoLetterISO() + { + return 'NL'; + } + + public function getThreeLetterISO() + { + return 'NLD'; + } +} diff --git a/src/Intrepidity/LicensePlate/FrenchLicensePlate.php b/src/Intrepidity/LicensePlate/FrenchLicensePlate.php new file mode 100644 index 0000000..284b828 --- /dev/null +++ b/src/Intrepidity/LicensePlate/FrenchLicensePlate.php @@ -0,0 +1,101 @@ +licenseplate)); + $sidecodes = array(); + + // Special sidecodes + $sidecodes['CIV'] = '/^[\d]{2,3}[DRNEdrne]{1}[\d]{4}[a-zA-Z]{1}$/'; // Civilian government cars 1976-2009: 99D-9999X + $sidecodes['MIL'] = '/^[\d]{8}$/'; // Military: 99999999 + + // Normal sidecodes + $sidecodes[1] = '/^[\d]{2,4}[a-zA-Z]{2,3}[\d]{2,3}$/'; // 1 9999-XX-99; 1976-2009 + $sidecodes[2] = '/^[a-zA-Z]{2}[\d]{3}[a-zA-Z]{2}$/'; // 2 XX-999-XX; 2009-now + + return $this->checkPatterns($sidecodes, $licenseplate); + } + + /** + * Format the license plate + * + * Example: will output 08-TT-NP for input of 08ttnp + * + * @param int $sidecode Optional input of sidecode. Automatically determined if omitted + * @return string Formatted license plate + */ + public function format($sidecode = 0) + { + if($sidecode === 0) + { + $sidecode = $this->getSidecode(); + } + + if(false === $sidecode) + { + return false; + } + + $licenseplate = strtoupper(str_replace('-', '', $this->licenseplate)); + + switch($sidecode) + { + case 'MIL': + return $this->licenseplate; + break; + + case 'CIV': + preg_match('/^([\d]{2,3}[DRNEdrne]{1})([\d]{4}[a-zA-Z]{1})$/', $licenseplate, $parts); + return $parts[1] . '-' . $parts[2]; + break; + + case 1: + preg_match('/^([\d]{2,4})([a-zA-Z]{2,3})([\d]{2,3})$/', $licenseplate, $parts); + return $parts[1] . '-' . $parts[2] . '-' . $parts[3]; + + case 2: + return substr($licenseplate, 0, 2) . '-' . substr($licenseplate, 2, 3) . '-' . substr($licenseplate, 5, 2); + } + + return $licenseplate; + } + + /** + * Tests if the license plate is valid + * The license plate is valid if the sidecode can be determined + * + * @return bool + */ + public function isValid() + { + return $this->getSidecode() != false; + } + + public function getTwoLetterISO() + { + return 'FR'; + } + + public function getThreeLetterISO() + { + return 'FRA'; + } +} diff --git a/src/Intrepidity/LicensePlate/GermanLicensePlate.php b/src/Intrepidity/LicensePlate/GermanLicensePlate.php new file mode 100644 index 0000000..6049253 --- /dev/null +++ b/src/Intrepidity/LicensePlate/GermanLicensePlate.php @@ -0,0 +1,311 @@ +district_regex = '/^('.implode('|',self::DISCTRICTS).')'; + $this->core_default_plate_regex = '[a-zA-Z]{1,2}[\d]{1,4}'; + $this->default_plate_regex = $this->core_default_plate_regex.'$/'; + $this->default_complete_plate_regex = $this->district_regex.$this->default_plate_regex; + $this->original_licenseplate = trim($licenseplate); + parent::__construct($licenseplate); + } + + /** + * Get the sidecode of the license plate + * + * More info: https://nl.wikipedia.org/wiki/Lijst_van_Duitse_kentekens#Speciale_kentekens (in Dutch) + * + * @return bool|int|string + */ + public function getSidecode() + { + $licenseplate = strtoupper(trim(str_replace(array('-', ' '), '', $this->licenseplate))); + if (strlen($licenseplate) > 8) + { + return false; + } + $sidecodes = array(); + + // Special sidecodes + $sidecodes[self::SIDE_CODE_POLITICAL_HEADS] = '/^(0[0-4]{1,1}|1{2,2})$/'; // Political heads + $sidecodes[self::SIDE_CODE_CORPS_DIPLOMATIC] = '/^0[\d]{3,6}$/'; // Corps diplomatique license plates + $sidecodes[self::SIDE_CODE_AMERICAN_FORCES] = '/^(AD|AF|HK|IF)'.$this->default_plate_regex; // American forces license plates + $sidecodes[self::SIDE_CODE_SPECIAL_TRANSPORT] = '/^AG'.$this->default_plate_regex; // Special transport license plates + $sidecodes[self::SIDE_CODE_FEDERAL_POLICE] = '/^(BG|BP)[\d]{3,6}$/'; // German federal police license plates + $sidecodes[self::SIDE_CODE_TECHNICAL_RELIEF] = '/^THW(8|9)[\d]{3,4}$/'; // Federal Agency for Technical Relief license plates + $sidecodes[self::SIDE_CODE_NATO] = '/^X[\d]{4,4}$/'; // NATO license plates + $sidecodes[self::SIDE_CODE_ARMY] = '/^Y[\d]{5,6}$/'; // Army license plates + $sidecodes[self::SIDE_CODE_HISTORICAL] = $this->district_regex.$this->core_default_plate_regex.'H$/'; // Historical vehicles license plates + $sidecodes[self::SIDE_CODE_ELECTRICAL] = $this->district_regex.$this->core_default_plate_regex.'E$/'; // Electric vehicles license plates + + // Normal sidecodes + $sidecodes[self::SIDE_CODE_DEFAULT] = $this->default_complete_plate_regex; // Default: district, 1-2 letters, 1-4 numbers + + return $this->checkPatterns($sidecodes, $licenseplate); + } + + /** + * Format the license plate + * + * Example: will output J YA 253 for input of jya253 and FRI ES 807 for fries807 + * + * @param int $sidecode Optional input of sidecode. Automatically determined if omitted + * @return string Formatted license plate + */ + public function format($sidecode = 0) + { + //TODO: find out right format per side code + if($sidecode === 0) + { + $sidecode = $this->getSidecode(); + } + if(false === $sidecode) + { + return false; + } + + $original_transformed_licenseplate = strtoupper($this->original_licenseplate); + $licenseplate = str_replace(array('-', ' '), '', $original_transformed_licenseplate); + + switch($sidecode) + { + case self::SIDE_CODE_DEFAULT: + return $this->formatDefaultLicensePlate($original_transformed_licenseplate, $licenseplate); + + case self::SIDE_CODE_ELECTRICAL: + $formatted_license_plate = $this->formatDefaultLicensePlate(substr($original_transformed_licenseplate,0, -1), substr($licenseplate,0, -1)).'E'; + return $formatted_license_plate; + + case self::SIDE_CODE_HISTORICAL: + $formatted_license_plate = $this->formatDefaultLicensePlate(substr($original_transformed_licenseplate,0, -1), substr($licenseplate,0, -1)).'H'; + return $formatted_license_plate; + + case self::SIDE_CODE_POLITICAL_HEADS: + return $licenseplate[0] . "-" . $licenseplate[1]; + + case self::SIDE_CODE_CORPS_DIPLOMATIC: + $parts = $this->getLicensePlateParts($original_transformed_licenseplate); + if (count($parts) === 3 && $parts[0] === '0') + { + $second_part_length = strlen($parts[1]); + $third_part_length = strlen($parts[2]); + if ($second_part_length >= 2 && $second_part_length <= 3 && $third_part_length >= 1 && $third_part_length <= 3) + { + return implode('-', $parts); + } + } + if (strlen($licenseplate) > 6) + { + return $licenseplate[0].'-'.substr($licenseplate, 1, 3).'-'.substr($licenseplate, 4); + } + return $licenseplate[0].'-'.substr($licenseplate, 1, 2).'-'.substr($licenseplate, 3); + + case self::SIDE_CODE_AMERICAN_FORCES: + $number_matches = array(); + preg_match('/\d/', $licenseplate, $number_matches, PREG_OFFSET_CAPTURE); + $first_number_index = $number_matches[0][1]; + + return substr($licenseplate, 0,2).' '.substr($licenseplate, 2, $first_number_index-2).' '. substr($licenseplate, $first_number_index); + + case self::SIDE_CODE_TECHNICAL_RELIEF: + return substr($licenseplate, 0,3).' '.substr($licenseplate, 3); + + case self::SIDE_CODE_FEDERAL_POLICE: + return substr($licenseplate, 0,2).' '.substr($licenseplate, 2, 2).'-'.substr($licenseplate, 4); + + case self::SIDE_CODE_ARMY: + if (strlen($licenseplate) === 6) + { + return 'Y-'.substr($licenseplate, 1, 2).' '.substr($licenseplate, 3); + } + return 'Y-'.substr($licenseplate, 1, 3).' '.substr($licenseplate, 4); + + case self::SIDE_CODE_NATO: + return 'X-'.substr($licenseplate,1); + + case self::SIDE_CODE_SPECIAL_TRANSPORT: + //TODO: implement, need more information + default: + // Sidecodes without any known format + return $this->licenseplate; + } + } + + /** + * Tests if the license plate is valid + * The license plate is valid if the sidecode can be determined + * + * @return bool + */ + public function isValid() + { + return $this->getSidecode() !== false; + } + + private function formatDefaultLicensePlate($original_transformed_licenseplate, $licenseplate) + { + $delimiter_position = $this->getDelimiterPositionFromLicensePlate($original_transformed_licenseplate); + if ($delimiter_position !== false) + { + $formatted_license_plate = $this->getFormattedLicensePlateForLicensePlateWithFormat($original_transformed_licenseplate, $licenseplate, $delimiter_position); + if (is_string($formatted_license_plate)) + { + return $formatted_license_plate; + } + } + + return $this->getFormattedLicensePlateForLicensePlateWithoutFormat($licenseplate); + } + + private function getDelimiterPositionFromLicensePlate($original_transformed_licenseplate, $start = 0, $length = 4) + { + $dash_position = strpos(substr($original_transformed_licenseplate,$start,$length), '-'); + if ($dash_position !== false) + { + return $dash_position; + } + return strpos(substr($original_transformed_licenseplate,$start,$length), ' '); + } + + private function getFormattedLicensePlateForLicensePlateWithFormat($original_transformed_licenseplate, $licenseplate, $delimiter_position) + { + $district = substr($original_transformed_licenseplate, 0,$delimiter_position); + $district_length = strlen($district); + + $letters_only = preg_replace("/[^a-zA-Z]+/", "", $original_transformed_licenseplate); + $middle_part = substr($letters_only,$district_length); + $middle_part_length = strlen($middle_part); + + if ($middle_part_length <= 2 && strlen($letters_only) > $district_length) + { + return $district.' '.$middle_part.' '.substr($licenseplate, $district_length + $middle_part_length); + } + return false; + } + + private function getFormattedLicensePlateForLicensePlateWithoutFormat($licenseplate) + { + $possible_districts = array(); + $letters_only = $result = preg_replace("/[^a-zA-Z]+/", "", $licenseplate); + $letters_only_length = strlen($letters_only); + $start = 0; + if ($letters_only_length > 2) + { + $start = $letters_only_length - 2; + } + for($i = $start; $i < $letters_only_length; $i ++) + { + $district = substr($letters_only,0, $i); + if (preg_match($this->district_regex.'$/', $district) === 1) + { + if (strlen($district) >= ($letters_only_length-2)) + { + $possible_districts[] = $district; + } + if (count($possible_districts) > 2) + { + array_shift($possible_districts); + } + } + } + //always prioritise the shortest possible (most chance to be right since it's a bigger city). + $district = $possible_districts[0]; + $district_length = strlen($district); + + $number_matches = array(); + preg_match('/\d/', $licenseplate, $number_matches, PREG_OFFSET_CAPTURE); + $middle_part_length = $number_matches[0][1] - $district_length; + + return $district.' '. + substr($licenseplate, $district_length, $middle_part_length).' '. + substr($licenseplate, $middle_part_length + $district_length); + } + + private function getLicensePlateParts($original_transformed_licenseplate) + { + $parts = array(); + $exploded_by_dash = explode('-', $original_transformed_licenseplate); + foreach($exploded_by_dash as $parted_by_dash) + { + $exploded_by_space = explode(' ', $parted_by_dash); + foreach ($exploded_by_space as $parted_by_space) + { + $parts[] = $parted_by_space; + } + } + return $parts; + } + + public function getTwoLetterISO() + { + return 'DE'; + } + + public function getThreeLetterISO() + { + return 'DEU'; + } +} \ No newline at end of file diff --git a/src/Intrepidity/LicensePlate/IsraeliLicensePlate.php b/src/Intrepidity/LicensePlate/IsraeliLicensePlate.php new file mode 100644 index 0000000..a70b0ed --- /dev/null +++ b/src/Intrepidity/LicensePlate/IsraeliLicensePlate.php @@ -0,0 +1,79 @@ +licenseplate); + + $sidecodes = array(); + $sidecodes['MTZ'] = '/^מצ[\d]{1,5}$/'; // Military police license plate + $sidecodes['M'] = '/^מ[\d]{1,7}$/'; // Police license plate + $sidecodes['TZ'] = '/^צ[\d]{1,7}$/'; // Military license plate + $sidecodes[1] = '/^[\d]{7}$/'; // Basic license plate + + return $this->checkPatterns($sidecodes, $licenseplate); + } + + /** + * Tests if the license plate is valid + * The license plate is valid if the string contains 7 numeric characters (and dashes) + * + * @return bool + */ + public function isValid() + { + return $this->getSidecode() != false; + } + + /** + * Format the license plate + * + * Example: will output 12-345-67 for input of 1234567 + * + * @return string Formatted license plate + */ + public function format() + { + $licenseplate = strtoupper(str_replace(array('-', '.'), '', $this->licenseplate)); + + if(false === $this->isValid()) + { + return false; + } + + switch($this->getSidecode()) + { + case 1: + return substr($licenseplate, 0, 2) . '-' . substr($licenseplate, 2, 3) . '-' . substr($licenseplate, 5, 2); + break; + + case 'M': + return 'מ-' . mb_substr($licenseplate, 1); + break; + + case 'TZ': + return 'צ-' . mb_substr($licenseplate, 1); + break; + + case 'MTZ': + return 'מצ-'.mb_substr($licenseplate, 2); + break; + + default: + return $licenseplate; // Formatting for special license plates not yet implemented + break; + } + } + + public function getTwoLetterISO() + { + return 'IL'; + } + + public function getThreeLetterISO() + { + return 'ISR'; + } +} \ No newline at end of file diff --git a/src/Intrepidity/LicensePlate/LicensePlateInterface.php b/src/Intrepidity/LicensePlate/LicensePlateInterface.php new file mode 100644 index 0000000..9bb5b90 --- /dev/null +++ b/src/Intrepidity/LicensePlate/LicensePlateInterface.php @@ -0,0 +1,11 @@ +licenseplate)); + $sidecodes = array(); + + // Normal sidecodes + $sidecodes[1] = '/^[A-Z]{1}[\d]{4}$/'; // A 5000 + $sidecodes[2] = '/^[A-Z]{2}[\d]{3}$/'; // AA 999 + $sidecodes[3] = '/^[A-Z]{2}[\d]{4}$/'; // CD 5000 + + return $this->checkPatterns($sidecodes, $licenseplate); + } + + /** + * Format the license plate + * + * Example: will output 08-TT-NP for input of 08ttnp + * + * @param int $sidecode Optional input of sidecode. Automatically determined if omitted + * @return string Formatted license plate + */ + public function format($sidecode = 0) + { + if($sidecode === 0) + { + $sidecode = $this->getSidecode(); + } + + if(false === $sidecode) + { + return false; + } + + $licenseplate = strtoupper(str_replace(array(' ', '-'), '', $this->licenseplate)); + + switch($sidecode) + { + case 1: + return substr($licenseplate, 0, 1) . ' ' . substr($licenseplate, 1); + break; + + case 2: + case 3: + return substr($licenseplate, 0, 2) . ' ' . substr($licenseplate, 2); + } + + return $licenseplate; + } + + /** + * Tests if the license plate is valid + * The license plate is valid if the sidecode can be determined + * + * @return bool + */ + public function isValid() + { + return $this->getSidecode() != false; + } + + public function getTwoLetterISO() + { + return 'LU'; + } + + public function getThreeLetterISO() + { + return 'LUX'; + } +} diff --git a/src/Intrepidity/LicensePlate/SpanishLicensePlate.php b/src/Intrepidity/LicensePlate/SpanishLicensePlate.php new file mode 100644 index 0000000..00d7773 --- /dev/null +++ b/src/Intrepidity/LicensePlate/SpanishLicensePlate.php @@ -0,0 +1,97 @@ +regionCodes) . "|" . implode("|", $this->specialCodes) . ")"; + $newPrefixRegex = "(" . implode("|", $this->colorCodes) . ")?"; + + $this->sideCodes = [ + 1 => "/^{$oldPrefixRegex}([\d]{1,6})$/", // 1900 - 1971 + 2 => "/^{$oldPrefixRegex}([\d]{4})([a-zA-Z]{1,2})$/", // 1971 - 2000 + 3 => "/^{$newPrefixRegex}([\d]{4})([a-zA-Z]{3})$/" // 2000 - current + ]; + } + + public function getSidecode() + { + return $this->checkPatterns($this->sideCodes, $this->licenseplate); + } + + public function format() + { + $sideCode = $this->getSidecode(); + + $parts = []; + preg_match($this->sideCodes[$sideCode], $this->licenseplate, $parts); + + switch ($sideCode) { + case 1: + return $parts[1] . '-' . $parts[2]; + break; + + case 2: + return $parts[1] . '-' . $parts[2] . '-'. $parts[3]; + break; + + case 3: + if ($parts[1] !== '') { + return $parts[1] . '-' . $parts[2] . '-' . $parts[3]; + } + + return $parts[2] . '-' . $parts[3]; + + break; + } + } + + public function isValid() + { + return $this->getSidecode() !== false; + } + + public function getTwoLetterISO() + { + return 'ES'; + } + + public function getThreeLetterISO() + { + return 'ESP'; + } +} \ No newline at end of file diff --git a/src/Intrepidity/LicensePlate/UKLicensePlate.php b/src/Intrepidity/LicensePlate/UKLicensePlate.php new file mode 100644 index 0000000..45eeb10 --- /dev/null +++ b/src/Intrepidity/LicensePlate/UKLicensePlate.php @@ -0,0 +1,125 @@ +licenseplate)); + $sidecodes = array(); + $sidecodes['NI'] = '/^[\d]{1,4}[a-zA-Z]{2}$/'; // Northern Ireland 1958-1985 + $sidecodes['JER'] = '/^J[\d]{1,6}$/'; // J999999; Jersey + $sidecodes['GUE'] = '/^[\d]{1,5}$/'; // 99999; Guernsey + $sidecodes['ALD'] = '/^AY[\d]{1,4}$/'; // AY9999; Alderney + + // Normal sidecodes + $sidecodes[1] = '/^[A-Z]{1,2}[\d]{1,4}$/'; // A(A) 9999; 1903-1932 + $sidecodes[2] = '/^(([A-Z]{3}[\d]{1,4})|([\d]{1,4}[A-Z]{1,3}))$/'; // XXX 999 and 999 XXX; 1932-1963 and Northern Ireland 1985-now + $sidecodes[3] = '/^[A-Z]{1,3}[\d]{1,4}[A-Z]{1}$/'; // XXX 9999X; 1963-1982 + $sidecodes[4] = '/^[A-Z]{1}[\d]{2,3}[A-Z]{3}$/'; // A999 XXX; 1982-2001 + $sidecodes[5] = '/^[A-Z]{2}[\d]{2}[A-Z]{3}$/'; // XX99 XXX; 2001-now + + return $this->checkPatterns($sidecodes, $licenseplate); + } + + /** + * Format the license plate + * + * Example: will output 08-TT-NP for input of 08ttnp + * + * @param int $sidecode Optional input of sidecode. Automatically determined if omitted + * @return string Formatted license plate + */ + public function format($sidecode = 0) + { + if($sidecode === 0) + { + $sidecode = $this->getSidecode(); + } + + if(false === $sidecode) + { + return false; + } + + $licenseplate = strtoupper(str_replace(array(' ', '-'), '', $this->licenseplate)); + + switch($sidecode) + { + case 1: + preg_match('/^([a-zA-Z]{1,2})([\d]{1,4})$/', $licenseplate, $parts); + return $parts[1] . ' ' . $parts[2]; + break; + + case 2: + if (preg_match('/^[a-zA-Z]{3}[\d]{1,4}$/', $licenseplate)) { + return substr($licenseplate, 0, 3) . ' ' . substr($licenseplate, 3); + } else { + preg_match('/^([\d]{1,4})([a-zA-Z]{1,3})$/', $licenseplate, $parts); + return $parts[1] . ' ' . $parts[2]; + } + break; + + case 3: + preg_match('/^([a-zA-Z]{1,3})([\d]{1,4}[a-zA-Z]{1})$/', $licenseplate, $parts); + return $parts[1] . ' ' . $parts[2]; + break; + + case 4: + preg_match('/^([A-Z]{1}[\d]{2,3})([A-Z]{3})$/', $licenseplate, $parts); + return $parts[1] . ' ' . $parts[2]; + break; + + case 5: + return substr($licenseplate, 0, 4) . ' ' . substr($licenseplate, 4, 3); + break; + + case 'NI': + preg_match('/^([\d]{1,4})([a-zA-Z]{2})$/', $licenseplate, $parts); + return $parts[1] . ' ' . $parts[2]; + break; + + case 'JER': + case 'GUE': + case 'ALD': + return $licenseplate; + } + + return $licenseplate; + } + + /** + * Tests if the license plate is valid + * The license plate is valid if the sidecode can be determined + * + * @return bool + */ + public function isValid() + { + return $this->getSidecode() != false; + } + + /** Country codes as per https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes */ + public function getTwoLetterISO() + { + return 'GB'; + } + + public function getThreeLetterISO() + { + return 'GBR'; + } +} diff --git a/tests/BelgianLicensePlateFormatTest.php b/tests/BelgianLicensePlateFormatTest.php new file mode 100644 index 0000000..0d4454f --- /dev/null +++ b/tests/BelgianLicensePlateFormatTest.php @@ -0,0 +1,32 @@ +assertEquals($licenseplate->format(), 'X.999.X'); + + $licenseplate = new BelgianLicensePlate('9999x'); + $this->assertEquals($licenseplate->format(), '9.999.X'); + + $licenseplate = new BelgianLicensePlate('999XXX'); + $this->assertEquals($licenseplate->format(), '999-XXX'); + + $licenseplate = new BelgianLicensePlate('xxx999'); + $this->assertEquals($licenseplate->format(), 'XXX-999'); + + $licenseplate = new BelgianLicensePlate('9999xxx'); + $this->assertEquals($licenseplate->format(), '9-999-XXX'); + + $licenseplate = new BelgianLicensePlate('9xxx999'); + $this->assertEquals($licenseplate->format(), '9-XXX-999'); + + $licenseplate = new BelgianLicensePlate('9x-x.x-9.9-9'); + $this->assertEquals($licenseplate->format(), '9-XXX-999'); + + $licenseplate = new BelgianLicensePlate('thisisnotalicenseplate'); + $this->assertFalse($licenseplate->format()); + } +} \ No newline at end of file diff --git a/tests/BelgianLicensePlateSidecodeTest.php b/tests/BelgianLicensePlateSidecodeTest.php new file mode 100644 index 0000000..8218ede --- /dev/null +++ b/tests/BelgianLicensePlateSidecodeTest.php @@ -0,0 +1,45 @@ +assertEquals($licenseplate->getSidecode(), 1); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new BelgianLicensePlate('9999x'); + $this->assertEquals($licenseplate->getSidecode(), 1); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode2() + { + $licenseplate = new BelgianLicensePlate('xxx999'); + $this->assertEquals($licenseplate->getSidecode(), 2); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode3() + { + $licenseplate = new BelgianLicensePlate('999xxx'); + $this->assertEquals($licenseplate->getSidecode(), 3); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode4() + { + $licenseplate = new BelgianLicensePlate('9xxx999'); + $this->assertEquals($licenseplate->getSidecode(), 4); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode5() + { + $licenseplate = new BelgianLicensePlate('9999xxx'); + $this->assertEquals($licenseplate->getSidecode(), 5); + $this->assertTrue($licenseplate->isValid()); + } +} \ No newline at end of file diff --git a/tests/DutchLicensePlateFormatTest.php b/tests/DutchLicensePlateFormatTest.php new file mode 100644 index 0000000..84c48dd --- /dev/null +++ b/tests/DutchLicensePlateFormatTest.php @@ -0,0 +1,50 @@ +assertEquals($licenseplate->format(), '10-AAA-1'); + + $licenseplate = new DutchLicensePlate('10AAA1'); + $this->assertEquals($licenseplate->format(), '10-AAA-1'); + + $licenseplate = new DutchLicensePlate('10-AAA-1'); + $this->assertEquals($licenseplate->format(), '10-AAA-1'); + + $licenseplate = new DutchLicensePlate('10-AAA1'); + $this->assertEquals($licenseplate->format(), '10-AAA-1'); + + $licenseplate = new DutchLicensePlate('1-0-a-a-a-1'); + $this->assertEquals($licenseplate->format(), '10-AAA-1'); + + $licenseplate = new DutchLicensePlate('9abc99'); + $this->assertEquals($licenseplate->format(), '9-ABC-99'); + + $licenseplate = new DutchLicensePlate('999xx9'); + $this->assertEquals($licenseplate->format(), '999-XX-9'); + + $licenseplate = new DutchLicensePlate('9xx999'); + $this->assertEquals($licenseplate->format(), '9-XX-999'); + + $licenseplate = new DutchLicensePlate('45fjvb'); + $this->assertEquals($licenseplate->format(), '45-FJ-VB'); + + $licenseplate = new DutchLicensePlate('thisisnotalicenseplate'); + $this->assertFalse($licenseplate->format()); + + $licenseplate = new DutchLicensePlate('08ttnp'); + $this->assertEquals($licenseplate->format(7), '08-TTN-P', 'Test format using specific sidecode'); + + $licenseplate = new DutchLicensePlate('aa123'); + $this->assertEquals($licenseplate->format(), 'AA-123'); + + $licenseplate = new DutchLicensePlate('cd123'); + $this->assertEquals($licenseplate->format(), 'CD-123'); + + $licenseplate = new DutchLicensePlate('cdj123'); + $this->assertEquals($licenseplate->format(), 'CDJ-123'); + } +} \ No newline at end of file diff --git a/tests/DutchLicensePlateSidecodeTest.php b/tests/DutchLicensePlateSidecodeTest.php new file mode 100644 index 0000000..011a9d5 --- /dev/null +++ b/tests/DutchLicensePlateSidecodeTest.php @@ -0,0 +1,154 @@ +assertEquals($licenseplate->getSidecode(), 1); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode2() + { + $licenseplate = new DutchLicensePlate('99-99-XX'); + $this->assertEquals($licenseplate->getSidecode(), 2); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode3() + { + $licenseplate = new DutchLicensePlate('99-XX-99'); + $this->assertEquals($licenseplate->getSidecode(), 3); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode4() + { + $licenseplate = new DutchLicensePlate('XX-99-XX'); + $this->assertEquals($licenseplate->getSidecode(), 4); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode5() + { + $licenseplate = new DutchLicensePlate('XX-XX-99'); + $this->assertEquals($licenseplate->getSidecode(), 5); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode6() + { + $licenseplate = new DutchLicensePlate('99-XX-XX'); + $this->assertEquals($licenseplate->getSidecode(), 6); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode7() + { + $licenseplate = new DutchLicensePlate('99-XXX-9'); + $this->assertEquals($licenseplate->getSidecode(), 7); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode8() + { + $licenseplate = new DutchLicensePlate('9-XXX-99'); + $this->assertEquals($licenseplate->getSidecode(), 8); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode9() + { + $licenseplate = new DutchLicensePlate('XX-999-X'); + $this->assertEquals($licenseplate->getSidecode(), 9); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode10() + { + $licenseplate = new DutchLicensePlate('X-999-XX'); + $this->assertEquals($licenseplate->getSidecode(), 10); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode11() + { + $licenseplate = new DutchLicensePlate('XXX-99-X'); + $this->assertEquals($licenseplate->getSidecode(), 11); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode12() + { + $licenseplate = new DutchLicensePlate('X-99-XXX'); + $this->assertEquals($licenseplate->getSidecode(), 12); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode13() + { + $licenseplate = new DutchLicensePlate('9-XX-999'); + $this->assertEquals($licenseplate->getSidecode(), 13); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecode14() + { + $licenseplate = new DutchLicensePlate('999-XX-9'); + $this->assertEquals($licenseplate->getSidecode(), 14); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecodeCD() + { + $licenseplate = new DutchLicensePlate('CD123'); + $this->assertEquals($licenseplate->getSidecode(), 'CD'); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new DutchLicensePlate('CD1234'); + $this->assertEquals($licenseplate->getSidecode(), 'CD'); + $this->assertTrue($licenseplate->isValid()); + } + + public function testGetSidecodeCDJ() + { + $licenseplate = new DutchLicensePlate('CDJ123'); + $this->assertEquals($licenseplate->getSidecode(), 'CDJ'); + + $licenseplate = new DutchLicensePlate('CDJ12'); + $this->assertEquals($licenseplate->getSidecode(), 'CDJ'); + + $licenseplate = new DutchLicensePlate('CDJ1'); + $this->assertFalse($licenseplate->getSidecode()); + } + + public function testGetSidecodeAA() + { + $licenseplate = new DutchLicensePlate('AA12'); + $this->assertEquals($licenseplate->getSidecode(), 'AA'); + + $licenseplate = new DutchLicensePlate('AA123'); + $this->assertEquals($licenseplate->getSidecode(), 'AA'); + + $licenseplate = new DutchLicensePlate('AA1234'); + $this->assertEquals($licenseplate->getSidecode(), 1); + } + + public function testGetSidecodeFalse() + { + $licenseplate = new DutchLicensePlate('12345'); + $this->assertFalse($licenseplate->getSidecode()); + $this->assertFalse($licenseplate->isValid()); + + $licenseplate = new DutchLicensePlate('99-XX-9'); + $this->assertFalse($licenseplate->getSidecode()); + $this->assertFalse($licenseplate->isValid()); + + $licenseplate = new DutchLicensePlate('CDC123'); + $this->assertFalse($licenseplate->getSidecode()); + $this->assertFalse($licenseplate->isValid()); + } +} \ No newline at end of file diff --git a/tests/FrenchLicensePlateFormatTest.php b/tests/FrenchLicensePlateFormatTest.php new file mode 100644 index 0000000..c7fd756 --- /dev/null +++ b/tests/FrenchLicensePlateFormatTest.php @@ -0,0 +1,44 @@ +assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '12345678'); + + $licenseplate = new FrenchLicensePlate('99d1234x'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '99D-1234X'); + + $licenseplate = new FrenchLicensePlate('999d1234x'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '999D-1234X'); + + $licenseplate = new FrenchLicensePlate('99xx99'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '99-XX-99'); + + $licenseplate = new FrenchLicensePlate('999xx99'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '999-XX-99'); + + $licenseplate = new FrenchLicensePlate('9999xx99'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '9999-XX-99'); + + $licenseplate = new FrenchLicensePlate('999xxx99'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '999-XXX-99'); + + $licenseplate = new FrenchLicensePlate('999xxx999'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '999-XXX-999'); + + $licenseplate = new FrenchLicensePlate('xx999xx'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'XX-999-XX'); + } +} \ No newline at end of file diff --git a/tests/FrenchLicensePlateSidecodeTest.php b/tests/FrenchLicensePlateSidecodeTest.php new file mode 100644 index 0000000..f659721 --- /dev/null +++ b/tests/FrenchLicensePlateSidecodeTest.php @@ -0,0 +1,37 @@ +assertEquals($licenseplate->getSidecode(), 'MIL'); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeCiv() + { + $licenseplate = new FrenchLicensePlate('99D-1234X'); + $this->assertEquals($licenseplate->getSidecode(), 'CIV'); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecode1() + { + $licenseplate = new FrenchLicensePlate('1234-AB-12'); + $this->assertEquals($licenseplate->getSidecode(), 1); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new FrenchLicensePlate('12-ABC-972'); + $this->assertEquals($licenseplate->getSidecode(), 1); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecode2() + { + $licenseplate = new FrenchLicensePlate('AB-123-AB'); + $this->assertEquals($licenseplate->getSidecode(), 2); + $this->assertTrue($licenseplate->isValid()); + } +} \ No newline at end of file diff --git a/tests/GermanLicensePlateFormatTest.php b/tests/GermanLicensePlateFormatTest.php new file mode 100644 index 0000000..1ac1e4f --- /dev/null +++ b/tests/GermanLicensePlateFormatTest.php @@ -0,0 +1,223 @@ +assertEquals('AA AA 900', $licenseplate->format(GermanLicensePlate::SIDE_CODE_DEFAULT)); + + //test magical license plate formatting #2 (priority to smallest district) + $licenseplate = new GermanLicensePlate('aaa900'); + $this->assertEquals('A AA 900', $licenseplate->format(GermanLicensePlate::SIDE_CODE_DEFAULT)); + + //test respecting given format with space + $licenseplate = new GermanLicensePlate('aa n900'); + $this->assertEquals('AA N 900', $licenseplate->format(GermanLicensePlate::SIDE_CODE_DEFAULT)); + + //test respecting given format with dash + $licenseplate = new GermanLicensePlate('aa-n900'); + $this->assertEquals('AA N 900', $licenseplate->format(GermanLicensePlate::SIDE_CODE_DEFAULT)); + + //test not respecting given format with dash but incorrect format + $licenseplate = new GermanLicensePlate('aan 900'); + $this->assertEquals('A AN 900', $licenseplate->format(GermanLicensePlate::SIDE_CODE_DEFAULT)); + + $licenseplate = new GermanLicensePlate('a an900'); + $this->assertEquals('A AN 900', $licenseplate->format(GermanLicensePlate::SIDE_CODE_DEFAULT)); + + $licenseplate = new GermanLicensePlate('a-an900'); + $this->assertEquals('A AN 900', $licenseplate->format(GermanLicensePlate::SIDE_CODE_DEFAULT)); + + $licenseplate = new GermanLicensePlate('a aaa900'); + $this->assertEquals('AA AA 900', $licenseplate->format(GermanLicensePlate::SIDE_CODE_DEFAULT)); + + //test 3 letter district, just to be sure + $licenseplate = new GermanLicensePlate('noh a900'); + $this->assertEquals('NOH A 900', $licenseplate->format(GermanLicensePlate::SIDE_CODE_DEFAULT)); + + //test 3 letter district with magical formatting, picks the smallest which in this case is still NOH + $licenseplate = new GermanLicensePlate('noha900'); + $this->assertEquals('NOH A 900', $licenseplate->format(GermanLicensePlate::SIDE_CODE_DEFAULT)); + + } + + public function testElectricFormat() + { + $licenseplate = new GermanLicensePlate('bnel269e'); + $this->assertEquals('BN EL 269E', $licenseplate->format(GermanLicensePlate::SIDE_CODE_ELECTRICAL)); + + $licenseplate = new GermanLicensePlate('bnel269E'); + $this->assertEquals('BN EL 269E', $licenseplate->format(GermanLicensePlate::SIDE_CODE_ELECTRICAL)); + + $licenseplate = new GermanLicensePlate('BNEL269E'); + $this->assertEquals('BN EL 269E', $licenseplate->format(GermanLicensePlate::SIDE_CODE_ELECTRICAL)); + + $licenseplate = new GermanLicensePlate('sb ac 23e'); + $this->assertEquals('SB AC 23E', $licenseplate->format(GermanLicensePlate::SIDE_CODE_ELECTRICAL)); + + $licenseplate = new GermanLicensePlate('m zx 726e'); + $this->assertEquals('M ZX 726E', $licenseplate->format(GermanLicensePlate::SIDE_CODE_ELECTRICAL)); + + $licenseplate = new GermanLicensePlate('b ge 6900e'); + $this->assertEquals('B GE 6900E', $licenseplate->format(GermanLicensePlate::SIDE_CODE_ELECTRICAL)); + + $licenseplate = new GermanLicensePlate('li fi 21e'); + $this->assertEquals('LI FI 21E', $licenseplate->format(GermanLicensePlate::SIDE_CODE_ELECTRICAL)); + } + + public function testHistoricalFormat() + { + $licenseplate = new GermanLicensePlate('e ra 55h'); + $this->assertEquals('E RA 55H', $licenseplate->format(GermanLicensePlate::SIDE_CODE_HISTORICAL)); + + $licenseplate = new GermanLicensePlate('e ra 55H'); + $this->assertEquals('E RA 55H', $licenseplate->format(GermanLicensePlate::SIDE_CODE_HISTORICAL)); + + $licenseplate = new GermanLicensePlate('wes q 501h'); + $this->assertEquals('WES Q 501H', $licenseplate->format(GermanLicensePlate::SIDE_CODE_HISTORICAL)); + + $licenseplate = new GermanLicensePlate('re mb 848h'); + $this->assertEquals('RE MB 848H', $licenseplate->format(GermanLicensePlate::SIDE_CODE_HISTORICAL)); + + $licenseplate = new GermanLicensePlate('me nb 7h'); + $this->assertEquals('ME NB 7H', $licenseplate->format(GermanLicensePlate::SIDE_CODE_HISTORICAL)); + + //test random WITH giving uppercase and correct format + $licenseplate = new GermanLicensePlate('ME NB 7H'); + $this->assertEquals('ME NB 7H', $licenseplate->format(GermanLicensePlate::SIDE_CODE_HISTORICAL)); + + //test random WITH giving uppercase and correct format, just with dashes instead of spaces + $licenseplate = new GermanLicensePlate('ME-NB-7H'); + $this->assertEquals('ME NB 7H', $licenseplate->format(GermanLicensePlate::SIDE_CODE_HISTORICAL)); + + $licenseplate = new GermanLicensePlate('mk b 260h'); + $this->assertEquals('MK B 260H', $licenseplate->format(GermanLicensePlate::SIDE_CODE_HISTORICAL)); + } + + public function testPoliticalHeadsFormat() + { + $licenseplate = new GermanLicensePlate('0-1'); + $this->assertEquals('0-1', $licenseplate->format(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS)); + + $licenseplate = new GermanLicensePlate('0 1'); + $this->assertEquals('0-1', $licenseplate->format(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS)); + + $licenseplate = new GermanLicensePlate('01'); + $this->assertEquals('0-1', $licenseplate->format(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS)); + + $licenseplate = new GermanLicensePlate('02'); + $this->assertEquals('0-2', $licenseplate->format(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS)); + + $licenseplate = new GermanLicensePlate('03'); + $this->assertEquals('0-3', $licenseplate->format(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS)); + + $licenseplate = new GermanLicensePlate('04'); + $this->assertEquals('0-4', $licenseplate->format(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS)); + + $licenseplate = new GermanLicensePlate('11'); + $this->assertEquals('1-1', $licenseplate->format(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS)); + } + + public function testCorpsDiplomaticFormat() + { + $licenseplate = new GermanLicensePlate('04422'); + $this->assertEquals('0-44-22', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + + $licenseplate = new GermanLicensePlate('0 100 100'); + $this->assertEquals('0-100-100', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + + $licenseplate = new GermanLicensePlate('0-17-112'); + $this->assertEquals('0-17-112', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + + $licenseplate = new GermanLicensePlate('0 17 112'); + $this->assertEquals('0-17-112', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + + $licenseplate = new GermanLicensePlate('0 17 175'); + $this->assertEquals('0-17-175', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + + $licenseplate = new GermanLicensePlate('0 59 114'); + $this->assertEquals('0-59-114', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + + //no way we could now this should be 0-166-1 instead of 0-16-61 + $licenseplate = new GermanLicensePlate('01661'); + $this->assertEquals('0-16-61', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + + $licenseplate = new GermanLicensePlate('0 166-1'); + $this->assertEquals('0-166-1', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + + $licenseplate = new GermanLicensePlate('0 158 1'); + $this->assertEquals('0-158-1', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + + $licenseplate = new GermanLicensePlate('0 100 9'); + $this->assertEquals('0-100-9', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + + $licenseplate = new GermanLicensePlate('0 110 1'); + $this->assertEquals('0-110-1', $licenseplate->format(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC)); + } + + public function testAmericanForcesFormat() + { + $licenseplate = new GermanLicensePlate('IFAG238'); + $this->assertEquals('IF AG 238', $licenseplate->format(GermanLicensePlate::SIDE_CODE_AMERICAN_FORCES)); + + $licenseplate = new GermanLicensePlate('HKML266'); + $this->assertEquals('HK ML 266', $licenseplate->format(GermanLicensePlate::SIDE_CODE_AMERICAN_FORCES)); + + $licenseplate = new GermanLicensePlate('AFAJ952'); + $this->assertEquals('AF AJ 952', $licenseplate->format(GermanLicensePlate::SIDE_CODE_AMERICAN_FORCES)); + + $licenseplate = new GermanLicensePlate('ADDV991'); + $this->assertEquals('AD DV 991', $licenseplate->format(GermanLicensePlate::SIDE_CODE_AMERICAN_FORCES)); + } + + public function testFederalPoliceFormat() + { + $licenseplate = new GermanLicensePlate('BP12345'); + $this->assertEquals('BP 12-345', $licenseplate->format(GermanLicensePlate::SIDE_CODE_FEDERAL_POLICE)); + + $licenseplate = new GermanLicensePlate('BP 12345'); + $this->assertEquals('BP 12-345', $licenseplate->format(GermanLicensePlate::SIDE_CODE_FEDERAL_POLICE)); + + $licenseplate = new GermanLicensePlate('BG12345'); + $this->assertEquals('BG 12-345', $licenseplate->format(GermanLicensePlate::SIDE_CODE_FEDERAL_POLICE)); + } + + public function testTechnicalReliefFormat() + { + $licenseplate = new GermanLicensePlate('THW80832'); + $this->assertEquals('THW 80832', $licenseplate->format(GermanLicensePlate::SIDE_CODE_TECHNICAL_RELIEF)); + + $licenseplate = new GermanLicensePlate('THW8207'); + $this->assertEquals('THW 8207', $licenseplate->format(GermanLicensePlate::SIDE_CODE_TECHNICAL_RELIEF)); + } + + public function testArmyFormat() + { + $licenseplate = new GermanLicensePlate('Y127508'); + $this->assertEquals('Y-127 508', $licenseplate->format(GermanLicensePlate::SIDE_CODE_ARMY)); + + $licenseplate = new GermanLicensePlate('Y401664'); + $this->assertEquals('Y-401 664', $licenseplate->format(GermanLicensePlate::SIDE_CODE_ARMY)); + + $licenseplate = new GermanLicensePlate('Y85129'); + $this->assertEquals('Y-85 129', $licenseplate->format(GermanLicensePlate::SIDE_CODE_ARMY)); + } + + public function testNatoFormat() + { + $licenseplate = new GermanLicensePlate('X1234'); + $this->assertEquals('X-1234', $licenseplate->format(GermanLicensePlate::SIDE_CODE_NATO)); + + $licenseplate = new GermanLicensePlate('x1234'); + $this->assertEquals('X-1234', $licenseplate->format(GermanLicensePlate::SIDE_CODE_NATO)); + + $licenseplate = new GermanLicensePlate('x 1234'); + $this->assertEquals('X-1234', $licenseplate->format(GermanLicensePlate::SIDE_CODE_NATO)); + + $licenseplate = new GermanLicensePlate(' x 1234 '); + $this->assertEquals('X-1234', $licenseplate->format(GermanLicensePlate::SIDE_CODE_NATO)); + } +} \ No newline at end of file diff --git a/tests/GermanLicensePlateSidecodeTest.php b/tests/GermanLicensePlateSidecodeTest.php new file mode 100644 index 0000000..99392fb --- /dev/null +++ b/tests/GermanLicensePlateSidecodeTest.php @@ -0,0 +1,160 @@ +assertEquals(GermanLicensePlate::SIDE_CODE_DEFAULT, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + + $licenseplate = new GermanLicensePlate('BBX900'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_DEFAULT, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeE() + { + $licenseplate = new GermanLicensePlate('bnel269e'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_ELECTRICAL, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('sb ac 23e'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_ELECTRICAL, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('m zx 726e'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_ELECTRICAL, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeH() + { + $licenseplate = new GermanLicensePlate('e ra 55h'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_HISTORICAL, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('wes q 501h'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_HISTORICAL, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('mk b 260h'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_HISTORICAL, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeP() + { + $licenseplate = new GermanLicensePlate('01'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('11'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('02'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('03'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('04'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_POLITICAL_HEADS, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeCD() + { + $licenseplate = new GermanLicensePlate('04422'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('01337'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('0133713'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_CORPS_DIPLOMATIC, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeAF() + { + $licenseplate = new GermanLicensePlate('ADVD1234'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_AMERICAN_FORCES, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('AFG123'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_AMERICAN_FORCES, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('HKA1'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_AMERICAN_FORCES, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('IFAG238'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_AMERICAN_FORCES, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeAG() + { + $licenseplate = new GermanLicensePlate('AGIR1337'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_SPECIAL_TRANSPORT, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('AGA9'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_SPECIAL_TRANSPORT, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeBG() + { + $licenseplate = new GermanLicensePlate('BG137'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_FEDERAL_POLICE, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('BP133701'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_FEDERAL_POLICE, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeTHW() + { + $licenseplate = new GermanLicensePlate('THW80832'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_TECHNICAL_RELIEF, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('THW8207'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_TECHNICAL_RELIEF, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeY() + { + $licenseplate = new GermanLicensePlate('Y127508'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_ARMY, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('Y401664'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_ARMY, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new GermanLicensePlate('Y85129'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_ARMY, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeX() + { + $licenseplate = new GermanLicensePlate('X1234'); + $this->assertEquals(GermanLicensePlate::SIDE_CODE_NATO, $licenseplate->getSidecode()); + $this->assertTrue($licenseplate->isValid()); + } +} \ No newline at end of file diff --git a/tests/IsraeliLicensePlateFormatTest.php b/tests/IsraeliLicensePlateFormatTest.php new file mode 100644 index 0000000..e824784 --- /dev/null +++ b/tests/IsraeliLicensePlateFormatTest.php @@ -0,0 +1,32 @@ +assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '29-521-65'); + + $licenseplate = new IsraeliLicensePlate('123456'); + $this->assertFalse($licenseplate->isValid()); + $this->assertFalse($licenseplate->format()); + + $licenseplate = new IsraeliLicensePlate('123456a'); + $this->assertFalse($licenseplate->isValid()); + $this->assertFalse($licenseplate->format()); + + $licenseplate = new IsraeliLicensePlate('מ1234'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'מ-1234'); + + $licenseplate = new IsraeliLicensePlate('צ1234'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'צ-1234'); + + $licenseplate = new IsraeliLicensePlate('מצ1234'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'מצ-1234'); + } +} \ No newline at end of file diff --git a/tests/IsraeliLicensePlateSidecodeTest.php b/tests/IsraeliLicensePlateSidecodeTest.php new file mode 100644 index 0000000..9f50770 --- /dev/null +++ b/tests/IsraeliLicensePlateSidecodeTest.php @@ -0,0 +1,33 @@ +assertEquals($licenseplate->getSidecode(), 1); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeM() + { + $licenseplate = new IsraeliLicensePlate('מ-12'); + $this->assertEquals($licenseplate->getSidecode(), 'M'); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeTZ() + { + $licenseplate = new IsraeliLicensePlate('צ-1234'); + $this->assertEquals($licenseplate->getSidecode(), 'TZ'); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeMTZ() + { + $licenseplate = new IsraeliLicensePlate('מצ-123'); + $this->assertEquals($licenseplate->getSidecode(), 'MTZ'); + $this->assertTrue($licenseplate->isValid()); + } +} \ No newline at end of file diff --git a/tests/LuxembourgianLicensePlateFormatTest.php b/tests/LuxembourgianLicensePlateFormatTest.php new file mode 100644 index 0000000..0ff3f4a --- /dev/null +++ b/tests/LuxembourgianLicensePlateFormatTest.php @@ -0,0 +1,20 @@ +assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'A 1234'); + + $licenseplate = new LuxembourgianLicensePlate('AB123'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'AB 123'); + + $licenseplate = new LuxembourgianLicensePlate('AB1234'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'AB 1234'); + } +} \ No newline at end of file diff --git a/tests/LuxembourgianLicensePlateSidecodeTest.php b/tests/LuxembourgianLicensePlateSidecodeTest.php new file mode 100644 index 0000000..5941f3d --- /dev/null +++ b/tests/LuxembourgianLicensePlateSidecodeTest.php @@ -0,0 +1,26 @@ +assertEquals($licenseplate->getSidecode(), 1); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecode2() + { + $licenseplate = new LuxembourgianLicensePlate('AA123'); + $this->assertEquals($licenseplate->getSidecode(), 2); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecode3() + { + $licenseplate = new LuxembourgianLicensePlate('AA1234'); + $this->assertEquals($licenseplate->getSidecode(), 3); + $this->assertTrue($licenseplate->isValid()); + } +} \ No newline at end of file diff --git a/tests/SpanishLicensePlateFormatTest.php b/tests/SpanishLicensePlateFormatTest.php new file mode 100644 index 0000000..6204b64 --- /dev/null +++ b/tests/SpanishLicensePlateFormatTest.php @@ -0,0 +1,36 @@ +assertEquals($expectedformat, $sut->format()); + } + + /** + * @return array + */ + public function sideCodeDataProvider() + { + return [ + ['A123456', 'A-123456'], + ['A12345', 'A-12345'], + ['TEG12345', 'TEG-12345'], + ['tEg12345', 'TEG-12345'], + + ['TEG1234AA', 'TEG-1234-AA'], + ['TEG1234A', 'TEG-1234-A'], + ['A1234A', 'A-1234-A'], + ['CNP1234AA', 'CNP-1234-AA'], + + ['1234AAA', '1234-AAA'], + ['C1234AAA', 'C-1234-AAA'], + ]; + } +} \ No newline at end of file diff --git a/tests/SpanishLicensePlateSidecodeTest.php b/tests/SpanishLicensePlateSidecodeTest.php new file mode 100644 index 0000000..a6e320e --- /dev/null +++ b/tests/SpanishLicensePlateSidecodeTest.php @@ -0,0 +1,40 @@ +assertEquals($expectedSideCode, $sut->getSidecode()); + } + + /** + * @return array + */ + public function sideCodeDataProvider() + { + return [ + ['A123456', 1], + ['A12345', 1], + ['A1234567', false], + ['X123456', false], + ['TEG12345', 1], + + ['TEG1234AA', 2], + ['TEG1234A', 2], + ['X1234AA', false], + ['A1234A', 2], + ['CNP1234AA', 2], + + ['1234AAA', 3], + ['12345AAA', false], + ['C1234AAA', 3], + ['X1234AAA', false] + ]; + } +} \ No newline at end of file diff --git a/tests/UKLicensePlateFormatTest.php b/tests/UKLicensePlateFormatTest.php new file mode 100644 index 0000000..b422c43 --- /dev/null +++ b/tests/UKLicensePlateFormatTest.php @@ -0,0 +1,56 @@ +assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'BD51 QMC'); + + $licenseplate = new UKLicensePlate('bbd1234'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'BBD 1234'); + + $licenseplate = new UKLicensePlate('bbd1234a'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'BBD 1234A'); + + $licenseplate = new UKLicensePlate('bd1234'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'BD 1234'); + + $licenseplate = new UKLicensePlate('1ia'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '1 IA'); + + $licenseplate = new UKLicensePlate('9999ia'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '9999 IA'); + + $licenseplate = new UKLicensePlate('aaa999'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'AAA 999'); + + $licenseplate = new UKLicensePlate('aaa9'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'AAA 9'); + + $licenseplate = new UKLicensePlate('999xxx'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '999 XXX'); + + $licenseplate = new UKLicensePlate('1000a'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), '1000 A'); + + $licenseplate = new UKLicensePlate('a11aaa'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'A11 AAA'); + + $licenseplate = new UKLicensePlate('y999yyy'); + $this->assertTrue($licenseplate->isValid()); + $this->assertEquals($licenseplate->format(), 'Y999 YYY'); + } +} \ No newline at end of file diff --git a/tests/UKLicensePlateSidecodeTest.php b/tests/UKLicensePlateSidecodeTest.php new file mode 100644 index 0000000..e7b4196 --- /dev/null +++ b/tests/UKLicensePlateSidecodeTest.php @@ -0,0 +1,85 @@ +assertEquals($licenseplate->getSidecode(), 'JER'); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeGue() + { + $licenseplate = new UKLicensePlate('12346'); + $this->assertEquals($licenseplate->getSidecode(), 'GUE'); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecodeAld() + { + $licenseplate = new UKLicensePlate('AY1234'); + $this->assertEquals($licenseplate->getSidecode(), 'ALD'); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecode1() + { + $licenseplate = new UKLicensePlate('BD1234'); + $this->assertEquals($licenseplate->getSidecode(), 1); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new UKLicensePlate('AK12GMCC'); + $this->assertFalse($licenseplate->getSidecode()); + $this->assertFalse($licenseplate->isValid()); + } + + public function testSidecode2() + { + $licenseplate = new UKLicensePlate('AAA999'); + $this->assertEquals($licenseplate->getSidecode(), 2); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new UKLicensePlate('AAA9'); + $this->assertEquals($licenseplate->getSidecode(), 2); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new UKLicensePlate('1000 E'); + $this->assertEquals($licenseplate->getSidecode(), 2); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new UKLicensePlate('1 AAA'); + $this->assertEquals($licenseplate->getSidecode(), 2); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecode3() + { + $licenseplate = new UKLicensePlate('BD1234A'); + $this->assertEquals($licenseplate->getSidecode(), 3); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecode4() + { + $licenseplate = new UKLicensePlate('a21aaa'); + $this->assertEquals($licenseplate->getSidecode(),4); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new UKLicensePlate('y999yyy'); + $this->assertEquals($licenseplate->getSidecode(),4); + $this->assertTrue($licenseplate->isValid()); + } + + public function testSidecode5() + { + $licenseplate = new UKLicensePlate('BD51GMQ'); + $this->assertEquals($licenseplate->getSidecode(), 5); + $this->assertTrue($licenseplate->isValid()); + + $licenseplate = new UKLicensePlate('AK12GMCC'); + $this->assertFalse($licenseplate->getSidecode()); + $this->assertFalse($licenseplate->isValid()); + } +} \ No newline at end of file