Skip to content

Commit b6abe6f

Browse files
authored
Merge pull request #26 from dotkernel/issue-25
Issue #25: Tests to improve code coverage
2 parents 56a9939 + aae880f commit b6abe6f

25 files changed

+1094
-26
lines changed

.github/workflows/codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
uses: shivammathur/setup-php@v2
2727
with:
2828
php-version: "${{ matrix.php }}"
29+
extensions: swoole
2930
coverage: pcov
3031
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
3132
tools: composer:v2, cs2pr

.laminas-ci.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"additional_composer_arguments": [
3-
"--no-scripts",
4-
"--no-plugins"
3+
"--no-scripts"
4+
],
5+
"extensions": [
6+
"redis"
57
],
68
"ignore_php_platform_requirements": {
79
}
8-
}
10+
}

.laminas-ci/pre-run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#!/bin/bash
1+
JOB=$3
2+
PHP_VERSION=$(echo "${JOB}" | jq -r '.php')
23

3-
# Due to the fact that we are disabling plugins when installing/updating/downgrading composer dependencies
4-
# we have to manually enable the coding standard here.
5-
composer enable-codestandard
4+
apt update
5+
apt install -y "php${PHP_VERSION}-swoole"

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
},
8585
"autoload-dev": {
8686
"psr-4": {
87-
"DotTest\\Mail\\": "test/"
87+
"QueueTest\\App\\": "test/App/",
88+
"QueueTest\\Swoole\\": "test/Swoole/"
8889
}
8990
},
9091
"scripts": {

config/autoload/log.local.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ return [
1010
'writers' => [
1111
'FileWriter' => [
1212
'name' => 'stream',
13-
'level' => \Dot\Log\Logger::ALERT, // this is equal to 1
13+
'priority' => \Dot\Log\Logger::ALERT, // this is equal to 1
1414
'options' => [
1515
'stream' => __DIR__ . '/../../log/queue-log.log',
1616
'formatter' => [

config/autoload/mail.global.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
/**
7+
* Dotkernel mail module configuration
8+
* Note that many of these options can be set programmatically too, when sending mail messages actually that is
9+
* what you'll usually do, these configs provide just defaults and options that remain the same for all mails
10+
*/
11+
'dot_mail' => [
12+
//the key is the mail service name, this is the default one, which does not extend any configuration
13+
'default' => [
14+
//message configuration
15+
'message_options' => [
16+
//from email address of the email
17+
'from' => '',
18+
//from name to be displayed instead of from address
19+
'from_name' => '',
20+
//reply-to email address of the email
21+
'reply_to' => '',
22+
//replyTo name to be displayed instead of the address
23+
'reply_to_name' => '',
24+
//destination email address as string or a list of email addresses
25+
'to' => [],
26+
//copy destination addresses
27+
'cc' => [],
28+
//hidden copy destination addresses
29+
'bcc' => [],
30+
//email subject
31+
'subject' => '',
32+
//body options - content can be plain text, HTML
33+
'body' => [
34+
'content' => '',
35+
'charset' => 'utf-8',
36+
],
37+
//attachments config
38+
'attachments' => [
39+
'files' => [],
40+
'dir' => [
41+
'iterate' => false,
42+
'path' => 'data/mail/attachments',
43+
'recursive' => false,
44+
],
45+
],
46+
],
47+
/**
48+
* the mail transport to use can be any class implementing
49+
* Symfony\Component\Mailer\Transport\TransportInterface
50+
*
51+
* for standard mail transports, you can use these aliases:
52+
* - sendmail => Symfony\Component\Mailer\Transport\SendmailTransport
53+
* - esmtp => Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport
54+
*
55+
* defaults to sendmail
56+
**/
57+
'transport' => 'sendmail',
58+
//options that will be used only if esmtp adapter is used
59+
'smtp_options' => [
60+
//hostname or IP address of the mail server
61+
'host' => '',
62+
//port of the mail server - 587 or 465 for secure connections
63+
'port' => 587,
64+
'connection_config' => [
65+
//the smtp authentication identity
66+
'username' => '',
67+
//the smtp authentication credential
68+
'password' => '',
69+
/**
70+
* tls will run by default on this component, use:
71+
*
72+
* null - to avoid interfering with automatic encryption
73+
* false - to disable automatic encryption
74+
*
75+
* It's not recommended to disable TLS while connecting to an SMTP server over the Internet
76+
**/
77+
'tls' => null,
78+
],
79+
],
80+
],
81+
// option to log the SENT emails
82+
'log' => [
83+
'sent' => getcwd() . '/log/mail/sent.log',
84+
],
85+
],
86+
];

src/App/ConfigProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Netglue\PsrContainer\Messenger\Container\Middleware\MessageHandlerMiddlewareStaticFactory;
1111
use Netglue\PsrContainer\Messenger\Container\Middleware\MessageSenderMiddlewareStaticFactory;
1212
use Netglue\PsrContainer\Messenger\HandlerLocator\OneToManyFqcnContainerHandlerLocator;
13-
use Queue\App\Message\ExampleMessage;
14-
use Queue\App\Message\ExampleMessageHandler;
13+
use Queue\App\Message\Message;
14+
use Queue\App\Message\MessageHandler;
1515
use Symfony\Component\Messenger\MessageBusInterface;
1616

1717
class ConfigProvider
@@ -37,7 +37,7 @@ private function getDependencies(): array
3737
"message_bus_stamp_middleware" => [BusNameStampMiddlewareStaticFactory::class, "message_bus"],
3838
"message_bus_sender_middleware" => [MessageSenderMiddlewareStaticFactory::class, "message_bus"],
3939
"message_bus_handler_middleware" => [MessageHandlerMiddlewareStaticFactory::class, "message_bus"],
40-
ExampleMessageHandler::class => AttributedServiceFactory::class,
40+
MessageHandler::class => AttributedServiceFactory::class,
4141
],
4242
"aliases" => [
4343
MessageBusInterface::class => "message_bus",
@@ -81,7 +81,7 @@ private function busConfig(): array
8181
*/
8282
'handler_locator' => OneToManyFqcnContainerHandlerLocator::class,
8383
'handlers' => [
84-
ExampleMessage::class => [ExampleMessageHandler::class],
84+
Message::class => [MessageHandler::class],
8585
],
8686

8787
/**
@@ -97,7 +97,7 @@ private function busConfig(): array
9797
* Route specific messages to specific transports by using the message name as the key.
9898
*/
9999
'routes' => [
100-
ExampleMessage::class => ["redis_transport"],
100+
Message::class => ["redis_transport"],
101101
],
102102
],
103103
];
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Queue\App\Message;
66

7-
class ExampleMessage
7+
class Message
88
{
99
public function __construct(
1010
private array $payload,
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use function json_decode;
1717

18-
class ExampleMessageHandler
18+
class MessageHandler
1919
{
2020
protected array $args = [];
2121

@@ -35,18 +35,19 @@ public function __construct(
3535
) {
3636
}
3737

38-
public function __invoke(ExampleMessage $message): void
38+
public function __invoke(Message $message): void
3939
{
4040
$payload = json_decode($message->getPayload()['foo'], true);
4141

4242
if ($payload !== null && isset($payload['userUuid'])) {
4343
$this->logger->info("message: " . $payload['userUuid']);
4444
$this->args = $payload;
45-
}
4645

47-
try {
48-
$this->perform();
49-
} catch (Exception $exception) {
46+
try {
47+
$this->perform();
48+
} catch (Exception $exception) {
49+
$this->logger->err("message: " . $exception->getMessage());
50+
}
5051
}
5152
}
5253

@@ -64,7 +65,7 @@ public function perform(): void
6465
public function sendWelcomeMail(): bool
6566
{
6667
$user = $this->userRepository->find($this->args['userUuid']);
67-
$this->mailService->getMessage()->addTo('[email protected]', 'sergiu');
68+
$this->mailService->getMessage()->addTo($user->getEmail(), $user->getName());
6869
$this->mailService->setSubject('Welcome to ' . $this->config['application']['name']);
6970
$body = $this->templateRenderer->render('notification-email::welcome', [
7071
'user' => $user,

src/Swoole/Delegators/TCPServerDelegator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Queue\Swoole\Delegators;
66

77
use Psr\Container\ContainerInterface;
8-
use Queue\App\Message\ExampleMessage;
8+
use Queue\App\Message\Message;
99
use Swoole\Server as TCPSwooleServer;
1010
use Symfony\Component\Messenger\MessageBusInterface;
1111
use Symfony\Component\Messenger\Stamp\DelayStamp;
@@ -28,8 +28,8 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal
2828

2929
// Register the function for the event `receive`
3030
$server->on('receive', function ($server, $fd, $fromId, $data) use ($logger, $bus) {
31-
$bus->dispatch(new ExampleMessage(["foo" => $data]));
32-
$bus->dispatch(new ExampleMessage(["foo" => "with 5 seconds delay"]), [
31+
$bus->dispatch(new Message(["foo" => $data]));
32+
$bus->dispatch(new Message(["foo" => "with 5 seconds delay"]), [
3333
new DelayStamp(5000),
3434
]);
3535

0 commit comments

Comments
 (0)