From efd7388d86e636a1dc754e59ebb4867901aa4571 Mon Sep 17 00:00:00 2001 From: ankurk91 Date: Sat, 5 Jun 2021 21:28:27 +0530 Subject: [PATCH] Test on php 8 - github actions * Remove travis-ci and replace with gh-actions * Update phpunit, update test cases * Bump minimum php requirement See php version usage stats https://packagist.org/packages/simshaun/recurr/php-stats --- .gitattributes | 2 +- .github/workflows/tests.yml | 38 +++++++++++++++++++ .gitignore | 1 + .travis.yml | 20 ---------- README.md | 14 +++++-- composer.json | 10 +++-- phpunit.xml.dist | 33 ++++++++++------ .../Recurr/Test/RecurrenceCollectionTest.php | 4 +- tests/Recurr/Test/RuleTest.php | 36 ++++++------------ .../Test/Transformer/ArrayTransformerBase.php | 4 +- .../Transformer/ArrayTransformerByDayTest.php | 2 +- .../ArrayTransformerExDateTest.php | 4 +- .../Transformer/ArrayTransformerRDateTest.php | 4 +- .../Constraint/AfterConstraintTest.php | 2 +- .../Constraint/BeforeConstraintTest.php | 2 +- .../Constraint/BetweenConstraintTest.php | 2 +- .../Test/Transformer/TextTransformerTest.php | 2 +- 17 files changed, 103 insertions(+), 77 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml diff --git a/.gitattributes b/.gitattributes index cfbd682..cb445a2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,3 @@ +/.github export-ignore /tests export-ignore -/.travis.yml export-ignore /phpunit.xml.dist export-ignore diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..af8a5ad --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,38 @@ +name: tests + +on: + push: + pull_request: + schedule: + - cron: '0 0 15 * *' + +jobs: + test: + + runs-on: ubuntu-latest + timeout-minutes: 15 + strategy: + fail-fast: false + matrix: + php: [7.2, 7.3, 7.4, 8.0] + + name: php v${{ matrix.php }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo + tools: composer:v2 + coverage: pcov + + - name: Install dependencies + run: composer install --no-interaction --no-progress + + - name: Execute tests + run: composer test + diff --git a/.gitignore b/.gitignore index 49dbaea..288e9f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor/ /.idea/ /composer.lock +/.phpunit.result.cache \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8532dfe..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: php -php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - 8.0 -env: - global: - - XDEBUG_MODE=coverage -install: - - composer self-update - - composer update - - composer --prefer-source install -script: ./vendor/bin/phpunit --coverage-text -cache: - directories: - - $HOME/.composer/cache diff --git a/README.md b/README.md index b70d41f..f6adf0e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -# Recurr [![Build Status](https://travis-ci.org/simshaun/recurr.png)](https://travis-ci.org/simshaun/recurr.png) [![Latest Stable Version](https://poser.pugx.org/simshaun/recurr/v/stable.svg)](https://packagist.org/packages/simshaun/recurr) [![Total Downloads](https://poser.pugx.org/simshaun/recurr/downloads.svg)](https://packagist.org/packages/simshaun/recurr) [![Latest Unstable Version](https://poser.pugx.org/simshaun/recurr/v/unstable.svg)](https://packagist.org/packages/simshaun/recurr) [![License](https://poser.pugx.org/simshaun/recurr/license.svg)](https://packagist.org/packages/simshaun/recurr) +# Recurr + +[![tests](https://github.com/simshaun/recurr/workflows/tests/badge.svg)](https://github.com/simshaun/recurr/actions) +[![Latest Stable Version](https://poser.pugx.org/simshaun/recurr/v/stable.svg)](https://packagist.org/packages/simshaun/recurr) +[![Total Downloads](https://poser.pugx.org/simshaun/recurr/downloads.svg)](https://packagist.org/packages/simshaun/recurr) +[![Latest Unstable Version](https://poser.pugx.org/simshaun/recurr/v/unstable.svg)](https://packagist.org/packages/simshaun/recurr) +[![License](https://poser.pugx.org/simshaun/recurr/license.svg)](https://packagist.org/packages/simshaun/recurr) Recurr is a PHP library for working with recurrence rules ([RRULE](https://tools.ietf.org/html/rfc5545)) and converting them in to DateTime objects. @@ -9,7 +15,9 @@ Installing Recurr The recommended way to install Recurr is through [Composer](http://getcomposer.org). -`composer require simshaun/recurr` +```bash +composer require simshaun/recurr +``` Using Recurr ----------- @@ -153,4 +161,4 @@ Feel free to comment or make pull requests. Please include tests with PRs. License ------- -Recurr is licensed under the MIT License. See the LICENSE file for details. +Recurr is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details. diff --git a/composer.json b/composer.json index 71480e1..b9b009f 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,12 @@ } ], "require": { - "php": ">=5.5.0", - "doctrine/collections": "~1.3" + "php": "^7.2||^8.0", + "doctrine/collections": "~1.6" }, "require-dev": { - "phpunit/phpunit": "~5.7" + "phpunit/phpunit": "^8.5.16", + "symfony/yaml": "^5.3" }, "autoload": { "psr-4": { @@ -33,5 +34,8 @@ "branch-alias": { "dev-master": "0.x-dev" } + }, + "scripts": { + "test": "./vendor/bin/phpunit --color=always" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 937f9ac..d658965 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,15 +1,24 @@ + + + + ./tests/Recurr/Test/ + + - - - - ./tests/Recurr/Test/ - - - - - - ./src/Recurr/ - - + + + ./src/Recurr/ + + diff --git a/tests/Recurr/Test/RecurrenceCollectionTest.php b/tests/Recurr/Test/RecurrenceCollectionTest.php index 52a3dd5..7bf2381 100644 --- a/tests/Recurr/Test/RecurrenceCollectionTest.php +++ b/tests/Recurr/Test/RecurrenceCollectionTest.php @@ -5,12 +5,12 @@ namespace Recurr\Test; use Recurr\Recurrence; use Recurr\RecurrenceCollection; -class RecurrenceCollectionTest extends \PHPUnit_Framework_TestCase +class RecurrenceCollectionTest extends \PHPUnit\Framework\TestCase { /** @var RecurrenceCollection */ protected $collection; - public function setUp() + public function setUp(): void { $this->collection = new RecurrenceCollection( array( diff --git a/tests/Recurr/Test/RuleTest.php b/tests/Recurr/Test/RuleTest.php index 3471f34..e23a2bf 100644 --- a/tests/Recurr/Test/RuleTest.php +++ b/tests/Recurr/Test/RuleTest.php @@ -7,12 +7,12 @@ use Recurr\DateInclusion; use Recurr\Frequency; use Recurr\Rule; -class RuleTest extends \PHPUnit_Framework_TestCase +class RuleTest extends \PHPUnit\Framework\TestCase { /** @var Rule */ protected $rule; - public function setUp() + public function setUp(): void { $this->rule = new Rule; } @@ -51,19 +51,15 @@ class RuleTest extends \PHPUnit_Framework_TestCase $this->assertEquals($startDate->getTimezone()->getName(), $this->rule->getTimezone()); } - /** - * @expectedException \Recurr\Exception\InvalidRRule - */ public function testLoadFromStringWithMissingFreq() { + $this->expectException(\Recurr\Exception\InvalidRRule::class); $this->rule->loadFromString('COUNT=2'); } - /** - * @expectedException \Recurr\Exception\InvalidRRule - */ public function testLoadFromStringWithBothCountAndUntil() { + $this->expectException(\Recurr\Exception\InvalidRRule::class); $this->rule->loadFromString('FREQ=DAILY;COUNT=2;UNTIL=20130510'); } @@ -312,11 +308,9 @@ class RuleTest extends \PHPUnit_Framework_TestCase date_default_timezone_set($defaultTimezone); } - /** - * @expectedException \Recurr\Exception\InvalidRRule - */ public function testLoadFromStringFails() { + $this->expectException(\Recurr\Exception\InvalidRRule::class); $this->rule->loadFromString('IM AN INVALID RRULE'); } @@ -403,7 +397,7 @@ class RuleTest extends \PHPUnit_Framework_TestCase $this->rule->loadFromString($string); - $this->assertNotContains('WKST', $this->rule->getString()); + $this->assertStringNotContainsString('WKST', $this->rule->getString()); } public function testGetStringWithExplicitWkst() @@ -412,7 +406,7 @@ class RuleTest extends \PHPUnit_Framework_TestCase $this->rule->loadFromString($string); - $this->assertContains('WKST=TH', $this->rule->getString()); + $this->assertStringContainsString('WKST=TH', $this->rule->getString()); } public function testSetStartDateAffectsStringOutput() @@ -430,35 +424,27 @@ class RuleTest extends \PHPUnit_Framework_TestCase $this->assertEquals('FREQ=MONTHLY;COUNT=2', $this->rule->getString()); } - /** - * @expectedException \Recurr\Exception\InvalidArgument - */ public function testBadInterval() { + $this->expectException(\Recurr\Exception\InvalidArgument::class); $this->rule->setInterval('six'); } - /** - * @expectedException \Recurr\Exception\InvalidRRule - */ public function testEmptyByDayThrowsException() { + $this->expectException(\Recurr\Exception\InvalidRRule::class); $this->rule->setByDay(array()); } - /** - * @expectedException \Recurr\Exception\InvalidRRule - */ public function testEmptyByDayFromStringThrowsException() { + $this->expectException(\Recurr\Exception\InvalidRRule::class); $this->rule->loadFromString('FREQ=WEEKLY;BYDAY=;INTERVAL=1;UNTIL=20160725'); } - /** - * @expectedException \Recurr\Exception\InvalidArgument - */ public function testBadWeekStart() { + $this->expectException(\Recurr\Exception\InvalidArgument::class); $this->rule->setWeekStart('monday'); } diff --git a/tests/Recurr/Test/Transformer/ArrayTransformerBase.php b/tests/Recurr/Test/Transformer/ArrayTransformerBase.php index 826f5fa..b1e2fd3 100644 --- a/tests/Recurr/Test/Transformer/ArrayTransformerBase.php +++ b/tests/Recurr/Test/Transformer/ArrayTransformerBase.php @@ -4,14 +4,14 @@ namespace Recurr\Test\Transformer; use Recurr\Transformer\ArrayTransformer; -class ArrayTransformerBase extends \PHPUnit_Framework_TestCase +class ArrayTransformerBase extends \PHPUnit\Framework\TestCase { /** @var ArrayTransformer */ protected $transformer; protected $timezone = 'America/New_York'; - public function setUp() + public function setUp(): void { $this->transformer = new ArrayTransformer(); } diff --git a/tests/Recurr/Test/Transformer/ArrayTransformerByDayTest.php b/tests/Recurr/Test/Transformer/ArrayTransformerByDayTest.php index 3f011fd..5702b46 100644 --- a/tests/Recurr/Test/Transformer/ArrayTransformerByDayTest.php +++ b/tests/Recurr/Test/Transformer/ArrayTransformerByDayTest.php @@ -97,10 +97,10 @@ class ArrayTransformerByDayTest extends ArrayTransformerBase /** * @dataProvider unsupportedNthByDayFrequencies - * @expectedException \Recurr\Exception\InvalidRRule */ public function testNthByDayWithUnsupportedFrequency($frequency) { + $this->expectException(\Recurr\Exception\InvalidRRule::class); new Rule( "FREQ=$frequency;COUNT=3;BYDAY=2MO", new \DateTime('1997-05-19 16:00:00') diff --git a/tests/Recurr/Test/Transformer/ArrayTransformerExDateTest.php b/tests/Recurr/Test/Transformer/ArrayTransformerExDateTest.php index 0395210..361bb0a 100644 --- a/tests/Recurr/Test/Transformer/ArrayTransformerExDateTest.php +++ b/tests/Recurr/Test/Transformer/ArrayTransformerExDateTest.php @@ -15,7 +15,7 @@ class ArrayTransformerExDateTest extends ArrayTransformerBase */ protected static $originalTimezoneName; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$originalTimezoneName = date_default_timezone_get(); date_default_timezone_set('America/New_York'); @@ -23,7 +23,7 @@ class ArrayTransformerExDateTest extends ArrayTransformerBase parent::setUpBeforeClass(); } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { date_default_timezone_set(self::$originalTimezoneName); diff --git a/tests/Recurr/Test/Transformer/ArrayTransformerRDateTest.php b/tests/Recurr/Test/Transformer/ArrayTransformerRDateTest.php index fc6a487..d8a2a18 100644 --- a/tests/Recurr/Test/Transformer/ArrayTransformerRDateTest.php +++ b/tests/Recurr/Test/Transformer/ArrayTransformerRDateTest.php @@ -15,7 +15,7 @@ class ArrayTransformerRDateTest extends ArrayTransformerBase */ protected static $originalTimezoneName; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$originalTimezoneName = date_default_timezone_get(); date_default_timezone_set('America/New_York'); @@ -23,7 +23,7 @@ class ArrayTransformerRDateTest extends ArrayTransformerBase parent::setUpBeforeClass(); } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { date_default_timezone_set(self::$originalTimezoneName); diff --git a/tests/Recurr/Test/Transformer/Constraint/AfterConstraintTest.php b/tests/Recurr/Test/Transformer/Constraint/AfterConstraintTest.php index 2cd3735..09e54e4 100644 --- a/tests/Recurr/Test/Transformer/Constraint/AfterConstraintTest.php +++ b/tests/Recurr/Test/Transformer/Constraint/AfterConstraintTest.php @@ -4,7 +4,7 @@ namespace Recurr\Test\Transformer\Filter; use Recurr\Transformer\Constraint\AfterConstraint; -class AfterConstraintTest extends \PHPUnit_Framework_TestCase +class AfterConstraintTest extends \PHPUnit\Framework\TestCase { public function testAfter() { diff --git a/tests/Recurr/Test/Transformer/Constraint/BeforeConstraintTest.php b/tests/Recurr/Test/Transformer/Constraint/BeforeConstraintTest.php index 201fc8a..0d66fd2 100644 --- a/tests/Recurr/Test/Transformer/Constraint/BeforeConstraintTest.php +++ b/tests/Recurr/Test/Transformer/Constraint/BeforeConstraintTest.php @@ -4,7 +4,7 @@ namespace Recurr\Test\Transformer\Filter; use Recurr\Transformer\Constraint\BeforeConstraint; -class BeforeConstraintTest extends \PHPUnit_Framework_TestCase +class BeforeConstraintTest extends \PHPUnit\Framework\TestCase { public function testBefore() { diff --git a/tests/Recurr/Test/Transformer/Constraint/BetweenConstraintTest.php b/tests/Recurr/Test/Transformer/Constraint/BetweenConstraintTest.php index 89c15f6..2291377 100644 --- a/tests/Recurr/Test/Transformer/Constraint/BetweenConstraintTest.php +++ b/tests/Recurr/Test/Transformer/Constraint/BetweenConstraintTest.php @@ -4,7 +4,7 @@ namespace Recurr\Test\Transformer\Filter; use Recurr\Transformer\Constraint\BetweenConstraint; -class BetweenConstraintTest extends \PHPUnit_Framework_TestCase +class BetweenConstraintTest extends \PHPUnit\Framework\TestCase { public function testBetween() { diff --git a/tests/Recurr/Test/Transformer/TextTransformerTest.php b/tests/Recurr/Test/Transformer/TextTransformerTest.php index e1150df..19dcfe0 100644 --- a/tests/Recurr/Test/Transformer/TextTransformerTest.php +++ b/tests/Recurr/Test/Transformer/TextTransformerTest.php @@ -7,7 +7,7 @@ use Symfony\Component\Yaml\Yaml; use Recurr\Transformer\Translator; use Recurr\Transformer\TextTransformer; -class TextTransformerTest extends \PHPUnit_Framework_TestCase +class TextTransformerTest extends \PHPUnit\Framework\TestCase { private static $languages = array();