Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #29 from spaantje/add-tests
Browse files Browse the repository at this point in the history
Add tests, Github Workflow and drop support for EOL Laravel Versions
  • Loading branch information
spaantje authored Dec 15, 2021
2 parents 9c56f32 + 8f90226 commit 4d6c7e7
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 8 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: run-tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [7.3, 7.4, 8.0]
laravel: [6.*, 8.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 6.*
testbench: ^4.14
- laravel: 8.*
testbench: ^6.20

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.phar
composer.lock
.DS_Store
.phpunit.result.cache
4 changes: 4 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
preset: laravel

disabled:
- single_class_element_per_statement
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ Laravel Email Database Log can be installed via [composer](http://getcomposer.or
```bash
composer require shvetsgroup/laravel-email-database-log
```
for publish migration files
```bash
php artisan vendor:publish --tag=laravel-email-database-log-migration
php artisan migrate
```

## Step 2: Configuration

Expand All @@ -30,8 +25,12 @@ You can skip this step if your version of Laravel is 5.5 or above. Otherwise, yo

## Step 3: Migration

Now, run this in terminal:
Publish migration files:
```bash
php artisan vendor:publish --tag=laravel-email-database-log-migration
```

Now, run this in terminal:
```bash
php artisan migrate
```
Expand Down
25 changes: 23 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
{
"name": "shvetsgroup/laravel-email-database-log",
"description": "A simple database logger for all outgoing emails sent by Laravel website.",
"keywords": ["laravel", "markdown"],
"keywords": ["laravel", "markdown", "mail"],
"license": "MIT",
"authors": [
{
"name": "Alexander Shvets",
"email": "neochief@shvetsgroup.com"
},
{
"name": "Spaan Productions",
"email": "info@spaanproductions.nl",
"role": "Developer"
}
],
"require": {
"illuminate/support": "~5.0|~6.0|~7.0|~8.0",
"illuminate/support": "~6.0|~8.0",
"doctrine/dbal": "^2.10"
},
"require-dev": {
"orchestra/testbench": "^4.0|^6.0",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-0": {
"ShvetsGroup\\LaravelEmailDatabaseLog\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ShvetsGroup\\LaravelEmailDatabaseLog\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
Expand Down
40 changes: 40 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<!--<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>-->
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="MAIL_DRIVER" value="array"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
</php>
</phpunit>
31 changes: 31 additions & 0 deletions tests/Feature/LaravelEmailDatabaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace ShvetsGroup\LaravelEmailDatabaseLog\Tests\Feature;

use Illuminate\Support\Facades\Mail;
use Illuminate\Foundation\Testing\RefreshDatabase;
use ShvetsGroup\LaravelEmailDatabaseLog\Tests\TestCase;
use ShvetsGroup\LaravelEmailDatabaseLog\Tests\Mail\TestMail;

class LaravelEmailDatabaseTest extends TestCase
{
use RefreshDatabase;

/** @test */
public function the_email_is_logged_to_the_database()
{
Mail::to('email@example.com')
->send(new TestMail());

$this->assertDatabaseHas('email_log', [
'date' => now()->format('Y-m-d H:i:s'),
'from' => 'Example <hello@example.com>',
'to' => 'email@example.com',
'cc' => null,
'bcc' => null,
'subject' => 'The e-mail subject',
'body' => '<p>Some random string.</p>',
'attachments' => null,
]);
}
}
35 changes: 35 additions & 0 deletions tests/Mail/TestMail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace ShvetsGroup\LaravelEmailDatabaseLog\Tests\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class TestMail extends Mailable
{
use Queueable, SerializesModels;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->subject('The e-mail subject')
->html('<p>Some random string.</p>');
}
}
30 changes: 30 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace ShvetsGroup\LaravelEmailDatabaseLog\Tests;

use ShvetsGroup\LaravelEmailDatabaseLog\LaravelEmailDatabaseLogServiceProvider;

class TestCase extends \Orchestra\Testbench\TestCase
{
public function getEnvironmentSetUp($app)
{
// import the migrations
include_once __DIR__ . '/../src/database/migrations/2015_07_31_1_email_log.php';
include_once __DIR__ . '/../src/database/migrations/2016_09_21_001638_add_bcc_column_email_log.php';
include_once __DIR__ . '/../src/database/migrations/2017_11_10_001638_add_more_mail_columns_email_log.php';
include_once __DIR__ . '/../src/database/migrations/2018_05_11_115355_use_longtext_for_attachments.php';

// run the up() method of those migration classes
(new \EmailLog)->up();
(new \AddBccColumnEmailLog)->up();
(new \AddMoreMailColumnsEmailLog)->up();
(new \UseLongtextForAttachments)->up();
}

protected function getPackageProviders($app)
{
return [
LaravelEmailDatabaseLogServiceProvider::class,
];
}
}

0 comments on commit 4d6c7e7

Please sign in to comment.