Skip to content

Commit

Permalink
Cake 5.0 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
gerd committed Jan 2, 2024
1 parent 5fdcd08 commit 8a521d6
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ app/[Cc]onfig/database.php
!empty
vendor/*
*.lock
.phpunit.result.cache
.phpunit.cache
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"port": 9003,
"pathMappings": {
"/ws": "${workspaceFolder}"
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CakePHP-Mailqueue-Plugin
[![Coverage Status](https://coveralls.io/repos/github/hakito/CakePHP-Mailqueue-Plugin/badge.svg?branch=master)](https://coveralls.io/github/hakito/CakePHP-Mailqueue-Plugin?branch=master)
[![Latest Stable Version](https://poser.pugx.org/hakito/cakephp-mailqueue-plugin/v/stable.svg)](https://packagist.org/packages/hakito/cakephp-mailqueue-plugin) [![Total Downloads](https://poser.pugx.org/hakito/cakephp-mailqueue-plugin/downloads.svg)](https://packagist.org/packages/hakito/cakephp-mailqueue-plugin) [![Latest Unstable Version](https://poser.pugx.org/hakito/cakephp-mailqueue-plugin/v/unstable.svg)](https://packagist.org/packages/hakito/cakephp-mailqueue-plugin) [![License](https://poser.pugx.org/hakito/cakephp-mailqueue-plugin/license.svg)](https://packagist.org/packages/hakito/cakephp-mailqueue-plugin)

CakePHP 4.x plugin to store mail in a queue for later sendout.
CakePHP 5.x plugin to store mail in a queue for later sendout.

When working with emails on a webservice sending email blocks the http request until the email is actually sent out. This can be frustrating for a user especially if the smtp server does not respond promptly.

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
}
},
"require": {
"cakephp/cakephp": "^4.0"
"cakephp/cakephp": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5"
"phpunit/phpunit": "^10.0"
},
"extra": {
"installer-name": "MailQueue"
Expand Down
29 changes: 12 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="tests/bootstrap.php"
colors="true"
>

<testsuites>
<testsuite name="MailQueue">
<directory>tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="MailQueue">
<directory>tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/Mailer/Transport/FlushException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace MailQueue\Mailer\Transport;

class FlushException extends \Cake\Core\Exception\Exception
class FlushException extends \Cake\Core\Exception\CakeException
{

protected $_messageTemplate = 'Could not get a lock for %s';
protected string $_messageTemplate = 'Could not get a lock for %s';

}
2 changes: 1 addition & 1 deletion src/Mailer/Transport/QueueFileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MailQueue\Mailer\Transport;

class QueueFileException extends \Cake\Core\Exception\Exception
class QueueFileException extends \Cake\Core\Exception\CakeException
{

protected $_messageTemplate = 'File %s could not be locked for queueing.';
Expand Down
8 changes: 4 additions & 4 deletions src/Mailer/Transport/QueueTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function send(Message $message): array
if (flock($fh, LOCK_EX))
{
$persistableMail = new PersistableMessage($message);
$serialized = $persistableMail->serialize();
$serialized = serialize($persistableMail->jsonSerialize());
fwrite($fh, $serialized);
chmod($filename, 0666);
flock($fh, LOCK_UN);
Expand All @@ -40,7 +40,7 @@ public function send(Message $message): array

/**
* Sendout mail queue using the given real mailer
* @param Cake\Mailer\AbstractTransport $realTransport
* @param AbstractTransport $realTransport
*/
public function flush(AbstractTransport $realTransport, bool $noBlock = false)
{
Expand Down Expand Up @@ -68,7 +68,7 @@ public function flush(AbstractTransport $realTransport, bool $noBlock = false)
{
$serialized = fread($fh, filesize($queueFile));
$message = new PersistableMessage();
$message->unserialize($serialized);
$message->createFromArray(unserialize($serialized));

$delFile = $this->tryRealSend($realTransport, $message);
if ($delFile === false)
Expand Down Expand Up @@ -117,7 +117,7 @@ private function tryRequeue($queueFile)

/**
* Trys to do the real sendout. In case of a SockeException the mail will
* @param Cake\Mailer\AbstractTransport $realTransport
* @param AbstractTransport $realTransport
* @param PersistableMessage $message queued mail
* @return boolean true on success
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Mailer/Transport/QueueTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use RecursiveIteratorIterator;

/**
* @property \Cake\Mailer\Email email
* @property \Cake\Mailer\Mailer email
*/
class QueueTransportTest extends TestCase
{
Expand All @@ -23,7 +23,7 @@ public function setUp(): void
$this->mailer = new Mailer('default');
$this->config = $this->mailer->getTransport()->getConfig(null);
$this->mTransport = $this->getMockBuilder(\Cake\Mailer\AbstractTransport::class)
->setMethods(['send'])
->onlyMethods(['send'])
->getMock();
}

Expand Down
5 changes: 3 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* and define the data required by your plugin here.
*/
require_once join(DS, [CORE_PATH, 'config', 'bootstrap.php']);
require CAKE . 'functions.php';

use Cake\Cache\Cache;
use Cake\Core\Configure;
Expand All @@ -50,8 +51,8 @@
Configure::load('MailQueue', 'default', false);
Cache::setConfig(Configure::consume('Cache'));

use Cake\Mailer\Email;
use Cake\Mailer\Mailer;
use Cake\Mailer\TransportFactory;

TransportFactory::setConfig(Configure::consume('EmailTransport'));
Email::setConfig(Configure::consume('Email'));
Mailer::setConfig(Configure::consume('Email'));

0 comments on commit 8a521d6

Please sign in to comment.