diff --git a/.docker/Dockerfile b/.docker/Dockerfile new file mode 100644 index 0000000..6663395 --- /dev/null +++ b/.docker/Dockerfile @@ -0,0 +1,12 @@ +FROM php:7.4-cli +WORKDIR "/opt/php" + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update && \ + pecl channel-update pecl.php.net && \ + pecl install xdebug && \ + docker-php-source delete && \ + rm -r /tmp/* /var/cache/* + +COPY ./.docker/php-ini-overrides.ini /usr/local/etc/php/conf.d/99-overrides.ini \ No newline at end of file diff --git a/.docker/php-ini-overrides.ini b/.docker/php-ini-overrides.ini new file mode 100644 index 0000000..d622f53 --- /dev/null +++ b/.docker/php-ini-overrides.ini @@ -0,0 +1,13 @@ +error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT +error_log = /dev/stderr +log_errors = On +display_startup_errors = Off +date.timezone = UTC +upload_max_filesize = 8M +post_max_size = 8M +html_errors = Off +memory_limit = 512M +max_execution_time = 60 +expose_php = Off +zend_extension=xdebug.so +xdebug.mode=coverage \ No newline at end of file diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..a95d939 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,39 @@ +name: PHPUnit tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + coverage: xdebug + - name: Checkout code + uses: actions/checkout@v2 + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Run test suite + run: composer run-script tests \ No newline at end of file diff --git a/.gitignore b/.gitignore index 05ce378..10ab4c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock -vendor -build +/vendor +/build +.phpunit.result.cache \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 74807c6..e5e8f64 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -5,8 +5,14 @@ checks: code_rating: true duplication: true tools: - external_code_coverage: - timeout: 630 php_code_sniffer: config: standard: "PSR2" +build: + environment: + php: + version: 7.4 + tests: + override: + - + command: './vendor/bin/phpunit --configuration code-coverage.xml tests/' \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 05511ea..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: php -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - hhvm -install: - - composer require satooshi/php-coveralls:~0.6@stable -before_script: composer dump-autoload -script: - - phpunit --configuration code-coverage.xml tests/ -after_success: - - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;' - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml -notifications: - email: false diff --git a/code-coverage.xml b/code-coverage.xml index f496aaa..cc1b093 100644 --- a/code-coverage.xml +++ b/code-coverage.xml @@ -1,27 +1,17 @@ - - - - - src/ - - - - - - - - - + + + + src/ + + + + + + + + + + diff --git a/composer.json b/composer.json index 8ebf704..0a581f3 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=5.3.3" + "php": ">=7.4" }, "minimum-stability": "stable", "autoload": { @@ -25,6 +25,11 @@ } }, "require-dev": { - "phpunit/phpunit": "^4.0" + "phpunit/phpunit": "^9.0" + }, + "scripts": { + "docker-build": "docker build -f .docker/Dockerfile -t larium-creditcard .", + "docker-tests": "docker run -v $(pwd):/opt/php larium-creditcard sh -c './vendor/bin/phpunit --configuration code-coverage.xml tests/'", + "tests": "./vendor/bin/phpunit --configuration code-coverage.xml tests/" } } diff --git a/tests/CreditCard/CreditCardDetectorTest.php b/tests/CreditCard/CreditCardDetectorTest.php index 615f260..0a6808f 100644 --- a/tests/CreditCard/CreditCardDetectorTest.php +++ b/tests/CreditCard/CreditCardDetectorTest.php @@ -2,7 +2,9 @@ namespace Larium\CreditCard; -class CreditCardDetectorTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class CreditCardDetectorTest extends TestCase { /** * @dataProvider creditCardsProvider diff --git a/tests/CreditCard/CreditCardTest.php b/tests/CreditCard/CreditCardTest.php index 4eda918..274391e 100644 --- a/tests/CreditCard/CreditCardTest.php +++ b/tests/CreditCard/CreditCardTest.php @@ -11,7 +11,9 @@ namespace Larium\CreditCard; -class CreditCardTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class CreditCardTest extends TestCase { public function testCreditCardInstance() { @@ -91,7 +93,7 @@ public function testSettingToken() $card = $card->withToken(new Token('0123456789')); - $this->assertRegExp('/XXXX-XXXX-XXXX-\d{4}/', $card->getNumber()); + $this->assertMatchesRegularExpression('/XXXX-XXXX-XXXX-\d{4}/', $card->getNumber()); } public function testExpiryDateImmutability() diff --git a/tests/CreditCard/CreditCardValidatorTest.php b/tests/CreditCard/CreditCardValidatorTest.php index adf9d14..c46c0d1 100644 --- a/tests/CreditCard/CreditCardValidatorTest.php +++ b/tests/CreditCard/CreditCardValidatorTest.php @@ -11,7 +11,9 @@ namespace Larium\CreditCard; -class CreditCardValidatorTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class CreditCardValidatorTest extends TestCase { /** * @dataProvider cardOptionsProvider @@ -50,11 +52,9 @@ public function testValidatorContext() $this->assertEmpty($errors); } - /** - * @expectedException RuntimeException - */ public function testInvalidValidatorContext() { + $this->expectException(\RuntimeException::class); $validator = new CreditCardValidator(); $validator->setContext('wrong'); diff --git a/tests/CreditCard/ExpiryDateTest.php b/tests/CreditCard/ExpiryDateTest.php index 94df93f..61fe6dc 100644 --- a/tests/CreditCard/ExpiryDateTest.php +++ b/tests/CreditCard/ExpiryDateTest.php @@ -12,8 +12,9 @@ namespace Larium\CreditCard; use DateTime; +use PHPUnit\Framework\TestCase; -class ExpiryDateTest extends \PHPUnit_Framework_TestCase +class ExpiryDateTest extends TestCase { public function testExpiryDateFormatters() { diff --git a/tests/CreditCard/TokenTest.php b/tests/CreditCard/TokenTest.php index 50e546a..fe22350 100644 --- a/tests/CreditCard/TokenTest.php +++ b/tests/CreditCard/TokenTest.php @@ -3,8 +3,9 @@ namespace Larium\CreditCard; use DateTime; +use PHPUnit\Framework\TestCase; -class TokenTest extends \PHPUnit_Framework_TestCase +class TokenTest extends TestCase { public function testTokenInstance() {