Skip to content

Commit 28ea493

Browse files
author
Arif Hoque
committed
unit test for chaiable job
1 parent 6ac60a9 commit 28ea493

File tree

7 files changed

+638
-2
lines changed

7 files changed

+638
-2
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@
4242
"sort-packages": true
4343
},
4444
"minimum-stability": "dev",
45-
"require": {}
45+
"require": {
46+
"opis/closure": "^4.4"
47+
}
4648
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Class;
4+
5+
class ChainTestState
6+
{
7+
public bool $callbackCalled = false;
8+
9+
public function markCalled(): void
10+
{
11+
$this->callbackCalled = true;
12+
}
13+
}
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 TestChainFailingJob extends Job
8+
{
9+
public static $executed = [];
10+
public string $name;
11+
12+
public function __construct(string $name = 'FailingJob')
13+
{
14+
$this->name = $name;
15+
}
16+
17+
public function handle(): void
18+
{
19+
self::$executed[] = $this->name;
20+
throw new \RuntimeException('Intentional chain failure');
21+
}
22+
23+
public static function reset(): void
24+
{
25+
self::$executed = [];
26+
}
27+
}

tests/Mock/Jobs/TestChainJobA.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Jobs;
4+
5+
use Doppar\Queue\Job;
6+
7+
class TestChainJobA extends Job
8+
{
9+
public static $executed = [];
10+
public string $name;
11+
12+
public function __construct(string $name = 'JobA')
13+
{
14+
$this->name = $name;
15+
}
16+
17+
public function handle(): void
18+
{
19+
self::$executed[] = $this->name;
20+
}
21+
22+
public static function reset(): void
23+
{
24+
self::$executed = [];
25+
}
26+
}

tests/Mock/Jobs/TestChainJobB.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Jobs;
4+
5+
use Doppar\Queue\Job;
6+
7+
class TestChainJobB extends Job
8+
{
9+
public static $executed = [];
10+
public string $name;
11+
12+
public function __construct(string $name = 'JobB')
13+
{
14+
$this->name = $name;
15+
}
16+
17+
public function handle(): void
18+
{
19+
self::$executed[] = $this->name;
20+
}
21+
22+
public static function reset(): void
23+
{
24+
self::$executed = [];
25+
}
26+
}

tests/Mock/Jobs/TestChainJobC.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Doppar\Queue\Tests\Mock\Jobs;
4+
5+
use Doppar\Queue\Job;
6+
7+
class TestChainJobC extends Job
8+
{
9+
public static $executed = [];
10+
public string $name;
11+
12+
public function __construct(string $name = 'JobC')
13+
{
14+
$this->name = $name;
15+
}
16+
17+
public function handle(): void
18+
{
19+
self::$executed[] = $this->name;
20+
}
21+
22+
public static function reset(): void
23+
{
24+
self::$executed = [];
25+
}
26+
}

0 commit comments

Comments
 (0)