From d96036d6d6a8e7f8a5e8cfcaa63aca63d082828f Mon Sep 17 00:00:00 2001 From: Tadas Gliaubicas Date: Sun, 20 Nov 2016 21:16:49 +0200 Subject: [PATCH 1/2] Integrate new version library. --- Doctrine/EntityManager/JobConfigurationManager.php | 12 ++++++++++-- Resources/config/db_driver/orm.xml | 1 + Resources/config/services.xml | 10 +++------- composer.json | 6 ++++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Doctrine/EntityManager/JobConfigurationManager.php b/Doctrine/EntityManager/JobConfigurationManager.php index 8cf86b2..35e1e1b 100644 --- a/Doctrine/EntityManager/JobConfigurationManager.php +++ b/Doctrine/EntityManager/JobConfigurationManager.php @@ -41,17 +41,23 @@ class JobConfigurationManager extends BaseJobConfigurationManager */ protected $class; + /** + * @var int + */ + protected $resetTimeout; + /** * Constructor. * * @param EntityManager $em * @param string $class */ - public function __construct(EntityManager $em, $class) + public function __construct(EntityManager $em, $class, $resetTimeout) { $this->em = $em; $this->repository = $em->getRepository($class); $this->class = $em->getClassMetadata($class)->name; + $this->resetTimeout = $resetTimeout; } /** @@ -89,9 +95,11 @@ public function findByQueueAndState($queue, $state) /** * {@inheritdoc} */ - public function findPotentialDeadJobs(\DateTime $nextStart, $queue) + public function findPotentialDeadJobs($queue) { $qb = $this->repository->createQueryBuilder('jc'); + $nextStart = new \DateTime(); + $nextStart->modify(sprintf('- %d seconds', $this->resetTimeout)); $qb ->select('jc') diff --git a/Resources/config/db_driver/orm.xml b/Resources/config/db_driver/orm.xml index 7c62fd0..daf71b3 100644 --- a/Resources/config/db_driver/orm.xml +++ b/Resources/config/db_driver/orm.xml @@ -22,6 +22,7 @@ class="Aureja\Bundle\JobQueueBundle\Doctrine\EntityManager\JobConfigurationManager"> %aureja_job_queue.model.job_configuration.class% + %aureja_job_queue.reset.timeout% diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 1e9bc47..9895be4 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -19,11 +19,11 @@ - + + %aureja_job_queue.queues% - %aureja_job_queue.reset.timeout% @@ -35,11 +35,7 @@ - - - - - + diff --git a/composer.json b/composer.json index ff83f8f..d5d83f1 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,12 @@ "require": { "php": ">=5.4", - "aureja/job-queue": "0.1.*", - "symfony/framework-bundle" : ">=2.7|~3.0" + "aureja/job-queue": "0.2.*@dev", + "symfony/framework-bundle" : ">=2.7|~3.0", + "doctrine/doctrine-bundle": "~1.4" }, "require-dev": { + "doctrine/orm": "~2.4,>=2.4.5", "phpunit/phpunit": "~4.2" }, "suggest": { From c5c51cd758501f7da4d20ed3de5041b843de7b64 Mon Sep 17 00:00:00 2001 From: Tadas Gliaubicas Date: Sat, 26 Nov 2016 19:40:14 +0200 Subject: [PATCH 2/2] Add functional test structure. --- .gitignore | 3 ++ .travis.yml | 12 +++++ Form/Subscriber/AddJobFactorySubscriber.php | 14 +++--- .../doctrine/model/JobConfiguration.orm.xml | 2 +- Resources/config/form-subscribers.xml | 2 +- Resources/config/form-types.xml | 9 ---- Tests/App/AppKernel.php | 30 ++++++++++++ Tests/App/Entity/JobConfiguration.php | 10 ++++ Tests/App/Entity/JobReport.php | 10 ++++ .../config/doctrine/JobConfiguration.orm.xml | 16 +++++++ .../config/doctrine/JobReport.orm.xml | 16 +++++++ Tests/App/bootstrap.php | 8 ++++ Tests/App/cache/.gitkeep | 0 Tests/App/config.yml | 47 +++++++++++++++++++ Tests/App/routing.yml | 0 Tests/Functional/JobQueueTest.php | 43 +++++++++++++++++ composer.json | 5 +- phpunit.xml.dist | 41 ++++++++++++++++ 18 files changed, 248 insertions(+), 20 deletions(-) create mode 100644 .travis.yml create mode 100644 Tests/App/AppKernel.php create mode 100644 Tests/App/Entity/JobConfiguration.php create mode 100644 Tests/App/Entity/JobReport.php create mode 100644 Tests/App/Resources/config/doctrine/JobConfiguration.orm.xml create mode 100644 Tests/App/Resources/config/doctrine/JobReport.orm.xml create mode 100644 Tests/App/bootstrap.php create mode 100644 Tests/App/cache/.gitkeep create mode 100644 Tests/App/config.yml create mode 100644 Tests/App/routing.yml create mode 100644 Tests/Functional/JobQueueTest.php create mode 100644 phpunit.xml.dist diff --git a/.gitignore b/.gitignore index f4686f8..c6d74bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /.idea/ +!/Tests/App/cache/ +/Tests/App/cache/* +!Tests/App/cache/.gitkeep /vendor/ /composer.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..12fe3b9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: php + +php: + - 5.4 + - 5.5 + - 5.6 + - 7.0 + +before_script: + - phpunit --self-update + - composer self-update + - composer install --dev diff --git a/Form/Subscriber/AddJobFactorySubscriber.php b/Form/Subscriber/AddJobFactorySubscriber.php index 82208b1..db5c16c 100644 --- a/Form/Subscriber/AddJobFactorySubscriber.php +++ b/Form/Subscriber/AddJobFactorySubscriber.php @@ -12,8 +12,8 @@ namespace Aureja\Bundle\JobQueueBundle\Form\Subscriber; use Aureja\Bundle\JobQueueBundle\Util\LegacyFormHelper; +use Aureja\JobQueue\JobFactoryRegistry; use Aureja\JobQueue\Model\JobConfigurationInterface; -use Aureja\JobQueue\Provider\JobProviderInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -28,18 +28,18 @@ class AddJobFactorySubscriber implements EventSubscriberInterface { /** - * @var JobProviderInterface + * @var JobFactoryRegistry */ - private $jobProvider; + private $registry; /** * Constructor. * - * @param JobProviderInterface $jobProvider + * @param JobFactoryRegistry $registry */ - public function __construct(JobProviderInterface $jobProvider) + public function __construct(JobFactoryRegistry $registry) { - $this->jobProvider = $jobProvider; + $this->registry = $registry; } /** @@ -82,7 +82,7 @@ public function addJobFactoryField(FormEvent $event) */ private function getFactoryNameChoices() { - $names = $this->jobProvider->getFactoryNames(); + $names = $this->registry->getNames(); return array_combine($names, $names); } diff --git a/Resources/config/doctrine/model/JobConfiguration.orm.xml b/Resources/config/doctrine/model/JobConfiguration.orm.xml index b225c05..3f35d54 100644 --- a/Resources/config/doctrine/model/JobConfiguration.orm.xml +++ b/Resources/config/doctrine/model/JobConfiguration.orm.xml @@ -22,7 +22,7 @@ - + diff --git a/Resources/config/form-subscribers.xml b/Resources/config/form-subscribers.xml index 33eb5fd..079a80b 100644 --- a/Resources/config/form-subscribers.xml +++ b/Resources/config/form-subscribers.xml @@ -18,7 +18,7 @@ - + diff --git a/Resources/config/form-types.xml b/Resources/config/form-types.xml index 6a89d09..e6e9c6e 100644 --- a/Resources/config/form-types.xml +++ b/Resources/config/form-types.xml @@ -27,15 +27,6 @@ %aureja_job_queue.model.job_configuration.class% - - - - - - %aureja_job_queue.queues% - %aureja_job_queue.model.job_configuration.class% - - diff --git a/Tests/App/AppKernel.php b/Tests/App/AppKernel.php new file mode 100644 index 0000000..c3a637c --- /dev/null +++ b/Tests/App/AppKernel.php @@ -0,0 +1,30 @@ +load(__DIR__ . '/config.yml'); + } +} diff --git a/Tests/App/Entity/JobConfiguration.php b/Tests/App/Entity/JobConfiguration.php new file mode 100644 index 0000000..bae8e9f --- /dev/null +++ b/Tests/App/Entity/JobConfiguration.php @@ -0,0 +1,10 @@ + + + + + + + + + + + + + diff --git a/Tests/App/Resources/config/doctrine/JobReport.orm.xml b/Tests/App/Resources/config/doctrine/JobReport.orm.xml new file mode 100644 index 0000000..ecdfe49 --- /dev/null +++ b/Tests/App/Resources/config/doctrine/JobReport.orm.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/Tests/App/bootstrap.php b/Tests/App/bootstrap.php new file mode 100644 index 0000000..5061c3d --- /dev/null +++ b/Tests/App/bootstrap.php @@ -0,0 +1,8 @@ +initClient(); + + $this->em = $this->getContainer()->get('doctrine.orm.entity_manager'); + + $this->createSchema(); + } + + public function testRun() + { + + } + + private function createSchema() + { + $schemaTool = new SchemaTool($this->em); + $schemaTool->createSchema( + [ + $this->em->getClassMetadata(JobConfiguration::class), + $this->em->getClassMetadata(JobReport::class), + ] + ); + + } +} diff --git a/composer.json b/composer.json index d5d83f1..de6cb51 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,13 @@ "php": ">=5.4", "aureja/job-queue": "0.2.*@dev", - "symfony/framework-bundle" : ">=2.7|~3.0", + "symfony/symfony" : ">=2.7|~3.0", "doctrine/doctrine-bundle": "~1.4" }, "require-dev": { "doctrine/orm": "~2.4,>=2.4.5", - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "~4.2", + "aureja/test-framework-bundle": "~0.1" }, "suggest": { "silvestra/paginator-bundle": "For using the job reports pagination." diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..efce75e --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,41 @@ + + + + + + + + + + + + + Tests/Functional + + + + + + . + + Tests/ + vendor/ + + + + \ No newline at end of file