Skip to content

Commit 90d882a

Browse files
committed
tests
1 parent 6c11f32 commit 90d882a

19 files changed

+321
-162
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"maglnet/composer-require-checker": "^2.0",
6868
"phpunit/phpunit": "^8.4",
6969
"symfony/var-dumper": "^4.3",
70-
"icanhazstring/composer-unused": "^0.6.2"
70+
"icanhazstring/composer-unused": "^0.6.2",
71+
"dg/bypass-finals": "^1.1"
7172
},
7273
"suggest": {
7374
"shapecode/cron-sonata-admin-bundle": "to manage cronjobs in the sonata admin panel"

composer.lock

Lines changed: 79 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/README.md

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,21 @@ Add the bundle to your project through composer:
2525
composer require shapecode/cron-bundle
2626
```
2727

28-
Add the bundle to your application kernel:
28+
Add the bundle to your config if it flex did not do it for you:
2929
```php
3030
<?php
3131

32-
// application/ApplicationKernel.php
33-
public function registerBundles()
34-
{
35-
// ...
36-
$bundles = array(
37-
// ...
38-
new Shapecode\Bundle\CronBundle\ShapecodeCronBundle(),
39-
);
32+
// config/bundles.php
33+
return [
4034
// ...
41-
42-
return $bundles;
43-
}
35+
Shapecode\Bundle\CronBundle\ShapecodeCronBundle::class,
36+
// ...
37+
];
4438
```
4539

4640
Update your DB schema ...
4741

48-
... with Doctrine standard method ...
42+
... with Doctrine schema update method ...
4943
```bash
5044
php bin/console doctrine:schema:update --force
5145
```
@@ -58,6 +52,8 @@ Creating your own tasks with CronBundle couldn't be easier - all you have to do
5852
```php
5953
<?php
6054

55+
declare(strict_types=1);
56+
6157
namespace App\DemoBundle\Command;
6258

6359
use Shapecode\Bundle\CronBundle\Annotation\CronJob;
@@ -66,29 +62,19 @@ use Symfony\Component\Console\Input\InputInterface;
6662
use Symfony\Component\Console\Output\OutputInterface;
6763

6864
/**
69-
* Class DemoCommand
70-
* @package App\DemoBundle\Command
71-
* @author Nikita Loges
72-
*
7365
* @CronJob("*\/5 * * * *")
7466
* Will be executed every 5 minutes
7567
*/
7668
class DemoCommand extends Command
7769
{
7870

79-
/**
80-
* @inheritdoc
81-
*/
82-
public function configure()
71+
public function configure() : void
8372
{
8473
// Must have a name configured
8574
// ...
8675
}
8776

88-
/**
89-
* @inheritdoc
90-
*/
91-
public function execute(InputInterface $input, OutputInterface $output)
77+
public function execute(InputInterface $input, OutputInterface $output) : void
9278
{
9379
// Your code here
9480
}

phpstan-baseline.neon

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Variable method call on Shapecode\\\\Bundle\\\\CronBundle\\\\Console\\\\Style\\\\CronStyle\\.$#"
5-
count: 1
6-
path: src/Command/CronProcessCommand.php
73

84
-
95
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#"
@@ -15,11 +11,6 @@ parameters:
1511
count: 3
1612
path: src/CronJob/GenericCleanUpHourlyCommand.php
1713

18-
-
19-
message: "#^Class Shapecode\\\\Bundle\\\\CronBundle\\\\Event\\\\GenericCleanUpEvent extends deprecated class Symfony\\\\Component\\\\EventDispatcher\\\\Event\\:\nsince Symfony 4\\.3, use \"Symfony\\\\Contracts\\\\EventDispatcher\\\\Event\" instead$#"
20-
count: 1
21-
path: src/Event/GenericCleanUpEvent.php
22-
2314
-
2415
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#"
2516
count: 1

phpunit.xml.dist

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
66
backupGlobals="false"
77
colors="true"
8-
processIsolation="false">
9-
<php>
10-
<ini name="error_reporting" value="-1"/>
11-
<server name="KERNEL_CLASS" value="AppKernel"/>
12-
</php>
8+
processIsolation="false"
9+
bootstrap="tests/bootstrap.php">
1310

1411
<testsuites>
1512
<testsuite name="default">

src/Command/CronProcessCommand.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use Symfony\Component\Stopwatch\Stopwatch;
1717
use Throwable;
1818
use function get_class;
19+
use function is_callable;
1920
use function number_format;
21+
use function sprintf;
2022
use function str_replace;
2123

2224
final class CronProcessCommand extends BaseCommand
@@ -92,7 +94,14 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
9294
}
9395

9496
$duration = $this->getStopWatch()->getEvent($watch)->getDuration();
95-
$style->{$block}($statusStr . ' in ' . number_format(($duration / 1000), 4) . ' seconds');
97+
98+
$seconds = $duration > 0 ? number_format(($duration / 1000), 4) : 0;
99+
$message = sprintf('%s in %s seconds', $statusStr, $seconds);
100+
101+
$callback = [$style, $block];
102+
if (is_callable($callback)) {
103+
$callback($message);
104+
}
96105

97106
// Record the result
98107
$this->recordJobResult($job, $duration, $jobOutput, $statusCode);

0 commit comments

Comments
 (0)