Skip to content

Commit 35d2f68

Browse files
improved Tests with unit and functional tests (#20)
* updated configuration to fit refactoring for tests * added missing unit-tests * added command-tests * added execution-date parameter to schedule command * updated dependencies
1 parent 0653638 commit 35d2f68

30 files changed

+998
-303
lines changed

.scrutinizer.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
tools:
22
external_code_coverage:
3-
timeout: 300
4-
runs: 6
3+
timeout: 1200

.travis.yml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
language: php
22

3-
php:
4-
- 5.5
5-
- 5.6
6-
- 7.0
7-
- hhvm
8-
9-
env:
10-
- STORAGE=array
11-
- STORAGE=doctrine
3+
matrix:
4+
fast_finish: true
5+
include:
6+
- php: 5.6
7+
env:
8+
- STORAGE=doctrine
9+
- CODE_COVERAGE=true
10+
- php: 5.6
11+
env:
12+
- STORAGE=array
13+
- php: 7.0
14+
env:
15+
- STORAGE=doctrine
16+
- php: 7.0
17+
env:
18+
- STORAGE=array
19+
- php: hhvm
20+
env:
21+
- STORAGE=doctrine
22+
- php: hhvm
23+
env:
24+
- STORAGE=array
1225

1326
install:
1427
- composer self-update
1528
- composer update
16-
- wget https://scrutinizer-ci.com/ocular.phar
1729

1830
before_script:
1931
- STORAGE=doctrine tests/app/console doctrine:database:create
@@ -23,4 +35,10 @@ script:
2335
- phpunit -c phpunit.xml.dist --coverage-clover=coverage.clover
2436

2537
after_script:
26-
- php ocular.phar code-coverage:upload --access-token="230ec5e01daf5bb3e46ea304fb20348b52d80de73463ec08ee9c96fcd1349e35" --format=php-clover coverage.clover
38+
- if [[ $CODE_COVERAGE == 'true' ]]; then wget https://scrutinizer-ci.com/ocular.phar ; fi
39+
- if [[ $CODE_COVERAGE == 'true' ]]; then php ocular.phar code-coverage:upload --access-token="230ec5e01daf5bb3e46ea304fb20348b52d80de73463ec08ee9c96fcd1349e35" --format=php-clover coverage.clover ; fi
40+
41+
cache:
42+
directories:
43+
- "$HOME/.composer/cache"
44+
- vendor

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"php": "~5.5 || ~7.0",
13+
"php": "~5.6 || ~7.0",
1414
"php-task/php-task": "dev-master",
1515
"symfony/http-kernel": "^2.6",
1616
"symfony/dependency-injection": "^2.6",
@@ -22,13 +22,19 @@
2222
"phpunit/phpunit": "^4.8",
2323
"symfony/framework-bundle": "^2.6",
2424
"symfony/finder": "^2.6",
25-
"doctrine/doctrine-bundle": "^1.5"
25+
"doctrine/doctrine-bundle": "^1.5",
26+
"doctrine/data-fixtures": "^1.2"
2627
},
2728
"autoload": {
2829
"psr-4": {
2930
"Task\\TaskBundle\\": "src"
3031
}
3132
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"Task\\TaskBundle\\Tests\\": "tests"
36+
}
37+
},
3238
"extra": {
3339
"branch-alias": {
3440
"dev-master": "1.0-dev"

src/Command/DebugTasksCommand.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
19-
use Task\Execution\TaskExecutionRepositoryInterface;
19+
use Task\Storage\TaskExecutionRepositoryInterface;
2020

2121
/**
2222
* Run pending tasks.
@@ -26,17 +26,17 @@ class DebugTasksCommand extends Command
2626
/**
2727
* @var TaskExecutionRepositoryInterface
2828
*/
29-
private $storage;
29+
private $taskExecutionRepository;
3030

3131
/**
3232
* @param string $name
33-
* @param TaskExecutionRepositoryInterface $storage
33+
* @param TaskExecutionRepositoryInterface $taskExecutionRepository
3434
*/
35-
public function __construct($name, TaskExecutionRepositoryInterface $storage)
35+
public function __construct($name, TaskExecutionRepositoryInterface $taskExecutionRepository)
3636
{
3737
parent::__construct($name);
3838

39-
$this->storage = $storage;
39+
$this->taskExecutionRepository = $taskExecutionRepository;
4040
}
4141

4242
/**
@@ -45,17 +45,19 @@ public function __construct($name, TaskExecutionRepositoryInterface $storage)
4545
protected function configure()
4646
{
4747
$this->setDescription('Debug tasks')
48-
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, '', null);
48+
->addOption('page', 'p', InputOption::VALUE_REQUIRED, '', 1)
49+
->addOption('page-size', null, InputOption::VALUE_REQUIRED, '', null);
4950
}
5051

5152
/**
5253
* {@inheritdoc}
5354
*/
5455
protected function execute(InputInterface $input, OutputInterface $output)
5556
{
56-
$limit = $input->getOption('limit');
57+
$page = $input->getOption('page');
58+
$pageSize = $input->getOption('page-size');
5759

58-
$executions = $this->storage->findAll($limit);
60+
$executions = $this->taskExecutionRepository->findAll($page, $pageSize);
5961

6062
$table = new Table($output);
6163
$table->setHeaders(['uuid', 'status', 'handler', 'schedule time', 'end time', 'duration']);

src/Command/RunCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
1717
use Task\Runner\TaskRunnerInterface;
18-
use Task\Scheduler\SchedulerInterface;
18+
use Task\Scheduler\TaskSchedulerInterface;
1919

2020
/**
2121
* Run pending tasks.
@@ -28,16 +28,16 @@ class RunCommand extends Command
2828
private $runner;
2929

3030
/**
31-
* @var SchedulerInterface
31+
* @var TaskSchedulerInterface
3232
*/
3333
private $scheduler;
3434

3535
/**
3636
* @param string $name
3737
* @param TaskRunnerInterface $runner
38-
* @param SchedulerInterface $scheduler
38+
* @param TaskSchedulerInterface $scheduler
3939
*/
40-
public function __construct($name, TaskRunnerInterface $runner, SchedulerInterface $scheduler)
40+
public function __construct($name, TaskRunnerInterface $runner, TaskSchedulerInterface $scheduler)
4141
{
4242
parent::__construct($name);
4343

src/Command/ScheduleTaskCommand.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
19-
use Task\Scheduler\SchedulerInterface;
19+
use Task\Scheduler\TaskSchedulerInterface;
2020

2121
/**
2222
* Schedule task.
2323
*/
2424
class ScheduleTaskCommand extends Command
2525
{
2626
/**
27-
* @var SchedulerInterface
27+
* @var TaskSchedulerInterface
2828
*/
2929
private $scheduler;
3030

3131
/**
3232
* @param string $name
33-
* @param SchedulerInterface $runner
33+
* @param TaskSchedulerInterface $runner
3434
*/
35-
public function __construct($name, SchedulerInterface $runner)
35+
public function __construct($name, TaskSchedulerInterface $runner)
3636
{
3737
parent::__construct($name);
3838

@@ -46,9 +46,10 @@ protected function configure()
4646
{
4747
$this
4848
->setDescription('Run pending tasks')
49-
->addArgument('handler', InputArgument::REQUIRED)
49+
->addArgument('handlerClass', InputArgument::REQUIRED)
5050
->addArgument('workload', InputArgument::OPTIONAL)
5151
->addOption('cron-expression', 'c', InputOption::VALUE_REQUIRED)
52+
->addOption('execution-date', null, InputOption::VALUE_REQUIRED)
5253
->addOption('end-date', null, InputOption::VALUE_REQUIRED);
5354
}
5455

@@ -57,16 +58,17 @@ protected function configure()
5758
*/
5859
protected function execute(InputInterface $input, OutputInterface $output)
5960
{
60-
$handler = $input->getArgument('handler');
61+
$handlerClass = $input->getArgument('handlerClass');
6162
$workload = $input->getArgument('workload');
6263
$cronExpression = $input->getOption('cron-expression');
64+
$executionDateString = $input->getOption('execution-date');
6365
$endDateString = $input->getOption('end-date');
6466

6567
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
66-
$output->writeln(sprintf('Schedule task "%s" with workload "%s"', $handler, $workload));
68+
$output->writeln(sprintf('Schedule task "%s" with workload "%s"', $handlerClass, $workload));
6769
}
6870

69-
$taskBuilder = $this->scheduler->createTask($input->getArgument('handler'), $input->getArgument('workload'));
71+
$taskBuilder = $this->scheduler->createTask($handlerClass, $workload);
7072

7173
if ($cronExpression !== null) {
7274
$endDate = null;
@@ -77,6 +79,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
7779
$taskBuilder->cron($cronExpression, new \DateTime(), $endDate);
7880
}
7981

82+
if ($executionDateString !== null) {
83+
$taskBuilder->executeAt(new \DateTime($executionDateString));
84+
}
85+
8086
$this->scheduler->addTask($taskBuilder->getTask());
8187
}
8288
}

src/DoctrineStorage/TaskExecutionRepository.php

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)