generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67580b5
commit a716392
Showing
5 changed files
with
60 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" | ||
backupGlobals="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
executionOrder="random" | ||
failOnWarning="true" | ||
failOnRisky="true" | ||
failOnEmptyTestSuite="true" | ||
beStrictAboutOutputDuringTests="true" | ||
cacheDirectory=".phpunit.cache" | ||
backupStaticProperties="false" | ||
> | ||
<testsuites> | ||
<testsuite name="CleaniqueCoders Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
<report> | ||
<html outputDirectory="build/coverage"/> | ||
<text outputFile="build/coverage.txt"/> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
</report> | ||
</coverage> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="BCRYPT_ROUNDS" value="4"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="DB_CONNECTION" value="sqlite"/> | ||
<env name="DB_DATABASE" value=":memory:"/> | ||
<env name="MAIL_MAILER" value="log"/> | ||
<env name="QUEUE_CONNECTION" value="sync"/> | ||
<env name="SESSION_DRIVER" value="array"/> | ||
<env name="TELESCOPE_ENABLED" value="false"/> | ||
</php> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false"> | ||
<testsuites> | ||
<testsuite name="CleaniqueCoders Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<report> | ||
<html outputDirectory="build/coverage"/> | ||
<text outputFile="build/coverage.txt"/> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
</report> | ||
</coverage> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="BCRYPT_ROUNDS" value="4"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="DB_CONNECTION" value="sqlite"/> | ||
<env name="DB_DATABASE" value=":memory:"/> | ||
<env name="MAIL_MAILER" value="log"/> | ||
<env name="QUEUE_CONNECTION" value="sync"/> | ||
<env name="SESSION_DRIVER" value="array"/> | ||
<env name="TELESCOPE_ENABLED" value="false"/> | ||
</php> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,62 +2,51 @@ | |
|
||
use Illuminate\Mail\Events\MessageSending; | ||
use Illuminate\Mail\Events\MessageSent; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
beforeEach(function () { | ||
// Set view paths | ||
config()->set('view.paths', [ | ||
dirname(__FILE__).'/resources/views', | ||
]); | ||
|
||
// Commit any existing transactions | ||
try { | ||
DB::commit(); | ||
} catch (\Exception $e) { | ||
// Ignore any commit errors since there might not be an active transaction | ||
} | ||
|
||
// Run migrations | ||
Artisan::call('vendor:publish', [ | ||
'--tag' => 'mailhistory-migrations', | ||
'--force' => true, | ||
]); | ||
|
||
// Fresh migration without transaction wrapping | ||
DB::unprepared('PRAGMA foreign_keys = OFF;'); | ||
Artisan::call('migrate:fresh'); | ||
DB::unprepared('PRAGMA foreign_keys = ON;'); | ||
}); | ||
use Illuminate\Support\Facades\Mail; | ||
|
||
it('has MessageSending and MessageSent event listened to if the package is enabled', function () { | ||
$this->assertTrue( | ||
Event::hasListeners(MessageSending::class), | ||
Event::hasListeners(MessageSending::class) | ||
); | ||
|
||
$this->assertTrue( | ||
Event::hasListeners(MessageSent::class), | ||
Event::hasListeners(MessageSent::class) | ||
); | ||
}); | ||
|
||
it('does not has the MessageSending and MessageSent event listened to if the package is disabled', function () { | ||
it('does not have the MessageSending and MessageSent event listened when disabled', function () { | ||
config([ | ||
'mailhistory.enabled' => false, | ||
]); | ||
|
||
Event::fake(); | ||
|
||
foreach (config('mailhistory.events') as $event => $listeners) { | ||
Event::flush($event); | ||
Event::forget($event); | ||
} | ||
|
||
$this->assertFalse( | ||
Event::hasListeners(MessageSending::class), | ||
Event::hasListeners(MessageSending::class) | ||
); | ||
|
||
$this->assertFalse( | ||
Event::hasListeners(MessageSent::class), | ||
Event::hasListeners(MessageSent::class) | ||
); | ||
})->skip('Need to work on disabling the event listener at runtime.'); | ||
}); | ||
|
||
it('stores mail history when sending mail', function () { | ||
$mailable = new \Illuminate\Mail\Mailable; | ||
$mailable->to('[email protected]') | ||
->from('[email protected]') | ||
->subject('Test Subject') | ||
->html('Test content'); | ||
|
||
Mail::send($mailable); | ||
|
||
$this->assertDatabaseHas('mail_histories', [ | ||
'status' => 'Sending', | ||
'body' => 'Test content', | ||
'content' => '{"text":null,"text-charset":null,"html":"Test content","html-charset":"utf-8"}', | ||
'meta' => '{"origin":"Mail"}', | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
<?php | ||
|
||
use CleaniqueCoders\MailHistory\Tests\TestCase; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
uses( | ||
TestCase::class, | ||
RefreshDatabase::class | ||
TestCase::class | ||
)->in(__DIR__); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters