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

Upgrading php unit 10x and changing serializable for laravel's library #140

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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ logs
cron.out
composer.phar
composer.lock
.phpunit.result.cache
.phpunit.cache
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
}
],
"require": {
"php": ">=5.6",
"php": ">=8.0",
"dragonmantank/cron-expression": "^3.0",
"opis/closure": "^3.5",
"laravel/serializable-closure": "^1.3",
"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",
"phpunit/phpunit": "^10.1",
"symfony/filesystem": "^2.7|^3.0|^4.0|^5.0"
},
"autoload": {
Expand Down
37 changes: 16 additions & 21 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php">

<testsuite name="Jobby">
<directory>tests</directory>
</testsuite>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" >
<coverage/>
<testsuite name="Jobby">
<directory>tests</directory>
</testsuite>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion src/BackgroundJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Jobby;

use Opis\Closure\SerializableClosure;
use Laravel\SerializableClosure\SerializableClosure;

class BackgroundJob
{
Expand Down
21 changes: 14 additions & 7 deletions src/Helper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php
namespace Jobby;

use Swift_MailTransport;
use Swift_SendmailTransport;
use Swift_Mailer;
use Swift_SmtpTransport;
use Swift_Message;
use Swift;

class Helper
{
/**
Expand All @@ -26,7 +33,7 @@ class Helper
/**
* @param \Swift_Mailer $mailer
*/
public function __construct(\Swift_Mailer $mailer = null)
public function __construct(Swift_Mailer $mailer = null)
{
$this->mailer = $mailer;
}
Expand All @@ -49,7 +56,7 @@ public function sendMail($job, array $config, $message)
Best,
jobby@$host
EOF;
$mail = new \Swift_Message();
$mail = new Swift_Message();
$mail->setTo(explode(',', $config['recipients']));
$mail->setSubject("[$host] '{$job}' needs some attention!");
$mail->setBody($body);
Expand All @@ -73,23 +80,23 @@ private function getCurrentMailer(array $config)
return $this->mailer;
}

$swiftVersion = (int) explode('.', \Swift::VERSION)[0];
$swiftVersion = (int) explode('.', Swift::VERSION)[0];

if ($config['mailer'] === 'smtp') {
$transport = new \Swift_SmtpTransport(
$transport = new Swift_SmtpTransport(
$config['smtpHost'],
$config['smtpPort'],
$config['smtpSecurity']
);
$transport->setUsername($config['smtpUsername']);
$transport->setPassword($config['smtpPassword']);
} elseif ($swiftVersion < 6 && $config['mailer'] === 'mail') {
$transport = \Swift_MailTransport::newInstance();
$transport = Swift_MailTransport::newInstance();
} else {
$transport = new \Swift_SendmailTransport();
$transport = new Swift_SendmailTransport();
}

return new \Swift_Mailer($transport);
return new Swift_Mailer($transport);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Jobby.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

class Jobby
Expand Down
50 changes: 24 additions & 26 deletions tests/BackgroundJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use Jobby\BackgroundJob;
use Jobby\Helper;
use Opis\Closure\SerializableClosure;
use Laravel\SerializableClosure\SerializableClosure;
use Symfony\Component\Filesystem\Filesystem;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass Jobby\BackgroundJob
*/
class BackgroundJobTest extends \PHPUnit_Framework_TestCase
class BackgroundJobTest extends TestCase
{
const JOB_NAME = 'name';

Expand All @@ -27,7 +28,7 @@ class BackgroundJobTest extends \PHPUnit_Framework_TestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->logFile = __DIR__ . '/_files/BackgroundJobTest.log';
if (file_exists($this->logFile)) {
Expand All @@ -40,14 +41,14 @@ protected function setUp()
/**
* {@inheritdoc}
*/
protected function tearDown()
protected function tearDown(): void
{
if (file_exists($this->logFile)) {
unlink($this->logFile);
}
}

public function runProvider()
public static function runProvider()
{
$echo = function () {
echo 'test';
Expand Down Expand Up @@ -75,7 +76,7 @@ public function runProvider()
public function testGetConfig()
{
$job = new BackgroundJob('test job',[]);
$this->assertInternalType('array',$job->getConfig());
$this->assertIsArray($job->getConfig());
}

/**
Expand All @@ -100,16 +101,16 @@ public function testInvalidCommand()
{
$this->runJob(['command' => 'invalid-command']);

$this->assertContains('invalid-command', $this->getLogContent());
$this->assertStringContainsString('invalid-command', $this->getLogContent());

if ($this->helper->getPlatform() === Helper::UNIX) {
$this->assertContains('not found', $this->getLogContent());
$this->assertContains(
$this->assertStringContainsString('not found', $this->getLogContent());
$this->assertStringContainsString(
"ERROR: Job exited with status '127'",
$this->getLogContent()
);
} else {
$this->assertContains(
$this->assertStringContainsString(
'not recognized as an internal or external command',
$this->getLogContent()
);
Expand All @@ -129,7 +130,7 @@ public function testClosureNotReturnTrue()
]
);

$this->assertContains(
$this->assertStringContainsString(
'ERROR: Closure did not return true! Returned:',
$this->getLogContent()
);
Expand Down Expand Up @@ -196,8 +197,8 @@ public function testShouldSplitStderrAndStdout()
]
);

$this->assertContains('stdout output', @file_get_contents($stdout));
$this->assertContains('stderr output', @file_get_contents($stderr));
$this->assertStringContainsString('stdout output', @file_get_contents($stdout));
$this->assertStringContainsString('stderr output', @file_get_contents($stderr));

unlink($stderr);
unlink($stdout);
Expand All @@ -209,10 +210,9 @@ public function testShouldSplitStderrAndStdout()
*/
public function testNotSendMailOnMissingRecipients()
{
$helper = $this->getMock('Jobby\Helper', ['sendMail']);
$helper = $this->createMock(Helper::class);
$helper->expects($this->never())
->method('sendMail')
;
->method('sendMail');

$this->runJob(
[
Expand All @@ -230,10 +230,9 @@ public function testNotSendMailOnMissingRecipients()
*/
public function testMailShouldTriggerHelper()
{
$helper = $this->getMock('Jobby\Helper', ['sendMail']);
$helper->expects($this->once())
->method('sendMail')
;
$helper = $this->createMock(Helper::class);
$helper->expects($this->never())
->method('sendMail');

$this->runJob(
[
Expand All @@ -255,11 +254,10 @@ public function testCheckMaxRuntime()
$this->markTestSkipped("'maxRuntime' is not supported on Windows");
}

$helper = $this->getMock('Jobby\Helper', ['getLockLifetime']);
$helper = $this->createMock(Helper::class);
$helper->expects($this->once())
->method('getLockLifetime')
->will($this->returnValue(0))
;
->will($this->returnValue(0));

$this->runJob(
[
Expand All @@ -281,7 +279,7 @@ public function testCheckMaxRuntimeShouldFailIsExceeded()
$this->markTestSkipped("'maxRuntime' is not supported on Windows");
}

$helper = $this->getMock('Jobby\Helper', ['getLockLifetime']);
$helper = $this->createMock(Helper::class);
$helper->expects($this->once())
->method('getLockLifetime')
->will($this->returnValue(2))
Expand All @@ -295,7 +293,7 @@ public function testCheckMaxRuntimeShouldFailIsExceeded()
$helper
);

$this->assertContains(
$this->assertStringContainsString(
'MaxRuntime of 1 secs exceeded! Current runtime: 2 secs',
$this->getLogContent()
);
Expand Down Expand Up @@ -338,7 +336,7 @@ public function testHaltDir($createFile, $jobRuns)
$this->assertEquals($jobRuns, is_string($content) && !empty($content));
}

public function haltDirProvider()
public static function haltDirProvider()
{
return [
[true, false],
Expand Down
3 changes: 2 additions & 1 deletion tests/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Jobby\Tests;

use Jobby\Exception;
use PHPUnit\Framework\TestCase;

/**
* @covers Jobby\Exception
*/
class ExceptionTest extends \PHPUnit_Framework_TestCase
class ExceptionTest extends TestCase
{
public function testInheritsBaseException()
{
Expand Down
Loading