Skip to content

Commit 041f104

Browse files
authored
Merge pull request #6 from doppar/unittest
[Unit Test] Queue unit test for all possible test case
2 parents 5ae4260 + 04b8c3d commit 041f104

16 files changed

+1259
-217
lines changed

composer.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "doppar/guard",
3-
"description": "A authorization package for doppar framework",
2+
"name": "doppar/queue",
3+
"description": "A lightweight queue management library for the Doppar framework.",
44
"type": "library",
55
"license": "MIT",
66
"support": {
7-
"issues": "https://github.com/doppar/guard/issues",
8-
"source": "https://github.com/doppar/guard"
7+
"issues": "https://github.com/doppar/queue/issues",
8+
"source": "https://github.com/doppar/queue"
99
},
1010
"authors": [
1111
{
@@ -15,16 +15,17 @@
1515
],
1616
"require-dev": {
1717
"mockery/mockery": "^1.6",
18-
"phpunit/phpunit": "^12.1.5"
18+
"phpunit/phpunit": "^12.1.5",
19+
"doppar/framework": "^3.0.0"
1920
},
2021
"autoload": {
2122
"psr-4": {
22-
"Doppar\\Authorizer\\": "src/"
23+
"Doppar\\Queue\\": "src/"
2324
}
2425
},
2526
"autoload-dev": {
2627
"psr-4": {
27-
"Doppar\\Authorizer\\Tests\\": "tests/"
28+
"Doppar\\Queue\\Tests\\": "tests/"
2829
}
2930
},
3031
"extra": {
@@ -33,7 +34,7 @@
3334
},
3435
"doppar": {
3536
"providers": [
36-
"Doppar\\Authorizer\\GuardServiceProvider"
37+
"Doppar\\Queue\\QueueServiceProvider"
3738
]
3839
}
3940
},

phpunit.xml.dist

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true">
2+
<phpunit backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="false" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
33
<testsuites>
4-
<testsuite name="Unit">
5-
<directory suffix="Test.php">./tests/Unit</directory>
4+
<testsuite name="Doppar Test Suite">
5+
<directory suffix="Test.php">./tests</directory>
66
</testsuite>
77
</testsuites>
88
<php>
9-
<env name="APP_KEY" value="base64:7n/+NIB4i3LQ6+ZbrclxuwyEqG5Uprufs90NJGL2pls="/>
9+
<ini name="date.timezone" value="UTC" />
10+
<ini name="intl.default_locale" value="C.UTF-8" />
11+
<ini name="memory_limit" value="2048M" />
12+
<env name="DB_CONNECTION" value="testing" />
13+
<!--
14+
<env name="REDIS_CLIENT" value="phpredis" />
15+
<env name="REDIS_HOST" value="127.0.0.1" />
16+
<env name="REDIS_PORT" value="6379" />
17+
-->
1018
</php>
1119
</phpunit>

storage/logs/doppar.log

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[2025-11-14T08:38:24.717063+00:00] stack.ERROR: Failed to mark job as failed: Database connection [] not configured.
2+
[2025-11-14T08:38:57.213083+00:00] stack.ERROR: Failed to mark job as failed: Database connection [] not configured.
3+
[2025-11-14T08:39:33.718229+00:00] stack.ERROR: Failed to mark job as failed: Database connection [] not configured.
4+
[2025-11-14T08:43:01.934544+00:00] stack.ERROR: Failed to mark job as failed: Database connection [] not configured.
5+
[2025-11-14T08:44:10.792443+00:00] stack.ERROR: Failed to mark job as failed: Database connection [] not configured.
6+
[2025-11-14T08:45:01.563845+00:00] stack.ERROR: Failed to mark job as failed: Database connection [] not configured.
7+
[2025-11-14T08:45:05.456173+00:00] stack.ERROR: Failed to mark job as failed: Database connection [] not configured.
8+
[2025-11-14T08:45:57.038190+00:00] stack.ERROR: Failed to mark job as failed: Database connection [] not configured.
9+
[2025-11-14T08:47:51.149909+00:00] stack.ERROR: Failed to mark job as failed: Database connection [] not configured.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Jobs;
4+
5+
use Doppar\Queue\Job;
6+
7+
class TestComplexDataJob extends Job
8+
{
9+
public $data;
10+
11+
public function __construct(array $data)
12+
{
13+
$this->data = $data;
14+
}
15+
16+
public function handle(): void
17+
{
18+
if (empty($this->data)) {
19+
throw new \RuntimeException('No data provided');
20+
}
21+
}
22+
}

tests/Mock/Jobs/TestCounterJob.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Jobs;
4+
5+
use Doppar\Queue\Job;
6+
7+
class TestCounterJob extends Job
8+
{
9+
public $counter = 0;
10+
11+
public function handle(): void
12+
{
13+
$this->counter++;
14+
}
15+
}

tests/Mock/Jobs/TestEmailJob.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Jobs;
4+
5+
use Doppar\Queue\Job;
6+
7+
class TestEmailJob extends Job
8+
{
9+
public $tries = 3;
10+
public $retryAfter = 60;
11+
public $to;
12+
public $subject;
13+
14+
public function __construct(string $to, string $subject)
15+
{
16+
$this->to = $to;
17+
$this->subject = $subject;
18+
}
19+
20+
public function handle(): void
21+
{
22+
// Simulate sending email
23+
if (empty($this->to) || empty($this->subject)) {
24+
throw new \RuntimeException('Invalid email data');
25+
}
26+
}
27+
}

tests/Mock/Jobs/TestFailingJob.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Jobs;
4+
5+
use Doppar\Queue\Job;
6+
7+
class TestFailingJob extends Job
8+
{
9+
public $tries = 3;
10+
public $retryAfter = 60;
11+
12+
public function handle(): void
13+
{
14+
throw new \RuntimeException('Test failure');
15+
}
16+
}

tests/Mock/Jobs/TestImageJob.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Jobs;
4+
5+
use Doppar\Queue\Job;
6+
7+
class TestImageJob extends Job
8+
{
9+
public $tries = 3;
10+
public $retryAfter = 120;
11+
public $imagePath;
12+
13+
public function __construct(string $imagePath)
14+
{
15+
$this->imagePath = $imagePath;
16+
}
17+
18+
public function handle(): void
19+
{
20+
if (empty($this->imagePath)) {
21+
throw new \RuntimeException('Invalid image path');
22+
}
23+
}
24+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Jobs;
4+
5+
use Doppar\Queue\Job;
6+
7+
class TestJobWithFailedCallback extends Job
8+
{
9+
public $tries = 1;
10+
public $failedCalled = false;
11+
12+
public function handle(): void
13+
{
14+
throw new \RuntimeException('Intentional failure');
15+
}
16+
17+
public function failed(\Throwable $exception): void
18+
{
19+
$this->failedCalled = true;
20+
}
21+
}

tests/Mock/Jobs/TestReportJob.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Jobs;
4+
5+
use Doppar\Queue\Job;
6+
7+
class TestReportJob extends Job
8+
{
9+
public $tries = 2;
10+
public $retryAfter = 300;
11+
public $reportType;
12+
13+
public function __construct(string $reportType)
14+
{
15+
$this->reportType = $reportType;
16+
}
17+
18+
public function handle(): void
19+
{
20+
if (empty($this->reportType)) {
21+
throw new \RuntimeException('Invalid report type');
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)