Skip to content

Commit

Permalink
Merge pull request #129 from jobbyphp/closure
Browse files Browse the repository at this point in the history
replace: jeremeamia/superclosure with opis/closure
  • Loading branch information
darkalchemy committed Jul 25, 2020
2 parents e57e905 + 39cbad6 commit a419850
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 59 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
"require": {
"php": ">=5.6",
"dragonmantank/cron-expression": "^3.0",
"jeremeamia/superclosure": "^2.2",
"opis/closure": "^3.5",
"swiftmailer/swiftmailer": "^5.4|^6.0",
"symfony/process": "^2.7|^3.0|^4.0|^5.0"
},
"require-dev": {
"mp091689/dump-die": "^1.0",
"phpunit/phpunit": "^4.6",
"symfony/filesystem": "^2.7|^3.0|^4.0|^5.0"
},
Expand Down
6 changes: 3 additions & 3 deletions src/BackgroundJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Jobby;

use Opis\Closure\SerializableClosure;

class BackgroundJob
{
use SerializerTrait;

/**
* @var Helper
*/
Expand Down Expand Up @@ -233,7 +233,7 @@ protected function log($message, $output = 'stdout')

protected function runFunction()
{
$command = $this->getSerializer()->unserialize($this->config['closure']);
$command = unserialize($this->config['closure']);

ob_start();
try {
Expand Down
7 changes: 3 additions & 4 deletions src/Jobby.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

use Closure;
use DateTimeImmutable;
use SuperClosure\SerializableClosure;
use Opis\Closure\SerializableClosure;
use Symfony\Component\Process\PhpExecutableFinder;

class Jobby
{
use SerializerTrait;

/**
* @var array
*/
Expand Down Expand Up @@ -207,7 +205,8 @@ protected function runWindows($job, array $config)
protected function getExecutableCommand($job, array $config)
{
if (isset($config['closure'])) {
$config['closure'] = $this->getSerializer()->serialize($config['closure']);
$wrapper = new SerializableClosure($config['closure']);
$config['closure'] = serialize($wrapper);
}

if (strpos(__DIR__, 'phar://') === 0) {
Expand Down
25 changes: 0 additions & 25 deletions src/SerializerTrait.php

This file was deleted.

7 changes: 3 additions & 4 deletions tests/BackgroundJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

use Jobby\BackgroundJob;
use Jobby\Helper;
use Jobby\SerializerTrait;
use Opis\Closure\SerializableClosure;
use Symfony\Component\Filesystem\Filesystem;

/**
* @coversDefaultClass Jobby\BackgroundJob
*/
class BackgroundJobTest extends \PHPUnit_Framework_TestCase
{
use SerializerTrait;

const JOB_NAME = 'name';

/**
Expand Down Expand Up @@ -370,7 +368,8 @@ private function getJobConfig(array $config)
$helper = new Helper();

if (isset($config['closure'])) {
$config['closure'] = $this->getSerializer()->serialize($config['closure']);
$wrapper = new SerializableClosure($config['closure']);
$config['closure'] = serialize($wrapper);
}

return array_merge(
Expand Down
11 changes: 8 additions & 3 deletions tests/JobbyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Jobby\Helper;
use Jobby\Jobby;
use SuperClosure\SerializableClosure;
use Opis\Closure\SerializableClosure;

/**
* @coversDefaultClass Jobby\Jobby
Expand Down Expand Up @@ -97,7 +97,7 @@ public function testBackgroundProcessIsNotSpawnedIfJobIsNotDueToBeRun()
* @covers ::add
* @covers ::run
*/
public function testSuperClosure()
public function testOpisClosure()
{
$fn = static function () {
echo 'Another function!';
Expand All @@ -106,10 +106,15 @@ public function testSuperClosure()
};

$jobby = new Jobby();
$wrapper = new SerializableClosure($fn);
$serialized = serialize($wrapper);
$wrapper = unserialize($serialized);
$closure = $wrapper->getClosure();

$jobby->add(
'HelloWorldClosure',
[
'command' => new SerializableClosure($fn),
'command' => $closure,
'schedule' => '* * * * *',
'output' => $this->logFile,
]
Expand Down
19 changes: 0 additions & 19 deletions tests/SerializerTraitTest.php

This file was deleted.

0 comments on commit a419850

Please sign in to comment.