Skip to content

Commit 78c3aed

Browse files
committed
TEST
1 parent 6fb71be commit 78c3aed

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use App\Jobs\GenerateSocialShareImage;
4+
use App\Models\Article;
5+
use Illuminate\Foundation\Testing\DatabaseMigrations;
6+
use Tests\TestCase;
7+
8+
uses(TestCase::class);
9+
uses(DatabaseMigrations::class);
10+
11+
test('social image is generated for articles', function () {
12+
$article = Article::factory()->create([
13+
'title' => 'This is an article to test social share image generation'
14+
]);
15+
16+
$generatedSocialShareImagePath = sys_get_temp_dir() . '/generated_social_share_temporary_image.png';
17+
18+
file_put_contents(
19+
$generatedSocialShareImagePath,
20+
((new GenerateSocialShareImage($article))->handle())->content()
21+
);
22+
23+
expect(
24+
hash_file(
25+
'sha256',
26+
$generatedSocialShareImagePath
27+
)
28+
)->toBe(
29+
hash_file(
30+
'sha256',
31+
$this->getStub('generate_social_share_image.png')
32+
)
33+
);
34+
35+
unlink($generatedSocialShareImagePath);
36+
});

tests/TestCase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ protected function dispatch($job): void
1313
{
1414
$job->handle();
1515
}
16+
17+
public function getStub(string $nameOfStub): string
18+
{
19+
return __DIR__ . "/stubs/{$nameOfStub}";
20+
}
1621
}
48.3 KB
Loading

0 commit comments

Comments
 (0)