Skip to content

Commit

Permalink
update tests and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Sep 19, 2024
1 parent c1481bb commit eacc271
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
with:
php-version: ${{ matrix.php-versions }}
tools: composer, phive, phpunit
extensions: intl, json, mbstring, gd, xdebug, xml, sqlite3, redis
extensions: intl, json, mbstring, gd, xdebug, xml, sqlite3, sqlsrv, oci8, pgsql
coverage: xdebug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
47 changes: 29 additions & 18 deletions tests/DatabaseHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Tests;

use Closure;
use CodeIgniter\I18n\Time;
use CodeIgniter\Queue\Entities\QueueJob;
use CodeIgniter\Queue\Enums\Status;
Expand All @@ -35,12 +36,22 @@ final class DatabaseHandlerTest extends TestCase

protected $seed = TestDatabaseQueueSeeder::class;
private QueueConfig $config;
private Closure $field;

protected function setUp(): void
{
parent::setUp();

$this->config = config(QueueConfig::class);

// handle filed custom type conversion for SQLSRV
$this->field = function ($field) {
if ($this->db->DBDriver === 'SQLSRV') {
return "CONVERT(VARCHAR, {$field})";
}

return $field;
};
}

public function testDatabaseHandler(): void
Expand Down Expand Up @@ -87,9 +98,9 @@ public function testPush(): void

$this->assertTrue($result);
$this->seeInDatabase('queue_jobs', [
'queue' => 'queue',
'payload' => json_encode(['job' => 'success', 'data' => ['key' => 'value']]),
'available_at' => '1703859316',
'queue' => 'queue',
($this->field)('payload') => json_encode(['job' => 'success', 'data' => ['key' => 'value']]),
'available_at' => '1703859316',
]);
}

Expand All @@ -105,10 +116,10 @@ public function testPushWithPriority(): void

$this->assertTrue($result);
$this->seeInDatabase('queue_jobs', [
'queue' => 'queue',
'payload' => json_encode(['job' => 'success', 'data' => ['key' => 'value']]),
'priority' => 'high',
'available_at' => '1703859316',
'queue' => 'queue',
($this->field)('payload') => json_encode(['job' => 'success', 'data' => ['key' => 'value']]),
'priority' => 'high',
'available_at' => '1703859316',
]);
}

Expand All @@ -121,20 +132,20 @@ public function testPushAndPopWithPriority(): void

$this->assertTrue($result);
$this->seeInDatabase('queue_jobs', [
'queue' => 'queue',
'payload' => json_encode(['job' => 'success', 'data' => ['key1' => 'value1']]),
'priority' => 'low',
'available_at' => '1703859316',
'queue' => 'queue',
($this->field)('payload') => json_encode(['job' => 'success', 'data' => ['key1' => 'value1']]),
'priority' => 'low',
'available_at' => '1703859316',
]);

$result = $handler->setPriority('high')->push('queue', 'success', ['key2' => 'value2']);

$this->assertTrue($result);
$this->seeInDatabase('queue_jobs', [
'queue' => 'queue',
'payload' => json_encode(['job' => 'success', 'data' => ['key2' => 'value2']]),
'priority' => 'high',
'available_at' => '1703859316',
'queue' => 'queue',
($this->field)('payload') => json_encode(['job' => 'success', 'data' => ['key2' => 'value2']]),
'priority' => 'high',
'available_at' => '1703859316',
]);

$result = $handler->pop('queue', ['high', 'low']);
Expand Down Expand Up @@ -347,9 +358,9 @@ public function testRetry(): void
$this->assertSame($count, 1);

$this->seeInDatabase('queue_jobs', [
'id' => 3,
'queue' => 'queue1',
'payload' => json_encode(['job' => 'failure', 'data' => []]),
'id' => 3,
'queue' => 'queue1',
($this->field)('payload') => json_encode(['job' => 'failure', 'data' => []]),
]);
$this->dontSeeInDatabase('queue_jobs_failed', [
'id' => 1,
Expand Down

0 comments on commit eacc271

Please sign in to comment.