forked from spatie/laravel-feed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCase.php
130 lines (110 loc) · 4.33 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace Spatie\Feed\Test;
use Carbon\Carbon;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use Spatie\Feed\FeedServiceProvider;
use Spatie\Snapshots\MatchesSnapshots;
abstract class TestCase extends \Orchestra\Testbench\TestCase
{
use MatchesSnapshots;
public function setUp(): void
{
Carbon::setTestNow(Carbon::create(2016, 1, 1, 0, 0, 0)
->setTimezone('Europe/Brussels')
->startOfDay());
parent::setUp();
$this->withoutExceptionHandling();
}
protected function getPackageProviders($app)
{
return [FeedServiceProvider::class];
}
protected function getEnvironmentSetUp($app)
{
$feed = [
'feed1' => [
'items' => 'Spatie\Feed\Test\DummyRepository@getAll',
'url' => '/feed1',
'title' => 'Feed 1',
'description' => 'This is feed 1 from the unit tests',
'language' => 'en-US',
'image' => 'http://localhost/image.jpg',
'format' => 'atom',
],
'feed2' => [
'items' => 'Spatie\Feed\Test\DummyRepository@getAll',
'url' => '/feed2',
'title' => 'Feed 2',
'description' => 'This is feed 2 from the unit tests',
'language' => 'en-US',
'image' => 'http://localhost/image.jpg',
'format' => 'atom',
],
'feed3' => [
'items' => ['Spatie\Feed\Test\DummyRepository@getAllWithArguments', 'first'],
'url' => '/feed3',
'title' => 'Feed 3',
'description' => 'This is feed 3 from the unit tests',
'language' => 'en-US',
'image' => 'http://localhost/image.jpg',
'format' => 'atom',
],
'feedcustom' => [
'items' => 'Spatie\Feed\Test\DummyRepository@getAll',
'url' => '/feed-with-custom-view',
'title' => 'Feed with Custom View',
'description' => 'This is a feed that uses custom views from the unit tests',
'language' => 'en-US',
'image' => 'http://localhost/image.jpg',
'view' => 'feed::links',
'format' => 'atom',
],
'feedrss' => [
'items' => 'Spatie\Feed\Test\DummyRepository@getAll',
'url' => '/feed1.rss',
'title' => 'Feed 1 RSS',
'description' => 'This is feed 1 as RSS from the unit tests',
'language' => 'en-US',
'image' => 'http://localhost/image.jpg',
'view' => 'feed::rss',
'type' => 'application/rss+xml',
'format' => 'rss',
],
'feedjson' => [
'items' => 'Spatie\Feed\Test\DummyRepository@getAll',
'url' => '/feed1.json',
'title' => 'Feed 1 JSON',
'description' => 'This is feed 1 as JSON from the unit tests',
'language' => 'en-US',
'image' => 'http://localhost/image.jpg',
'view' => 'feed::json',
'type' => 'application/feed+json',
'format' => 'json',
],
];
$app['config']->set('feed.feeds', $feed);
$app['config']->set('app.debug', true);
$this->setUpRoutes($app);
}
private function renderBlade($app, string $template, array $data = []): string
{
$tempDirectory = dirname(__FILE__) . '/temp';
if (! in_array($tempDirectory, $app['view']->getFinder()->getPaths())) {
$app['view']->addLocation($tempDirectory);
}
$tempFile = $tempDirectory . '/laravel-feed-' . Str::random(10) . '.blade.php';
file_put_contents($tempFile, $template);
return $app['view']->make(Str::before(basename($tempFile), '.blade.php'))->with($data);
}
protected function setUpRoutes($app): void
{
Route::feeds('feedBaseUrl');
Route::get('/test-route', function () use ($app) {
return $app['view']->make('feed::links');
});
Route::get('/test-route-blade-component', function () use ($app) {
return $this->renderBlade($app, '<x-feed-links />');
});
}
}