diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml new file mode 100644 index 0000000..f54eefe --- /dev/null +++ b/.github/workflows/phpunit.yml @@ -0,0 +1,54 @@ +name: tests + +on: + pull_request: + push: + branches: [ master ] + +jobs: + unit-tests: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php-version: + - 7.0 + - 7.1 + - 7.2 + - 7.3 + - 7.4 + - 8.0 + - 8.1 + - 8.2 + - 8.3 + + env: + EXECUTE_COVERAGE: ${{ matrix.php-version == '8.0' }} + CLOVER_PATH: "logs/clover.xml" + + steps: + - uses: actions/checkout@v4 + + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + coverage: xdebug + + - if: matrix.php-version == '7.0' || matrix.php-version == '7.1' + run: composer config --no-plugins allow-plugins.kylekatarnls/update-helper true + + - run: composer install --no-interaction --no-scripts --no-suggest --no-progress --optimize-autoloader + + - if: env.EXECUTE_COVERAGE == 'true' + run: vendor/bin/phpunit --coverage-text --coverage-clover ${{ env.CLOVER_PATH }} + + - if: env.EXECUTE_COVERAGE != 'true' + run: vendor/bin/phpunit + + - if: env.EXECUTE_COVERAGE == 'true' + # This fails in forks + continue-on-error: true + run: | + wget https://scrutinizer-ci.com/ocular.phar + php ocular.phar code-coverage:upload --format=php-clover coverage.clover diff --git a/.gitignore b/.gitignore index fa949f1..fce6633 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +!.github vendor .idea .php_cs.cache diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 247ef02..0000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: php - -git: - depth: 1 -env: - global: - - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-progress --optimize-autoloader" - - REPORT_TESTS_COVERAGE=0 -matrix: - fast_finish: true - include: - - php: 7.0 - - php: 7.1 - - php: 7.2 - - php: 7.3 - - php: 7.4 - - php: 8.0 - env: REPORT_TESTS_COVERAGE=1 - -cache: - directories: - - $HOME/.composer/cache - -before_install: - - travis_retry composer self-update - -install: - - travis_retry composer install --no-interaction --prefer-dist --no-suggest - -script: - - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover - -after_script: - - if [ $REPORT_TESTS_COVERAGE == 1 ]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [ $REPORT_TESTS_COVERAGE == 1 ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi diff --git a/README.md b/README.md index a8643c3..e6d7af3 100755 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ This rule will validate that a given credit card **number**, **expiration date** or **cvc** is valid.
-
-
+
+
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 04c6517..c144305 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -4,4 +4,10 @@
class TestCase extends \Orchestra\Testbench\TestCase
{
+ // The TestCase::__construct in the new PHPUnit versions requires first argument,
+ // this workaround allows to instantiate test files in the tests.
+ public function __construct($name = null)
+ {
+ parent::__construct($name ?? get_class($this));
+ }
}
diff --git a/tests/Unit/CardCvcTest.php b/tests/Unit/CardCvcTest.php
index bda9810..595ebb4 100644
--- a/tests/Unit/CardCvcTest.php
+++ b/tests/Unit/CardCvcTest.php
@@ -7,6 +7,7 @@
use LVR\CreditCard\Cards\Card;
use LVR\CreditCard\Tests\TestCase;
use LVR\CreditCard\Tests\Unit\Cards\AmericanExpressTest;
+use LVR\CreditCard\Tests\Unit\Cards\BaseCardTests;
use LVR\CreditCard\Tests\Unit\Cards\VisaTest;
class CardCvcTest extends TestCase
@@ -14,9 +15,6 @@ class CardCvcTest extends TestCase
/** @test **/
public function it_check_cvc_by_credit_card()
{
- $this->assertTrue($this->validator('243')->passes());
- $this->assertTrue($this->validator('1234')->passes());
-
$this->assertTrue($this->validator('1234', new AmericanExpressTest)->passes());
$this->assertFalse($this->validator('243', new AmericanExpressTest)->passes()); // American Express supports only 4 digits
@@ -63,15 +61,11 @@ public function it_checks_cvc_code_length()
/**
* @param string|int $cvc
- * @param null $testCard
+ * @param BaseCardTests $testCard
* @return mixed
*/
- protected function validator($cvc, $testCard = null)
+ protected function validator($cvc, $testCard)
{
- if (! $testCard) {
- $testCard = new AmericanExpressTest();
- }
-
return Validator::make(
[
'cvc' => $cvc,
diff --git a/tests/Unit/CardTest.php b/tests/Unit/CardTest.php
index 45ea22c..d698a45 100644
--- a/tests/Unit/CardTest.php
+++ b/tests/Unit/CardTest.php
@@ -10,17 +10,16 @@
class CardTest extends TestCase
{
- /** @test @dataProvider badStrings **/
- public function it_expects_card_number($input)
+ public function it_expects_card_number()
{
$this->expectException(CreditCardException::class);
-
- Factory::makeFromNumber($input);
+ Factory::makeFromNumber(null);
}
- public function badStrings()
+ public function it_expects_not_empty_card_number()
{
- return ['empty string' => [''], 'null' => [null]];
+ $this->expectException(CreditCardException::class);
+ Factory::makeFromNumber('');
}
/** @test **/