Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Symfony 4.4, update project dependencies, update test… #259

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
phpunit.xml
vendor/
.idea/
.idea/
.phpunit.result.cache
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ language: php

sudo: false

env:
- XDEBUG_MODE=coverage

cache:
directories:
- $HOME/.composer/cache

matrix:
fast_finish: true
include:
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4

before_script:
- composer self-update
- echo "memory_limit=3G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- echo "xdebug.mode=coverage" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

install: composer install --dev
install: composer install

script: phpunit --coverage-clover clover

Expand Down
4 changes: 2 additions & 2 deletions Command/CleanUpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace JMS\JobQueueBundle\Command;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
use JMS\JobQueueBundle\Entity\Job;
Expand All @@ -19,7 +19,7 @@ class CleanUpCommand extends Command
private $jobManager;
private $registry;

public function __construct(ManagerRegistry $registry, JobManager $jobManager)
public function __construct(Registry $registry, JobManager $jobManager)
{
parent::__construct();

Expand Down
4 changes: 2 additions & 2 deletions Command/MarkJobIncompleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace JMS\JobQueueBundle\Command;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManager;
use JMS\JobQueueBundle\Entity\Job;
use Symfony\Component\Console\Command\Command;
Expand All @@ -18,7 +18,7 @@ class MarkJobIncompleteCommand extends Command
private $registry;
private $jobManager;

public function __construct(ManagerRegistry $managerRegistry, JobManager $jobManager)
public function __construct(Registry $managerRegistry, JobManager $jobManager)
{
parent::__construct();

Expand Down
12 changes: 6 additions & 6 deletions Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

namespace JMS\JobQueueBundle\Command;

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManager;
use JMS\JobQueueBundle\Entity\Job;
use JMS\JobQueueBundle\Entity\Repository\JobManager;
use JMS\JobQueueBundle\Event\NewOutputEvent;
use JMS\JobQueueBundle\Event\StateChangeEvent;
use JMS\JobQueueBundle\Exception\InvalidArgumentException;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -46,7 +46,7 @@ class RunCommand extends Command
/** @var OutputInterface */
private $output;

/** @var ManagerRegistry */
/** @var Registry */
private $registry;

/** @var JobManager */
Expand All @@ -67,7 +67,7 @@ class RunCommand extends Command
/** @var array */
private $queueOptions;

public function __construct(ManagerRegistry $managerRegistry, JobManager $jobManager, EventDispatcherInterface $dispatcher, array $queueOptionsDefault, array $queueOptions)
public function __construct(Registry $managerRegistry, JobManager $jobManager, EventDispatcherInterface $dispatcher, array $queueOptionsDefault, array $queueOptions)
{
parent::__construct();

Expand Down Expand Up @@ -283,13 +283,13 @@ private function checkRunningJobs()

if ( ! empty($newOutput)) {
$event = new NewOutputEvent($data['job'], $newOutput, NewOutputEvent::TYPE_STDOUT);
$this->dispatcher->dispatch('jms_job_queue.new_job_output', $event);
$this->dispatcher->dispatch($event, 'jms_job_queue.new_job_output');
$newOutput = $event->getNewOutput();
}

if ( ! empty($newErrorOutput)) {
$event = new NewOutputEvent($data['job'], $newErrorOutput, NewOutputEvent::TYPE_STDERR);
$this->dispatcher->dispatch('jms_job_queue.new_job_output', $event);
$this->dispatcher->dispatch($event, 'jms_job_queue.new_job_output');
$newErrorOutput = $event->getNewOutput();
}

Expand Down Expand Up @@ -350,7 +350,7 @@ private function checkRunningJobs()
private function startJob(Job $job)
{
$event = new StateChangeEvent($job, Job::STATE_RUNNING);
$this->dispatcher->dispatch('jms_job_queue.job_state_change', $event);
$this->dispatcher->dispatch($event, 'jms_job_queue.job_state_change');
$newState = $event->getNewState();

if (Job::STATE_CANCELED === $newState) {
Expand Down
4 changes: 2 additions & 2 deletions Command/ScheduleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace JMS\JobQueueBundle\Command;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use JMS\JobQueueBundle\Console\CronCommand;
Expand All @@ -23,7 +23,7 @@ class ScheduleCommand extends Command
private $schedulers;
private $cronCommands;

public function __construct(ManagerRegistry $managerRegistry, iterable $schedulers, iterable $cronCommands)
public function __construct(Registry $managerRegistry, iterable $schedulers, iterable $cronCommands)
{
parent::__construct();

Expand Down
2 changes: 1 addition & 1 deletion Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\HttpKernel\KernelInterface;

/**
Expand Down
6 changes: 3 additions & 3 deletions Controller/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use JMS\JobQueueBundle\Entity\Job;
use JMS\JobQueueBundle\Entity\Repository\JobManager;
use JMS\JobQueueBundle\View\JobFilter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;

class JobController extends Controller
class JobController extends AbstractController
{
/**
* @Route("/", name = "jms_jobs_overview")
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('jms_job_queue');
$treeBuilder = new TreeBuilder('jms_job_queue');
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down
2 changes: 1 addition & 1 deletion Entity/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Doctrine\ORM\Mapping as ORM;
use JMS\JobQueueBundle\Exception\InvalidStateTransitionException;
use JMS\JobQueueBundle\Exception\LogicException;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\ErrorHandler\Exception\FlattenException;

/**
* @ORM\Entity
Expand Down
3 changes: 2 additions & 1 deletion Entity/Listener/ManyToAnyListener.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace JMS\JobQueueBundle\Entity\Listener;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\Event\LifecycleEventArgs;
use JMS\JobQueueBundle\Entity\Job;

Expand All @@ -19,7 +20,7 @@ class ManyToAnyListener
private $registry;
private $ref;

public function __construct(\Doctrine\Common\Persistence\ManagerRegistry $registry)
public function __construct(Registry $registry)
{
$this->registry = $registry;
$this->ref = new \ReflectionProperty('JMS\JobQueueBundle\Entity\Job', 'relatedEntities');
Expand Down
4 changes: 2 additions & 2 deletions Entity/Listener/PersistentRelatedEntitiesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use ArrayIterator;
use Closure;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
use Doctrine\Common\Collections\Selectable;
use Doctrine\Common\Persistence\ManagerRegistry;
use JMS\JobQueueBundle\Entity\Job;

/**
Expand All @@ -25,7 +25,7 @@ class PersistentRelatedEntitiesCollection implements Collection, Selectable
private $job;
private $entities;

public function __construct(ManagerRegistry $registry, Job $job)
public function __construct(Registry $registry, Job $job)
{
$this->registry = $registry;
$this->job = $job;
Expand Down
6 changes: 3 additions & 3 deletions Entity/Repository/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace JMS\JobQueueBundle\Entity\Repository;

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\Connection;
Expand All @@ -29,7 +30,6 @@
use JMS\JobQueueBundle\Event\StateChangeEvent;
use JMS\JobQueueBundle\Retry\ExponentialRetryScheduler;
use JMS\JobQueueBundle\Retry\RetryScheduler;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class JobManager
Expand All @@ -38,7 +38,7 @@ class JobManager
private $registry;
private $retryScheduler;

public function __construct(ManagerRegistry $managerRegistry, EventDispatcherInterface $eventDispatcher, RetryScheduler $retryScheduler)
public function __construct(Registry $managerRegistry, EventDispatcherInterface $eventDispatcher, RetryScheduler $retryScheduler)
{
$this->registry = $managerRegistry;
$this->dispatcher = $eventDispatcher;
Expand Down Expand Up @@ -269,7 +269,7 @@ private function closeJobInternal(Job $job, $finalState, array &$visited = array

if (null !== $this->dispatcher && ($job->isRetryJob() || 0 === count($job->getRetryJobs()))) {
$event = new StateChangeEvent($job, $finalState);
$this->dispatcher->dispatch('jms_job_queue.job_state_change', $event);
$this->dispatcher->dispatch($event, 'jms_job_queue.job_state_change');
$finalState = $event->getNewState();
}

Expand Down
2 changes: 1 addition & 1 deletion Event/JobEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace JMS\JobQueueBundle\Event;

use JMS\JobQueueBundle\Entity\Job;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

abstract class JobEvent extends Event
{
Expand Down
1 change: 0 additions & 1 deletion Event/NewOutputEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
namespace JMS\JobQueueBundle\Event;

use JMS\JobQueueBundle\Entity\Job;
use JMS\JobQueueBundle\Event\JobEvent;

class NewOutputEvent extends JobEvent
{
Expand Down
1 change: 0 additions & 1 deletion Event/StateChangeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
namespace JMS\JobQueueBundle\Event;

use JMS\JobQueueBundle\Entity\Job;
use JMS\JobQueueBundle\Event\JobEvent;

class StateChangeEvent extends JobEvent
{
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Below, is a sample configuration that you can use with supervisord:
.. code-block :: ini

[program:jms_job_queue_runner]
command=php %kernel.root_dir%/console jms-job-queue:run --env=prod --verbose
command=php %kernel.project_dir%/console jms-job-queue:run --env=prod --verbose
process_name=%(program_name)s
numprocs=1
directory=/tmp
Expand Down
9 changes: 4 additions & 5 deletions Tests/Entity/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace JMS\JobQueueBundle\Tests\Entity;

use JMS\JobQueueBundle\Entity\Job;
use JMS\JobQueueBundle\Exception\InvalidStateTransitionException;
use PHPUnit\Framework\TestCase;

class JobTest extends TestCase
Expand All @@ -38,10 +39,10 @@ public function testConstruct()

/**
* @depends testConstruct
* @expectedException JMS\JobQueueBundle\Exception\InvalidStateTransitionException
*/
public function testInvalidTransition(Job $job)
{
$this->expectException(InvalidStateTransitionException::class);
$job->setState('failed');
}

Expand Down Expand Up @@ -145,12 +146,10 @@ public function testAddDependency()
$this->assertSame($b, $a->getDependencies()->first());
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage You cannot add dependencies to a job which might have been started already.
*/
public function testAddDependencyToRunningJob()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('You cannot add dependencies to a job which might have been started already.');
$job = new Job('a');
$job->setState(Job::STATE_RUNNING);
$this->setField($job, 'id', 1);
Expand Down
2 changes: 0 additions & 2 deletions Tests/Functional/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
require_once $autoloadFile;
});

\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/ConcurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testHighConcurrency()
$this->assertEquals(array('one', 'two'), $workers);
}

protected function setUp()
protected function setUp(): void
{
$this->databaseFile = tempnam(sys_get_temp_dir(), 'db');
$this->configFile = tempnam(sys_get_temp_dir(), 'di-cfg');
Expand All @@ -77,7 +77,7 @@ protected function setUp()
$this->importDatabaseSchema();
}

protected function tearDown()
protected function tearDown(): void
{
@unlink($this->databaseFile);
@unlink($this->configFile);
Expand Down
3 changes: 1 addition & 2 deletions Tests/Functional/CronTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace JMS\JobQueueBundle\Tests\Functional;

use Doctrine\ORM\EntityManager;
use JMS\JobQueueBundle\Entity\Job;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Bundle\FrameworkBundle\Console\Application;

Expand All @@ -21,7 +20,7 @@ public function testSchedulesCommands()
$this->assertEquals(2, substr_count($output, 'Scheduling command scheduled-every-few-seconds'), $output);
}

protected function setUp()
protected function setUp(): void
{
$this->createClient(array('config' => 'persistent_db.yml'));

Expand Down
Loading