From fb97d20b8e5a2b35cbd60087fc826d64725d4131 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Sun, 17 May 2020 14:19:32 -0500 Subject: [PATCH] ci: setup GitHub actions Been having issues with Travis CI, figured time to give GitHub Actions a go. Also moved over from Coveralls to CodeCov due to some limitations in coverage format. --- .coveralls.yml | 1 - .github/workflows/test.yml | 33 ++++++++++++++++++++++ .travis.yml | 40 -------------------------- README.md | 7 +++++ codecov.yml | 20 +++++++++++++ composer.json | 2 +- tests/RandomDateTest.php | 57 +++++++++++++++++++++++++++++++++++++- 7 files changed, 117 insertions(+), 43 deletions(-) delete mode 100644 .coveralls.yml create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml create mode 100644 codecov.yml diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 9160059..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -service_name: travis-ci diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5deb99a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Test +on: [push, pull_request] +jobs: + test: + name: Test PHP ${{ matrix.php-version }} + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + - name: PHP Version + run: php --version + - name: Composer Version + run: composer --version + - name: Update Composer + run: composer self-update + - name: Composer Version + run: composer --version + - name: Install Dependencies + run: COMPOSER_MEMORY_LIMIT=-1 composer install + - name: Run Tests + run: vendor/bin/phpunit --coverage-clover ./coverage.xml + - name: Upload Coverage + if: ${{ matrix.php-version == '7.4' }} + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 36d3649..0000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -language: php -dist: bionic -sudo: required - -matrix: - include: - - php: 5.3 - dist: precise - - php: 5.4 - dist: trusty - - php: 5.5 - dist: trusty - - php: 5.6 - dist: trusty - - php: 7.0 - dist: xenial - - php: 7.1 - - php: 7.2 - - php: 7.3 - - php: 7.4 - env: COVERAGE=true - - php: nightly - allow_failures: - - php: nightly - -install: - - php --version - - composer install - -before_script: - - mkdir -p build/logs - -script: - - vendor/bin/phpunit --coverage-clover build/logs/clover.xml - -after_success: - - | - if [[ $COVERAGE ]]; then - travis_retry php vendor/bin/php-coveralls --config .coveralls.yml -v - fi diff --git a/README.md b/README.md index f8552d2..4f9b1e0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # php-randomdate +[![License](https://img.shields.io/packagist/l/joshtronic/php-randomdate?style=for-the-badge)](https://github.com/joshtronic/php-randomdate/blob/master/LICENSE) +![PHP Version](https://img.shields.io/packagist/php-v/joshtronic/php-randomdate?style=for-the-badge) +[![Test Status](https://img.shields.io/github/workflow/status/joshtronic/php-randomdate/Test?style=for-the-badge)](https://github.com/joshtronic/php-randomdate/actions) +[![Code Coverage](https://img.shields.io/codecov/c/github/joshtronic/php-randomdate?style=for-the-badge)](https://codecov.io/gh/joshtronic/php-randomdate) +[![Monthly Downloads](https://img.shields.io/packagist/dm/joshtronic/php-randomdate?style=for-the-badge)](https://packagist.org/packages/joshtronic/php-randomdate) + Random time/date generator fully compatible with PHP's date function. Compatible with PHP 5.3+. @@ -13,6 +19,7 @@ composer require joshtronic/randomdate ## Usage ```php +=')) { + $assertRegExp = 'assertMatchesRegularExpression'; + } else { + $assertRegExp = 'assertRegExp'; + } + $rd = new joshtronic\RandomDate(); - $this->assertRegExp('/^[0-9]{4}(-[0-9]{2}){2}$/i', $rd->date('Y-m-d')); + $date = $rd->date('Y-m-d'); + + $this->$assertRegExp('/^[0-9]{4}(-[0-9]{2}){2}$/i', $date); + } + + public function testMin() + { + $rd = new joshtronic\RandomDate(); + $date = $rd->min('yesterday')->date('Y-m-d'); + + $min = date('Y-m-d', strtotime('yesterday')); + $max = date('Y-m-d', strtotime('today')); + + $this->assertGreaterThanOrEqual($min, $date); + $this->assertLessThanOrEqual($max, $date); + } + + public function testMax() + { + $rd = new joshtronic\RandomDate(); + $date = $rd->min('5 days ago')->max('4 days ago')->date('Y-m-d'); + + $min = date('Y-m-d', strtotime('5 days ago')); + $max = date('Y-m-d', strtotime('4 days ago')); + + $this->assertGreaterThanOrEqual($min, $date); + $this->assertLessThanOrEqual($max, $date); + } + + public function testBetween() + { + $rd = new joshtronic\RandomDate(); + $date = $rd->between('7 days ago', '6 days ago')->date('Y-m-d'); + + $min = date('Y-m-d', strtotime('7 days ago')); + $max = date('Y-m-d', strtotime('6 days ago')); + + $this->assertGreaterThanOrEqual($min, $date); + $this->assertLessThanOrEqual($max, $date); + } + + public function testReset() + { + $rd = new joshtronic\RandomDate(); + $date = $rd->between('+8 days', '+9 days')->date('Y-m-d'); + $date = $rd->reset()->date('Y-m-d'); + + $today = date('Y-m-d', strtotime('today')); + + $this->assertLessThanOrEqual($today, $date); } }