Skip to content

Commit

Permalink
Add command send-test-mail
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Dec 18, 2023
1 parent 6641c6b commit 0768366
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 15 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:

steps:
- name: "Checkout"
uses: actions/checkout@master
uses: actions/checkout@v4

- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
with:
coverage: none
extensions: mbstring
php-version: 8.1
php-version: 8.3

- name: "Validate composer.json and composer.lock"
run: composer validate --strict
Expand All @@ -39,7 +39,7 @@ jobs:

steps:
- name: "Checkout"
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

Expand All @@ -48,7 +48,7 @@ jobs:
with:
coverage: none
extensions: mbstring
php-version: 8.1
php-version: 8.3

- name: "Install locked dependencies with composer"
run: composer install --no-interaction --no-progress --no-suggest
Expand All @@ -68,7 +68,7 @@ jobs:

steps:
- name: "Checkout"
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

Expand All @@ -77,7 +77,7 @@ jobs:
with:
coverage: none
extensions: mbstring
php-version: 8.1
php-version: 8.3

- name: "Install dependencies with composer"
run: composer install --no-interaction --no-progress --no-suggest
Expand All @@ -100,12 +100,13 @@ jobs:
php-version:
- "8.1"
- "8.2"
- "8.3"
laravel-version:
- ^9.51
- ^10

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
Expand All @@ -131,6 +132,7 @@ jobs:
php-version:
- "8.1"
- "8.2"
- "8.3"
dependencies:
- lowest
- highest
Expand All @@ -150,7 +152,7 @@ jobs:

steps:
- name: "Checkout"
uses: actions/checkout@master
uses: actions/checkout@v4

- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -190,14 +192,14 @@ jobs:

steps:
- name: "Checkout"
uses: actions/checkout@master
uses: actions/checkout@v4

- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
with:
coverage: pcov
extensions: mbstring
php-version: 8.1
php-version: 8.3

- name: "Install dependencies with composer"
run: composer install --no-interaction --no-progress --no-suggest
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"ergebnis/composer-normalize": "^2",
"jangregor/phpstan-prophecy": "^1",
"jbzoo/mermaid-php": "^2.3",
"larastan/larastan": "^2",
"laravel/framework": "^9 || ^10",
"mll-lab/graphql-php-scalars": "^4 || ^5",
"mll-lab/php-cs-fixer-config": "^5",
"mll-lab/rector-config": "^2",
"nunomaduro/larastan": "^2",
"orchestra/testbench": "^7.7 || ^8",
"phpstan/extension-installer": "^1",
"phpstan/phpstan-deprecation-rules": "^1",
Expand All @@ -60,9 +60,9 @@
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"ocramius/package-versions": true,
"phpstan/extension-installer": true,
"ergebnis/composer-normalize": true
"phpstan/extension-installer": true
},
"preferred-install": "dist",
"sort-packages": true
Expand All @@ -72,6 +72,7 @@
"providers": [
"MLL\\LaravelUtils\\LaravelUtilsServiceProvider",
"MLL\\LaravelUtils\\Database\\DatabaseServiceProvider",
"MLL\\LaravelUtils\\Mail\\MailServiceProvider",
"MLL\\LaravelUtils\\ModelStates\\ModelStatesServiceProvider"
]
}
Expand Down
2 changes: 1 addition & 1 deletion php.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1-cli
FROM php:8.3-cli

WORKDIR /workdir

Expand Down
15 changes: 15 additions & 0 deletions src/Mail/MailServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

namespace MLL\LaravelUtils\Mail;

use Illuminate\Support\ServiceProvider;

class MailServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->commands([
SendTestMailCommand::class,
]);
}
}
22 changes: 22 additions & 0 deletions src/Mail/SendTestMailCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace MLL\LaravelUtils\Mail;

use Illuminate\Console\Command;
use Illuminate\Mail\Message;
use Illuminate\Mail\PendingMail;
use Illuminate\Support\Facades\Mail;

class SendTestMailCommand extends Command
{
protected $signature = '
send-test-mail
{--to= : Recipient}
';

public function handle(): void
{
Mail::to($this->option('to'))
->send(new TestMail());
}
}
15 changes: 15 additions & 0 deletions src/Mail/TestMail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace MLL\LaravelUtils\Mail;

use Illuminate\Mail\Mailable;

class TestMail extends Mailable
{
/** @return $this */
public function build(): self
{
return $this->subject('This is a test mail sent by php artisan send-test-mail')
->html(/** @lang HTML */ "<p>This is a test mail sent by php artisan send-test-mail</p>");
}
}
29 changes: 29 additions & 0 deletions tests/Mail/SendTestMailCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);

namespace MLL\LaravelUtils\Tests\Mail;

use Illuminate\Support\Facades\Mail;
use MLL\LaravelUtils\Mail\TestMail;
use MLL\LaravelUtils\Tests\TestCase;

final class SendTestMailCommandTest extends TestCase
{
public function testSendsTestMail(): void
{
Mail::fake();

$to = '[email protected]';

$this->artisan('send-test-mail', [
'--to' => $to,
]);

$sent = Mail::sent(TestMail::class);

$this->assertCount(1, $sent);

Check failure on line 23 in tests/Mail/SendTestMailCommandTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9.51

Dynamic call to static method PHPUnit\Framework\Assert::assertCount().

Check failure on line 23 in tests/Mail/SendTestMailCommandTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10

Dynamic call to static method PHPUnit\Framework\Assert::assertCount().

Check failure on line 23 in tests/Mail/SendTestMailCommandTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9.51

Dynamic call to static method PHPUnit\Framework\Assert::assertCount().

Check failure on line 23 in tests/Mail/SendTestMailCommandTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10

Dynamic call to static method PHPUnit\Framework\Assert::assertCount().

Check failure on line 23 in tests/Mail/SendTestMailCommandTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.3 with Laravel ^9.51

Dynamic call to static method PHPUnit\Framework\Assert::assertCount().

Check failure on line 23 in tests/Mail/SendTestMailCommandTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.3 with Laravel ^10

Dynamic call to static method PHPUnit\Framework\Assert::assertCount().

$testMail = $sent->firstOrFail();
assert($testMail instanceof TestMail);
$testMail->assertTo($to);
}
}
2 changes: 1 addition & 1 deletion tests/ModelStates/StateTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace MLL\LaravelUtils\ModelStates\Tests;
namespace MLL\LaravelUtils\Tests\ModelStates;

use App\ModelStates\ModelStates\StateA;
use App\ModelStates\ModelStates\StateB;
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MLL\LaravelUtils\Tests;

use MLL\LaravelUtils\LaravelUtilsServiceProvider;
use MLL\LaravelUtils\Mail\MailServiceProvider;
use Orchestra\Testbench\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
Expand All @@ -20,6 +21,7 @@ protected function getPackageProviders($app): array
{
return [
LaravelUtilsServiceProvider::class,
MailServiceProvider::class,
];
}
}

0 comments on commit 0768366

Please sign in to comment.