diff --git a/.github/workflows/deptrac.yml b/.github/workflows/deptrac.yml index ebaf4df..f481772 100644 --- a/.github/workflows/deptrac.yml +++ b/.github/workflows/deptrac.yml @@ -20,4 +20,4 @@ on: jobs: deptrac: - uses: codeigniter4/.github/.github/workflows/deptrac.yml@main + uses: codeigniter4/.github/.github/workflows/deptrac.yml@CI46 diff --git a/.github/workflows/infection.yml b/.github/workflows/infection.yml index bc1d813..96bf487 100644 --- a/.github/workflows/infection.yml +++ b/.github/workflows/infection.yml @@ -12,4 +12,4 @@ on: jobs: infection: - uses: codeigniter4/.github/.github/workflows/infection.yml@main + uses: codeigniter4/.github/.github/workflows/infection.yml@CI46 diff --git a/.github/workflows/phpcpd.yml b/.github/workflows/phpcpd.yml index 8ef9e2f..ce66866 100644 --- a/.github/workflows/phpcpd.yml +++ b/.github/workflows/phpcpd.yml @@ -16,6 +16,6 @@ on: jobs: phpcpd: - uses: codeigniter4/.github/.github/workflows/phpcpd.yml@main + uses: codeigniter4/.github/.github/workflows/phpcpd.yml@CI46 with: dirs: "src/ tests/" diff --git a/.github/workflows/phpcsfixer.yml b/.github/workflows/phpcsfixer.yml index ee1221a..773c0dc 100644 --- a/.github/workflows/phpcsfixer.yml +++ b/.github/workflows/phpcsfixer.yml @@ -16,4 +16,4 @@ on: jobs: phpcsfixer: - uses: codeigniter4/.github/.github/workflows/phpcsfixer.yml@main + uses: codeigniter4/.github/.github/workflows/phpcsfixer.yml@CI46 diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 58e2add..01d9b36 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -20,4 +20,4 @@ on: jobs: phpstan: - uses: codeigniter4/.github/.github/workflows/phpstan.yml@main + uses: codeigniter4/.github/.github/workflows/phpstan.yml@CI46 diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 9bcd5ec..68b9dbc 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -20,4 +20,4 @@ on: jobs: phpunit: - uses: codeigniter4/.github/.github/workflows/phpunit.yml@main + uses: codeigniter4/.github/.github/workflows/phpunit.yml@CI46 diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml index 53c76e7..cf704fd 100644 --- a/.github/workflows/psalm.yml +++ b/.github/workflows/psalm.yml @@ -20,4 +20,4 @@ on: jobs: psalm: - uses: codeigniter4/.github/.github/workflows/psalm.yml@main + uses: codeigniter4/.github/.github/workflows/psalm.yml@CI46 diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index 8c19b16..9a60447 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -20,4 +20,4 @@ on: jobs: rector: - uses: codeigniter4/.github/.github/workflows/rector.yml@main + uses: codeigniter4/.github/.github/workflows/rector.yml@CI46 diff --git a/.github/workflows/unused.yml b/.github/workflows/unused.yml index 50235ef..29f938d 100644 --- a/.github/workflows/unused.yml +++ b/.github/workflows/unused.yml @@ -1,4 +1,4 @@ -name: Rector +name: Unused on: pull_request: @@ -18,4 +18,4 @@ on: jobs: rector: - uses: codeigniter4/.github/.github/workflows/rector.yml@main + uses: codeigniter4/.github/.github/workflows/unused.yml@CI46 diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index e7d5df4..4e9f9a7 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -43,5 +43,5 @@ return Factory::create(new CodeIgniter4(), $overrides, $options)->forLibrary( 'CodeIgniter Tasks', 'CodeIgniter Foundation', - 'admin@codeigniter.com' + 'admin@codeigniter.com', ); diff --git a/README.md b/README.md index 2ce3b11..aa097df 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A task scheduler for CodeIgniter 4. [![Deptrac](https://github.com/codeigniter4/tasks/actions/workflows/deptrac.yml/badge.svg)](https://github.com/codeigniter4/tasks/actions/workflows/deptrac.yml) [![Coverage Status](https://coveralls.io/repos/github/codeigniter4/tasks/badge.svg?branch=develop)](https://coveralls.io/github/codeigniter4/tasks?branch=develop) -![PHP](https://img.shields.io/badge/PHP-%5E7.4-blue) +![PHP](https://img.shields.io/badge/PHP-%5E8.1-blue) ![CodeIgniter](https://img.shields.io/badge/CodeIgniter-%5E4.1-blue) ![License](https://img.shields.io/badge/License-MIT-blue) diff --git a/composer.json b/composer.json index c7194a3..de0c9bc 100644 --- a/composer.json +++ b/composer.json @@ -18,16 +18,13 @@ ], "homepage": "https://github.com/codeigniter4/tasks", "require": { - "php": "^7.4 || ^8.0", + "php": "^8.1", "ext-json": "*", "codeigniter4/settings": "^2.0" }, "require-dev": { - "codeigniter/coding-standard": "1.7.*", - "codeigniter4/devkit": "^1.0", - "codeigniter4/framework": "^4.1", - "phpunit/phpunit": "^9.6", - "rector/rector": "1.2.10" + "codeigniter4/devkit": "^1.3", + "codeigniter4/framework": "^4.1" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/docs/index.md b/docs/index.md index 7fae3d7..f57ff19 100644 --- a/docs/index.md +++ b/docs/index.md @@ -11,7 +11,7 @@ information, which provides a convenient way of storing settings in the database ### Requirements -![PHP](https://img.shields.io/badge/PHP-%5E7.4-red) +![PHP](https://img.shields.io/badge/PHP-%5E8.1-red) ![CodeIgniter](https://img.shields.io/badge/CodeIgniter-%5E4.1-red) ### Quickstart diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..1a0f597 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,37 @@ +parameters: + ignoreErrors: + - + message: '#^Parameter \#1 \$array of function usort contains unresolvable type\.$#' + identifier: argument.unresolvableType + count: 1 + path: src/Commands/Lister.php + + - + message: '#^Parameter \#2 \$callback of function usort contains unresolvable type\.$#' + identifier: argument.unresolvableType + count: 1 + path: src/Commands/Lister.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''CodeIgniter\\\\I18n\\\\Time'' and CodeIgniter\\I18n\\Time will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/unit/CronExpressionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Closure'' and Closure\(\)\: ''Hello'' will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/unit/SchedulerTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''CodeIgniter\\\\Tasks\\\\Task'' and CodeIgniter\\Tasks\\Task will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 3 + path: tests/unit/SchedulerTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertSame\(\) with ''Hello'' and ''Hello'' will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/unit/SchedulerTest.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index f0119b8..fad0196 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,3 +1,5 @@ +includes: + - phpstan-baseline.neon parameters: tmpDir: build/phpstan level: 5 @@ -7,8 +9,6 @@ parameters: bootstrapFiles: - vendor/codeigniter4/framework/system/Test/bootstrap.php excludePaths: - - src/Config/Routes.php - - src/Views/* universalObjectCratesClasses: - CodeIgniter\Entity - CodeIgniter\Entity\Entity diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ac88cfc..c4ddfec 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,102 +1,83 @@ + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" + bootstrap="vendor/codeigniter4/framework/system/Test/bootstrap.php" + backupGlobals="false" + beStrictAboutOutputDuringTests="true" + colors="true" + executionOrder="random" + failOnRisky="true" + failOnWarning="true" + stopOnError="false" + stopOnFailure="false" + stopOnIncomplete="false" + stopOnSkipped="false" + cacheDirectory="build/.phpunit.cache" + beStrictAboutCoverageMetadata="true"> - - - ./src/ - - - ./src/Config - ./src/Views - - - - - - - - - + + + + + + + + + - - - ./tests - - + + + ./tests + + - - - - - - 0.50 - - - 30 - - - 2 - - - true - - - true - - - - - + + + + + + + - - - - - + + + + + - - - + + + - - + + - - + + - - + + - - + + - - - - + + + + + + + ./src/ + + + ./src/Config + + diff --git a/src/Commands/Publish.php b/src/Commands/Publish.php index d416090..fcefb1b 100644 --- a/src/Commands/Publish.php +++ b/src/Commands/Publish.php @@ -48,7 +48,7 @@ public function run(array $params) 'namespace CodeIgniter\\Tasks\\Config' => 'namespace Config', 'use CodeIgniter\\Config\\BaseConfig' => 'use CodeIgniter\\Tasks\\Config\\Tasks as BaseTasks', 'class Tasks extends BaseConfig' => 'class Tasks extends BaseTasks', - ] + ], ); } diff --git a/src/CronExpression.php b/src/CronExpression.php index b77561b..8cc24c3 100644 --- a/src/CronExpression.php +++ b/src/CronExpression.php @@ -145,7 +145,7 @@ private function checkTime(string $time, string $format): bool assert(ctype_digit($currentTime)); // Handle repeating times (i.e. /5 or */5 for every 5 minutes) - if (strpos($time, '/') !== false) { + if (str_contains($time, '/')) { $period = substr($time, strpos($time, '/') + 1) ?: ''; if ($period === '' || ! ctype_digit($period)) { @@ -156,7 +156,7 @@ private function checkTime(string $time, string $format): bool } // Handle ranges (1-5) - if (strpos($time, '-') !== false) { + if (str_contains($time, '-')) { $items = []; [$start, $end] = explode('-', $time); diff --git a/src/RunResolver.php b/src/RunResolver.php index 840a0c9..316131a 100644 --- a/src/RunResolver.php +++ b/src/RunResolver.php @@ -82,19 +82,19 @@ public function nextRun(string $expression, Time $next): Time $satisfied = true; } // If the value is a list - elseif (strpos($value, ',') !== false) { + elseif (str_contains($value, ',')) { if ($this->isInList($nextValue, $value)) { $satisfied = true; } } // If the value is a range - elseif (strpos($value, '-') !== false) { + elseif (str_contains($value, '-')) { if ($this->isInRange($nextValue, $value)) { $satisfied = true; } } // If the value is an increment - elseif (strpos($value, '/') !== false) { + elseif (str_contains($value, '/')) { if ($this->isInIncrement($nextValue, $value)) { $satisfied = true; } @@ -207,13 +207,13 @@ protected function convertDOWToNumbers(string $origValue): string } $days = [ - 'sun' => 0, - 'mon' => 1, - 'tue' => 2, - 'wed' => 3, - 'thu' => 4, - 'fri' => 5, - 'sat' => 6, + 'sun' => '0', + 'mon' => '1', + 'tue' => '2', + 'wed' => '3', + 'thu' => '4', + 'fri' => '5', + 'sat' => '6', ]; return str_replace(array_keys($days), array_values($days), $origValue); diff --git a/tests/_support/Commands/TasksTest.php b/tests/_support/Commands/TasksExample.php similarity index 74% rename from tests/_support/Commands/TasksTest.php rename to tests/_support/Commands/TasksExample.php index ea2d780..a368b3c 100644 --- a/tests/_support/Commands/TasksTest.php +++ b/tests/_support/Commands/TasksExample.php @@ -19,12 +19,12 @@ /** * @internal */ -final class TasksTest extends BaseCommand +final class TasksExample extends BaseCommand { protected $group = 'Testing'; - protected $name = 'tasks:test'; - protected $description = 'Tests Tasks'; - protected $usage = 'tasks:test'; + protected $name = 'tasks:example'; + protected $description = 'Tests Example'; + protected $usage = 'tasks:example'; public function run(array $params = []) { diff --git a/tests/unit/CronExpressionTest.php b/tests/unit/CronExpressionTest.php index 83f0cd2..a26f527 100644 --- a/tests/unit/CronExpressionTest.php +++ b/tests/unit/CronExpressionTest.php @@ -15,6 +15,7 @@ use CodeIgniter\Tasks\CronExpression; use CodeIgniter\Tasks\Exceptions\TasksException; use CodeIgniter\Test\CIUnitTestCase as TestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @internal @@ -140,11 +141,10 @@ public function testHoursAndMins() } /** - * @dataProvider provideEveryHour - * * @param mixed $hourTrue * @param mixed $hourFalse */ + #[DataProvider('provideEveryHour')] public function testEveryHour($hourTrue, $hourFalse) { $this->cron->testTime($hourTrue); @@ -234,9 +234,7 @@ public static function provideNextRun(): iterable ]; } - /** - * @dataProvider provideNextRun - */ + #[DataProvider('provideNextRun')] public function testNextRun(string $exp, string $expected) { $this->cron->testTime('October 5, 2020 8:00 pm'); diff --git a/tests/unit/TaskLogTest.php b/tests/unit/TaskLogTest.php index 7abb63c..cb9549e 100644 --- a/tests/unit/TaskLogTest.php +++ b/tests/unit/TaskLogTest.php @@ -15,6 +15,7 @@ use CodeIgniter\Tasks\Task; use CodeIgniter\Tasks\TaskLog; use CodeIgniter\Test\CIUnitTestCase as TestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @internal @@ -46,12 +47,11 @@ public static function provideDuration(): iterable } /** - * @dataProvider provideDuration - * * @param array|bool|int|string|null $output * * @throws Exception */ + #[DataProvider('provideDuration')] public function testDuration(string $start, string $end, string $expected, $output) { $start = new Time($start); diff --git a/tests/unit/TaskTest.php b/tests/unit/TaskTest.php index 788dcfb..5267079 100644 --- a/tests/unit/TaskTest.php +++ b/tests/unit/TaskTest.php @@ -90,13 +90,13 @@ public function testGetType() public function testCommandRunsCommand() { - $task = new Task('command', 'tasks:test'); + $task = new Task('command', 'tasks:example'); $task->run(); $this->assertStringContainsString( 'Commands can output text.', - $this->getBuffer() + $this->getBuffer(), ); }