From 39cbad62fb97d87a4204a525b517dfddb403610a Mon Sep 17 00:00:00 2001 From: darkalchemy Date: Fri, 17 Jul 2020 17:58:52 -0400 Subject: [PATCH] replace: jeremeamia/superclosure with opis/closure --- composer.json | 3 ++- src/BackgroundJob.php | 6 +++--- src/Jobby.php | 7 +++---- src/SerializerTrait.php | 25 ------------------------- tests/BackgroundJobTest.php | 7 +++---- tests/JobbyTest.php | 11 ++++++++--- tests/SerializerTraitTest.php | 19 ------------------- 7 files changed, 19 insertions(+), 59 deletions(-) delete mode 100644 src/SerializerTrait.php delete mode 100644 tests/SerializerTraitTest.php diff --git a/composer.json b/composer.json index 5d96f38..326e27b 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/src/BackgroundJob.php b/src/BackgroundJob.php index ea754f6..c339747 100644 --- a/src/BackgroundJob.php +++ b/src/BackgroundJob.php @@ -2,10 +2,10 @@ namespace Jobby; +use Opis\Closure\SerializableClosure; + class BackgroundJob { - use SerializerTrait; - /** * @var Helper */ @@ -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 { diff --git a/src/Jobby.php b/src/Jobby.php index 53858af..821f8c6 100644 --- a/src/Jobby.php +++ b/src/Jobby.php @@ -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 */ @@ -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) { diff --git a/src/SerializerTrait.php b/src/SerializerTrait.php deleted file mode 100644 index a763c84..0000000 --- a/src/SerializerTrait.php +++ /dev/null @@ -1,25 +0,0 @@ -serializer === null) { - $this->serializer = new Serializer(); - } - - return $this->serializer; - } -} diff --git a/tests/BackgroundJobTest.php b/tests/BackgroundJobTest.php index ff54183..4f23482 100644 --- a/tests/BackgroundJobTest.php +++ b/tests/BackgroundJobTest.php @@ -4,7 +4,7 @@ use Jobby\BackgroundJob; use Jobby\Helper; -use Jobby\SerializerTrait; +use Opis\Closure\SerializableClosure; use Symfony\Component\Filesystem\Filesystem; /** @@ -12,8 +12,6 @@ */ class BackgroundJobTest extends \PHPUnit_Framework_TestCase { - use SerializerTrait; - const JOB_NAME = 'name'; /** @@ -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( diff --git a/tests/JobbyTest.php b/tests/JobbyTest.php index 9218ee7..9891942 100644 --- a/tests/JobbyTest.php +++ b/tests/JobbyTest.php @@ -4,7 +4,7 @@ use Jobby\Helper; use Jobby\Jobby; -use SuperClosure\SerializableClosure; +use Opis\Closure\SerializableClosure; /** * @coversDefaultClass Jobby\Jobby @@ -97,7 +97,7 @@ public function testBackgroundProcessIsNotSpawnedIfJobIsNotDueToBeRun() * @covers ::add * @covers ::run */ - public function testSuperClosure() + public function testOpisClosure() { $fn = static function () { echo 'Another function!'; @@ -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, ] diff --git a/tests/SerializerTraitTest.php b/tests/SerializerTraitTest.php deleted file mode 100644 index 0951fb6..0000000 --- a/tests/SerializerTraitTest.php +++ /dev/null @@ -1,19 +0,0 @@ -getObjectForTrait('Jobby\SerializerTrait'); - $method = new \ReflectionMethod($mock, 'getSerializer'); - $method->setAccessible(true); - - $serializer = $method->invoke($mock); - $this->assertInstanceOf('\SuperClosure\Serializer', $serializer); - - $serializer2 = $method->invoke($mock); - $this->assertSame($serializer, $serializer2); - } -}