-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0b64c4d
Showing
23 changed files
with
349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: CI-CHECKS | ||
|
||
on: [push] | ||
|
||
jobs: | ||
run-phpcs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: php-actions/composer@v5 | ||
- name: PHPCS analyze | ||
run: ./vendor/bin/phpcs -p -s --standard=phpcs.xml src tests | ||
run-php-stan: | ||
needs: run-phpcs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: php-actions/composer@v5 | ||
- name: PHPStan Static Analysis source code | ||
uses: php-actions/phpstan@v3 | ||
with: | ||
configuration: ./phpstan.neon.dist | ||
run-php-unit-tests: | ||
needs: run-php-stan | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: php-actions/composer@v5 | ||
- uses: php-actions/phpunit@v3 | ||
with: | ||
version: 9.5.28 | ||
bootstrap: vendor/autoload.php | ||
configuration: phpunit.xml | ||
args: --coverage-text | ||
run-assemble-php-unit-coverage: | ||
needs: run-php-unit-tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: php-actions/composer@v5 | ||
- name: Run PHPUnit Tests | ||
uses: php-actions/phpunit@v3 | ||
with: | ||
version: 9.5.28 | ||
php_extensions: xdebug | ||
bootstrap: vendor/autoload.php | ||
configuration: phpunit.xml | ||
args: --coverage-text | ||
env: | ||
XDEBUG_MODE: coverage | ||
- name: Generate test coverage badge | ||
uses: timkrase/[email protected] | ||
with: | ||
report: ./clover.xml | ||
coverage_badge_path: 'badge.svg' | ||
push_badge: true | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
composer.phar | ||
/vendor/ | ||
.idea | ||
.phpunit.result.cache | ||
|
||
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control | ||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file | ||
# composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM php:7.4-fpm | ||
RUN apt-get update && apt-get install -y \ | ||
zlib1g-dev \ | ||
libzip-dev \ | ||
unzip \ | ||
mc | ||
RUN docker-php-ext-install zip | ||
RUN mkdir -p /home/app | ||
WORKDIR /home/app | ||
COPY . /home/app | ||
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Country vat format validator template description | ||
|
||
## Implementation steps | ||
|
||
1. Create repository use template for name: <ISO-3166-standard-alpha2-code>-vat-format-validator | ||
2. Update composer.json **name** attribute: rocketfellows/<ISO-3166-standard-alpha2-code>-vat-format-validator | ||
3. Update composer.json with autoload and autoload-dev sections by pattern: | ||
```php | ||
"autoload": { | ||
"psr-4": { | ||
"rocketfellows\\<ISO-3166-standard-alpha2-code>VatFormatValidator\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"rocketfellows\\<ISO-3166-standard-alpha2-code>VatFormatValidator\\tests\\": "tests/" | ||
} | ||
} | ||
``` | ||
3. Run docker-deploy.sh | ||
4. Implement unit test in test/unit directory | ||
5. Implement direct validator | ||
|
||
# Templated readme | ||
|
||
# <Country> vat format validator | ||
|
||
![Code Coverage Badge](./badge.svg) | ||
|
||
This component provides <Country> vat number format validator. | ||
|
||
Implementation of interface **rocketfellows\CountryVatFormatValidatorInterface\CountryVatFormatValidatorInterface** | ||
|
||
Depends on https://github.com/rocketfellows/country-vat-format-validator-interface | ||
|
||
## Installation | ||
|
||
```shell | ||
composer require rocketfellows/<ISO-3166-standard-alpha2-code>-vat-format-validator | ||
``` | ||
|
||
## Usage example | ||
|
||
Valid <Country> vat number: | ||
|
||
```php | ||
$validator = new <Country>VatFormatValidator(); | ||
$validator->isValid(''); | ||
$validator->isValid(''); | ||
``` | ||
|
||
Returns: | ||
|
||
```shell | ||
true | ||
true | ||
``` | ||
|
||
Invalid <Country> vat number: | ||
|
||
```php | ||
$validator = new <Country>VatFormatValidator(); | ||
$validator->isValid(''); | ||
$validator->isValid(''); | ||
``` | ||
|
||
```shell | ||
false | ||
false | ||
``` | ||
|
||
## Contributing | ||
|
||
Welcome to pull requests. If there is a major changes, first please open an issue for discussion. | ||
|
||
Please make sure to update tests as appropriate. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<coverage generated="1648587867"> | ||
<project timestamp="1648587867"> | ||
<metrics files="0" loc="0" ncloc="0" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/> | ||
</project> | ||
</coverage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "rocketfellows/country-vat-format-validator-template", | ||
"authors": [ | ||
{ | ||
"name": "Arslan Imamutdinov", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=7.4", | ||
"rocketfellows/country-vat-format-validator-interface": "^1.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^8.5", | ||
"phpstan/phpstan": "^0.12.90", | ||
"squizlabs/php_codesniffer": "3.6.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
docker-compose down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
docker-compose up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: "3" | ||
services: | ||
php: | ||
build: | ||
dockerfile: Dockerfile | ||
context: ./ | ||
volumes: | ||
- ./:/home/app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
docker-compose -f docker-compose.yml up -d && \ | ||
docker-compose exec php composer install && \ | ||
docker-compose exec php composer dump-autoload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
sh ./docker-run-phpcs.sh && \ | ||
sh ./docker-run-phpstan.sh && \ | ||
sh ./docker-run-unit-tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "=================== PHPCS ===================" | ||
|
||
eval "docker-compose exec php ./vendor/bin/phpcs -p -s --standard=phpcs.xml src tests" | ||
|
||
echo "\n=============================================" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "=================== PHPSTAN ===================" | ||
|
||
eval "docker-compose exec php ./vendor/bin/phpstan analyse" | ||
|
||
echo "\n=============================================" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "=================== UNIT-TESTS ===================" | ||
|
||
eval "docker-compose exec php ./vendor/bin/phpunit --colors=always --verbose --testdox" | ||
|
||
echo "\n=============================================" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<ruleset name="base-coding-style"> | ||
<description>Base component coding style</description> | ||
|
||
<rule ref="PSR12"/> | ||
|
||
<rule ref="PSR2.Methods.MethodDeclaration.Underscore"/> | ||
|
||
<rule ref="Generic.Formatting.SpaceAfterCast"/> | ||
|
||
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/> | ||
|
||
<rule ref="Generic.Files.LineLength"> | ||
<properties> | ||
<property name="lineLimit" value="300"/> | ||
<property name="absoluteLineLimit" value="500"/> | ||
</properties> | ||
</rule> | ||
|
||
<rule ref="Squiz.Scope.MethodScope"/> | ||
|
||
<rule ref="Squiz.Classes.ValidClassName"/> | ||
|
||
<rule ref="PEAR.Functions.ValidDefaultValue"/> | ||
|
||
<rule ref="Zend.Files.ClosingTag"/> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
parameters: | ||
level: 5 | ||
paths: | ||
- src | ||
- tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
executionOrder="depends,defects" | ||
beStrictAboutCoversAnnotation="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
verbose="true"> | ||
<coverage cacheDirectory=".phpunit.cache/code-coverage" processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
<report> | ||
<clover outputFile="clover.xml" /> | ||
</report> | ||
</coverage> | ||
|
||
<testsuites> | ||
<testsuite name="default"> | ||
<directory>./tests/unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
// TODO: set namespace | ||
|
||
/** | ||
* TODO: rename validator | ||
*/ | ||
class CountryVatFormatValidator extends CountryVatFormatValidator | ||
{ | ||
private const VAT_NUMBER_PATTERN = ''; // TODO: implement pattern | ||
|
||
protected function isValidFormat(string $vatNumber): bool | ||
{ | ||
return (bool) preg_match(self::VAT_NUMBER_PATTERN, $vatNumber); | ||
} | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
// TODO: set namespace | ||
namespace unit; | ||
|
||
class CountryVatFormatValidatorTest extends TestCase | ||
{ | ||
/** | ||
* TODO: set type | ||
* @var | ||
*/ | ||
private $validator; | ||
|
||
/** | ||
* TODO: setup validator for test | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->validator = new CountryVatFormatValidator(); | ||
} | ||
|
||
/** | ||
* @dataProvider getVatNumbersProvidedData | ||
*/ | ||
public function testValidationResult(string $vatNumber, bool $isValid): void | ||
{ | ||
$this->assertEquals($isValid, $this->validator->isValid($vatNumber)); | ||
} | ||
|
||
public function getVatNumbersProvidedData(): array | ||
{ | ||
return [ | ||
[ | ||
'vatNumber', | ||
'isValid', | ||
], | ||
]; | ||
} | ||
} |