Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
boomhq committed Feb 16, 2022
1 parent af12065 commit d9d9f05
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Queue/DatabaseFailedJobProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Illuminate\Tests\Queue;

use Exception;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Queue\Failed\DatabaseFailedJobProvider;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Str;
use PHPUnit\Framework\TestCase;

class DatabaseFailedJobProviderTest extends TestCase
Expand Down Expand Up @@ -39,4 +41,34 @@ public function testCanFlushFailedJobs()
$provider->flush(10 * 24);
$this->assertSame(0, $db->getConnection()->table('failed_jobs')->count());
}

public function testCanProperlyLogFailedJob()
{
$db = new DB;
$db->addConnection([
'driver' => 'sqlite',
'database' => ':memory:',
]);

$db->getConnection()->getSchemaBuilder()->create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});

$uuid = Str::uuid();

$exception = new Exception(utf8_decode('ÐÑÙ0E\xE2\x�98\xA0World��7B¹!þÿ'));
$provider = new DatabaseFailedJobProvider($db->getDatabaseManager(), 'default', 'failed_jobs');

$provider->log('database', 'default', json_encode(['uuid' => (string) $uuid]), $exception);

$exception = (string) mb_convert_encoding($exception, 'UTF-8');

$this->assertSame(1, $db->getConnection()->table('failed_jobs')->count());
$this->assertSame($exception, $db->getConnection()->table('failed_jobs')->first()->exception);
}
}

0 comments on commit d9d9f05

Please sign in to comment.