-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathTestCase.php
93 lines (73 loc) · 2.68 KB
/
TestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace Spatie\Mailcoach\Tests;
use CreateMailcoachTables;
use CreateMediaTable;
use CreateUsersTable;
use Illuminate\Foundation\Auth\User;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Route;
use Orchestra\Testbench\TestCase as Orchestra;
use Spatie\BladeX\BladeXServiceProvider;
use Spatie\Feed\FeedServiceProvider;
use Spatie\Mailcoach\Http\Front\Controllers\UnsubscribeController;
use Spatie\Mailcoach\MailcoachServiceProvider;
use Spatie\Mailcoach\Models\Send;
use Spatie\MediaLibrary\MediaLibraryServiceProvider;
use Spatie\TestTime\TestTime;
abstract class TestCase extends Orchestra
{
public function setUp(): void
{
parent::setUp();
$this->withFactories(__DIR__.'/../database/factories');
Route::mailcoach('mailcoach');
$this->withoutExceptionHandling();
Redis::flushAll();
Gate::define('viewMailcoach', fn () => true);
TestTime::freeze();
}
protected function getPackageProviders($app)
{
return [
MailcoachServiceProvider::class,
FeedServiceProvider::class,
BladeXServiceProvider::class,
MediaLibraryServiceProvider::class,
];
}
protected function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'sqlite');
$app['config']->set('database.connections.sqlite', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
include_once __DIR__.'/../database/migrations/create_mailcoach_tables.php.stub';
(new CreateMailcoachTables())->up();
include_once __DIR__.'/../vendor/spatie/laravel-medialibrary/database/migrations/create_media_table.php.stub';
(new CreateMediaTable())->up();
include_once __DIR__.'/database/migrations/create_users_table.php.stub';
(new CreateUsersTable())->up();
}
protected function simulateUnsubscribes(Collection $sends)
{
$sends->each(function (Send $send) {
$this
->get(action(UnsubscribeController::class, [$send->subscriber->uuid, $send->uuid]));
});
}
public function authenticate(string $guard = null)
{
$user = factory(User::class)->create();
$this->actingAs($user, $guard);
}
public function assertMatchesHtmlSnapshotWithoutWhitespace(string $content)
{
$contentWithoutWhitespace = preg_replace('/\s/', '', $content);
$contentWithoutWhitespace = str_replace(PHP_EOL, '', $contentWithoutWhitespace);
$this->assertMatchesHtmlSnapshot($contentWithoutWhitespace);
}
}