Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Check & fix styling

on: [push]
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'

permissions:
contents: write
Expand All @@ -15,12 +21,13 @@ jobs:
with:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes
- name: Install Composer packages
run: composer update --ansi --no-interaction

- name: Run PHP-CS-Fixer Lint
run: vendor/bin/php-cs-fixer fix

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
commit_message: Fix styling
18 changes: 18 additions & 0 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@
'count' => 1,
'path' => __DIR__ . '/src/Commands/Run.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method startOfMinute\\(\\) on BlitzPHP\\\\Utilities\\\\Date\\|string\\.$#',
'identifier' => 'method.nonObject',
'count' => 2,
'path' => __DIR__ . '/src/Commands/Work.php',
];
$ignoreErrors[] = [
'message' => '#^While loop condition is always true\\.$#',
'identifier' => 'while.alwaysTrue',
'count' => 1,
'path' => __DIR__ . '/src/Commands/Work.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$name of function service expects class\\-string\\<container\\>, string given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/src/Task.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$name of function service expects class\\-string\\<cronExpression\\>, string given\\.$#',
'identifier' => 'argument.type',
Expand Down
28 changes: 14 additions & 14 deletions spec/FrequenciesTrait.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
$this->class->daily('4:08 pm');
expect('08 16 * * *')->toBe($this->class->getExpression());

$this->class->at('4:08 pm');
$this->class->at('4:08 pm');
expect('08 16 * * *')->toBe($this->class->getExpression());

$this->class->at('04:28');
$this->class->at('04:28');
expect('28 4 * * *')->toBe($this->class->getExpression());
});

Expand Down Expand Up @@ -241,16 +241,16 @@
$this->class->everyHour(3);
$this->assertSame('0 */3 * * *', $this->class->getExpression());

$this->class->everyTwoHours();
$this->class->everyTwoHours();
$this->assertSame('0 */2 * * *', $this->class->getExpression());

$this->class->everyThreeHours();
$this->class->everyThreeHours();
$this->assertSame('0 */3 * * *', $this->class->getExpression());

$this->class->everyFourHours();
$this->class->everyFourHours();
$this->assertSame('0 */4 * * *', $this->class->getExpression());

$this->class->everySixHours();
$this->class->everySixHours();
$this->assertSame('0 */6 * * *', $this->class->getExpression());
});

Expand Down Expand Up @@ -300,19 +300,19 @@
$this->class->everyMinute(15);
$this->assertSame('*/15 * * * *', $this->class->getExpression());

$this->class->everyTwoMinutes();
$this->class->everyTwoMinutes();
$this->assertSame('*/2 * * * *', $this->class->getExpression());

$this->class->everyThreeMinutes();
$this->class->everyThreeMinutes();
$this->assertSame('*/3 * * * *', $this->class->getExpression());

$this->class->everyFourMinutes();
$this->class->everyFourMinutes();
$this->assertSame('*/4 * * * *', $this->class->getExpression());

$this->class->everyTenMinutes();
$this->class->everyTenMinutes();
$this->assertSame('*/10 * * * *', $this->class->getExpression());

$this->class->everyThirtyMinutes();
$this->class->everyThirtyMinutes();
$this->assertSame('*/30 * * * *', $this->class->getExpression());
});

Expand Down Expand Up @@ -340,9 +340,9 @@
$this->assertSame('* * 1,15 * *', $this->class->getExpression());
});

it('testLastDayOfMonth', function () {
it('testLastDayOfMonth', function () {
$this->class->lastDayOfMonth();
$lastDay = Date::now()->endOfMonth()->getDay();
$lastDay = Date::now()->endOfMonth()->getDay();

$this->assertSame('0 0 ' . $lastDay . ' * *', $this->class->getExpression());
});
Expand All @@ -359,7 +359,7 @@
$this->assertSame('* * * 1-7 *', $this->class->getExpression());
});

it('testBetween', function () {
it('testBetween', function () {
$this->class->between('10:00', '12:30');

$this->assertSame('0-30 10-12 * * *', $this->class->getExpression());
Expand Down
108 changes: 54 additions & 54 deletions spec/HooksTrait.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@

describe('HookTrait', function () {
it('testAfter et testBefore', function () {
expect(file_exists($path = __DIR__.'/test-hook.txt'))->toBeFalsy();
expect(file_exists($path = __DIR__ . '/test-hook.txt'))->toBeFalsy();

$task = new Task('closure', fn() => 'Hello');
$task->before(function() use($path) {
file_put_contents($path, 'before');
});
$task = new Task('closure', fn () => 'Hello');
$task->before(function () use ($path) {
file_put_contents($path, 'before');
});

$task->after(function() use($path) {
file_put_contents($path, 'after', FILE_APPEND);
});
$task->after(function () use ($path) {
file_put_contents($path, 'after', FILE_APPEND);
});

$result = $task->run();
$result = $task->run();

expect(file_exists($path))->toBeTruthy();
$content = file_get_contents($path);
expect(file_exists($path))->toBeTruthy();
$content = file_get_contents($path);

expect(str_contains($content, 'before'))->toBeTruthy();
expect(str_contains($content, 'after'))->toBeTruthy();
expect($result)->toBe('Hello');
expect(str_contains($content, 'before'))->toBeTruthy();
expect(str_contains($content, 'after'))->toBeTruthy();
expect($result)->toBe('Hello');

unlink($path);
unlink($path);
});

it('sendOutputTo', function () {
$task = new Task('closure', function() {
echo 'Hello';
it('sendOutputTo', function () {
$task = new Task('closure', function () {
echo 'Hello';

return 'world';
return 'world';
});

$task->sendOutputTo($path = __DIR__ . '/output.txt');
$task->sendOutputTo($path = __DIR__ . '/output.txt');

$result = $task->run();

Expand All @@ -54,50 +54,50 @@
expect($result)->toBe('world');

unlink($path);
});
});

it('appendOutputTo', function () {
$task = new Task('closure', function() {
echo 'Hello';
});
it('appendOutputTo', function () {
$task = new Task('closure', function () {
echo 'Hello';
});

$task->appendOutputTo($path = __DIR__ . '/output.txt');
$task->appendOutputTo($path = __DIR__ . '/output.txt');

file_put_contents($path, 'World');
file_put_contents($path, 'World');

$task->run();

expect(file_exists($path))->toBeTruthy();
expect(file_get_contents($path))->toBe('WorldHello');

unlink($path);
});
});

it('onSuccess', function () {
$task = new Task('closure', fn() => 'Hello');
it('onSuccess', function () {
$task = new Task('closure', fn () => 'Hello');

expect(file_exists($path = __DIR__.'/test-hook.txt'))->toBeFalsy();
expect(file_exists($path = __DIR__ . '/test-hook.txt'))->toBeFalsy();

$task->onSuccess(function() use($path) {
$task->onSuccess(function () use ($path) {
file_put_contents($path, 'Success!');
});

$task->run();

expect(file_exists($path))->toBeTruthy();
expect(file_get_contents($path))->toBe('Success!');
expect(file_exists($path))->toBeTruthy();
expect(file_get_contents($path))->toBe('Success!');

unlink($path);
});
unlink($path);
});

it('onFailure', function () {
$task = new Task('closure', function() {
it('onFailure', function () {
$task = new Task('closure', function () {
throw new Exception('Error');
});

expect(file_exists($path = __DIR__.'/test-hook.txt'))->toBeFalsy();
expect(file_exists($path = __DIR__ . '/test-hook.txt'))->toBeFalsy();

$task->onFailure(function() use($path) {
$task->onFailure(function () use ($path) {
file_put_contents($path, 'Failure!');
});

Expand All @@ -106,15 +106,15 @@
expect(file_exists($path))->toBeTruthy();
expect(file_get_contents($path))->toBe('Failure!');

unlink($path);
});
unlink($path);
});

it('onFailure lorsqu\'il y\'a pas exception mais on renvoie un code d\'erreur', function () {
$task = new Task('closure', fn() => EXIT_ERROR);
it('onFailure lorsqu\'il y\'a pas exception mais on renvoie un code d\'erreur', function () {
$task = new Task('closure', fn () => EXIT_ERROR);

expect(file_exists($path = __DIR__.'/test-hook.txt'))->toBeFalsy();
expect(file_exists($path = __DIR__ . '/test-hook.txt'))->toBeFalsy();

$task->onFailure(function() use($path) {
$task->onFailure(function () use ($path) {
file_put_contents($path, 'Failure!');
});

Expand All @@ -123,17 +123,17 @@
expect(file_exists($path))->toBeTruthy();
expect(file_get_contents($path))->toBe('Failure!');

unlink($path);
});
unlink($path);
});

it('onFailure avec recuperation de l\'exception', function () {
$task = new Task('closure', function() {
it('onFailure avec recuperation de l\'exception', function () {
$task = new Task('closure', function () {
throw new Exception('Error');
});

expect(file_exists($path = __DIR__.'/test-hook.txt'))->toBeFalsy();
expect(file_exists($path = __DIR__ . '/test-hook.txt'))->toBeFalsy();

$task->onFailure(function(Throwable $e) use($path) {
$task->onFailure(function (Throwable $e) use ($path) {
file_put_contents($path, $e->getMessage());
});

Expand All @@ -142,6 +142,6 @@
expect(file_exists($path))->toBeTruthy();
expect(file_get_contents($path))->toBe('Error');

unlink($path);
});
unlink($path);
});
});
4 changes: 2 additions & 2 deletions spec/Scheduler.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public function __invoke(Container $container)
expect('shell')->toBe($task->getType());
});

it('Peut sauvegarder un evenement', function () {
it('Peut sauvegarder un evenement', function () {
$task = $this->scheduler->event('foo.bar');

expect($task)->toBeAnInstanceOf(Task::class);
expect('foo.bar')->toBe($task->getAction());
expect('event')->toBe($task->getType());
});

it('Peut sauvegarder un appel d\'URL', function () {
it('Peut sauvegarder un appel d\'URL', function () {
$task = $this->scheduler->url('http://localhost');

expect($task)->toBeAnInstanceOf(Task::class);
Expand Down
Loading
Loading