Skip to content

Commit

Permalink
Cake5 (#4)
Browse files Browse the repository at this point in the history
* Init Cake5 upgrade
  • Loading branch information
dereuromark committed Nov 16, 2023
1 parent 12ff9eb commit 5d9d74e
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 62 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.2']
php-version: ['8.1', '8.3']
db-type: ['sqlite', 'mysql', 'pgsql']
prefer-lowest: ['']
include:
- php-version: '7.4'
- php-version: '8.1'
db-type: 'sqlite'
prefer-lowest: 'prefer-lowest'

Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?encoding=utf8'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
Expand All @@ -87,7 +87,7 @@ jobs:
run: if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then vendor/bin/validate-prefer-lowest -m; fi

- name: Code Coverage Report
if: success() && matrix.php-version == '7.4'
if: success() && matrix.php-version == '8.1'
uses: codecov/codecov-action@v3

validation:
Expand All @@ -100,7 +100,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
extensions: mbstring, intl
coverage: none

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
"type": "cakephp-plugin",
"license": "MIT",
"require": {
"php": ">=7.4",
"cakephp/cakephp": "^4.4.17",
"php": ">=8.1",
"cakephp/cakephp": "^5.0.1",
"dragonmantank/cron-expression": "^3.3",
"dereuromark/cakephp-tools": "^2.5.0",
"dereuromark/cakephp-queue": "^6.7.2"
"dereuromark/cakephp-tools": "^3.0.0",
"dereuromark/cakephp-queue": "^7.0.0"
},
"require-dev": {
"cakephp/migrations": "^3.9.0",
"phpunit/phpunit": "^9.5",
"fig-r/psr2r-sniffer": "^1.5.1"
"cakephp/migrations": "^4.1.0",
"phpunit/phpunit": "^10.3",
"fig-r/psr2r-sniffer": "dev-next"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<exclude-pattern>*/config/Migrations/*</exclude-pattern>
<exclude-pattern>*/config/Seeds/*</exclude-pattern>
</rule>
<rule ref="Spryker.Classes.ClassFileName.NoMatch">
<rule ref="PhpCollective.Classes.ClassFileName.NoMatch">
<exclude-pattern>*/config/Migrations/*</exclude-pattern>
</rule>

Expand Down
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
</testsuites>

<extensions>
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension"/>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>

<coverage>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
</source>
</phpunit>
18 changes: 9 additions & 9 deletions src/Model/Entity/SchedulerRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace QueueScheduler\Model\Entity;

use Cake\I18n\FrozenTime;
use Cake\I18n\DateTime;
use Cron\CronExpression;
use DateInterval;
use Queue\Queue\Config;
Expand All @@ -18,11 +18,11 @@
* @property int $type
* @property string $content
* @property string $frequency
* @property \Cake\I18n\FrozenTime|null $last_run
* @property \Cake\I18n\FrozenTime|null $next_run
* @property \Cake\I18n\DateTime|null $last_run
* @property \Cake\I18n\DateTime|null $next_run
* @property bool $allow_concurrent
* @property \Cake\I18n\FrozenTime|null $created
* @property \Cake\I18n\FrozenTime|null $modified
* @property \Cake\I18n\DateTime|null $created
* @property \Cake\I18n\DateTime|null $modified
* @property bool $enabled
* @property-read string|null $job_task
* @property-read array $job_data
Expand All @@ -40,7 +40,7 @@ class SchedulerRow extends Entity {
*
* @var array<string, bool>
*/
protected $_accessible = [
protected array $_accessible = [
'*' => true,
'id' => false,
];
Expand Down Expand Up @@ -82,7 +82,7 @@ public static function types($value = null) {
public function isDue(): bool {
$nextRun = $this->next_run;

$dateTime = new FrozenTime();
$dateTime = new DateTime();
if ($nextRun) {
return $nextRun->timestamp < $dateTime->timestamp;
}
Expand Down Expand Up @@ -119,12 +119,12 @@ public function calculateNextInterval(): ?DateInterval {

/**
* @throws \Exception
* @return \Cake\I18n\FrozenTime|null
* @return \Cake\I18n\DateTime|null
*/
public function calculateNextRun() {
$dateTime = $this->last_run;
if ($dateTime === null) {
return new FrozenTime();
return new DateTime();
}

$i = $this->calculateNextInterval();
Expand Down
20 changes: 10 additions & 10 deletions src/Model/Table/SchedulerRowsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\I18n\FrozenTime;
use Cake\ORM\Query;
use Cake\I18n\DateTime;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\Validation\Validator;
Expand Down Expand Up @@ -172,11 +172,11 @@ public function beforeSave(EventInterface $event, EntityInterface $entity, Array
}

/**
* @param \Cake\ORM\Query $query
* @param \Cake\ORM\Query\SelectQuery $query
*
* @return \Cake\ORM\Query
* @return \Cake\ORM\Query\SelectQuery
*/
public function findActive(Query $query) {
public function findActive(SelectQuery $query): SelectQuery {
$conditions = ['enabled' => true];
$debug = Configure::read('debug');
if (!$debug && !Configure::read('QueueScheduler.allowRaw')) {
Expand All @@ -187,12 +187,12 @@ public function findActive(Query $query) {
}

/**
* @param \Cake\ORM\Query $query
* @param \Cake\ORM\Query\SelectQuery $query
*
* @return \Cake\ORM\Query
* @return \Cake\ORM\Query\SelectQuery
*/
public function findScheduled(Query $query) {
return $query->where(['OR' => ['next_run IS' => null, 'next_run <=' => new FrozenTime()]]);
public function findScheduled(SelectQuery $query): SelectQuery {
return $query->where(['OR' => ['next_run IS' => null, 'next_run <=' => new DateTime()]]);
}

/**
Expand All @@ -215,7 +215,7 @@ public function run(SchedulerRow $row): bool {
}

$queuedJobsTable->createJob($row->job_task, $row->job_data, $config);
$row->last_run = new FrozenTime();
$row->last_run = new DateTime();
$this->saveOrFail($row);

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/QueueSchedulerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class QueueSchedulerPlugin extends BasePlugin {
/**
* @var bool
*/
protected $bootstrapEnabled = false;
protected bool $bootstrapEnabled = false;

/**
* @var bool
*/
protected $middlewareEnabled = false;
protected bool $middlewareEnabled = false;

/**
* Add routes for the plugin.
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixture/SchedulerRowsFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class SchedulerRowsFixture extends TestFixture {
/**
* @var string
*/
public $table = 'queue_scheduler_rows';
public string $table = 'queue_scheduler_rows';

/**
* @var array
*/
public $fields = [
public array $fields = [
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'name' => ['type' => 'string', 'length' => 140, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'type' => ['type' => 'tinyinteger', 'length' => null, 'unsigned' => false, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null],
Expand Down
12 changes: 1 addition & 11 deletions tests/TestCase/Command/RunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,10 @@ class RunCommandTest extends TestCase {
/**
* @var string[]
*/
protected $fixtures = [
protected array $fixtures = [
'plugin.QueueScheduler.SchedulerRows',
];

/**
* setUp method
*
* @return void
*/
protected function setUp(): void {
parent::setUp();
$this->useCommandRunner();
}

/**
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SchedulerRowsControllerTest extends TestCase {
/**
* @var string[]
*/
protected $fixtures = [
protected array $fixtures = [
'plugin.QueueScheduler.SchedulerRows',
];

Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Model/Table/SchedulerRowsTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace QueueScheduler\Test\TestCase\Model\Table;

use Cake\Command\CacheClearCommand;
use Cake\I18n\FrozenTime;
use Cake\I18n\DateTime;
use Cake\TestSuite\TestCase;
use Queue\Queue\Task\ExampleTask;
use QueueScheduler\Model\Entity\SchedulerRow;
Expand All @@ -27,7 +27,7 @@ class SchedulerRowsTableTest extends TestCase {
*
* @var array<string>
*/
protected $fixtures = [
protected array $fixtures = [
'plugin.QueueScheduler.SchedulerRows',
];

Expand Down Expand Up @@ -73,13 +73,13 @@ public function testInsert(): void {
$this->assertNotEmpty($row->next_run);
$this->assertSame($row->next_run->getTestNow()->toDateTimeString(), $row->next_run->toDateTimeString());

$row->last_run = (new FrozenTime())->addDays(1);
$row->last_run = (new DateTime())->addDays(1);
$row->frequency = '+50seconds';
$row = $this->SchedulerRows->saveOrFail($row);

$this->assertSame($row->next_run->getTestNow()->addDays(1)->addSeconds(50)->toDateTimeString(), $row->next_run->toDateTimeString());

$row->last_run = (new FrozenTime())->addDays(2);
$row->last_run = (new DateTime())->addDays(2);
$row = $this->SchedulerRows->saveOrFail($row);

$this->assertSame($row->next_run->getTestNow()->addDays(2)->addSeconds(50)->toDateTimeString(), $row->next_run->toDateTimeString());
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Utility/CommandFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Cake\Core\Plugin as CakePlugin;
use Cake\TestSuite\TestCase;
use Queue\Plugin;
use Queue\QueuePlugin;
use QueueScheduler\Utility\CommandFinder;

class CommandFinderTest extends TestCase {
Expand All @@ -13,7 +13,7 @@ class CommandFinderTest extends TestCase {
* @return void
*/
public function testAll() {
CakePlugin::getCollection()->add(new Plugin());
CakePlugin::getCollection()->add(new QueuePlugin());

$result = (new CommandFinder())->all();
$expected = [
Expand Down
5 changes: 3 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

require PLUGIN_ROOT . '/vendor/autoload.php';
require CORE_PATH . 'config/bootstrap.php';
require CAKE . 'functions.php';

Configure::write('App', [
'namespace' => 'TestApp',
Expand Down Expand Up @@ -99,8 +100,8 @@ class_alias(AppController::class, 'App\Controller\AppController');
]);

Plugin::getCollection()->add(new QueueScheduler\QueueSchedulerPlugin());
Plugin::getCollection()->add(new Queue\Plugin());
Plugin::getCollection()->add(new Tools\Plugin());
Plugin::getCollection()->add(new Queue\QueuePlugin());
Plugin::getCollection()->add(new Tools\ToolsPlugin());

if (!getenv('DB_URL')) {
putenv('DB_URL=sqlite:///:memory:');
Expand Down
15 changes: 12 additions & 3 deletions tests/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ function addTablesFromSchemaFile(string $file, string $pluginName, array $tables

$name = $matches[1];
$class = $pluginName . '\\Test\\Fixture\\' . $name . 'Fixture';
try {
$fieldsObject = (new ReflectionClass($class))->getProperty('fields');
$tableObject = (new ReflectionClass($class))->getProperty('table');
$tableName = $tableObject->getDefaultValue();
} catch (ReflectionException $e) {
return $tables;
}

if (!$tableName) {
$tableName = Inflector::underscore($name);
}

$object = new $class();
$array = $object->fields;
$tableName = $object->table ?: Inflector::underscore($name);
$array = $fieldsObject->getDefaultValue();
$constraints = $array['_constraints'] ?? [];
$indexes = $array['_indexes'] ?? [];
unset($array['_constraints'], $array['_indexes'], $array['_options']);
Expand Down

0 comments on commit 5d9d74e

Please sign in to comment.