|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spiral\Tests\Queue\Core; |
|
4
|
|
|
|
|
5
|
|
|
use Mockery as m; |
|
6
|
|
|
use ReflectionClass; |
|
7
|
|
|
use RuntimeException; |
|
8
|
|
|
use Spiral\Core\Exception\Container\NotFoundException; |
|
9
|
|
|
use Spiral\Core\FactoryInterface; |
|
10
|
|
|
use Spiral\Queue\Config\QueueConfig; |
|
11
|
|
|
use Spiral\Queue\Core\QueueInjector; |
|
12
|
|
|
use Spiral\Queue\QueueInterface; |
|
13
|
|
|
use Spiral\Queue\QueueManager; |
|
14
|
|
|
use Spiral\Tests\Queue\Core\Stub\TestQueueClass; |
|
15
|
|
|
use Spiral\Tests\Queue\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
final class QueueInjectorTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
private ?QueueInterface $defaultQueue = null; |
|
20
|
|
|
|
|
21
|
|
|
public function testGetByContext(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$injector = $this->createInjector(); |
|
24
|
|
|
$reflection = new ReflectionClass(TestQueueClass::class); |
|
25
|
|
|
|
|
26
|
|
|
$result = $injector->createInjection($reflection, 'test'); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertInstanceOf(TestQueueClass::class, $result); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testGetByIncorrectContext(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$injector = $this->createInjector(); |
|
34
|
|
|
$reflection = new ReflectionClass(QueueInterface::class); |
|
35
|
|
|
|
|
36
|
|
|
$result = $injector->createInjection($reflection, 'userQueue'); |
|
37
|
|
|
|
|
38
|
|
|
// The default connection should be returned |
|
39
|
|
|
$this->assertSame($this->defaultQueue, $result); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testBadArgumentTypeException(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$injector = $this->createInjector(); |
|
45
|
|
|
$this->expectException(RuntimeException::class); |
|
46
|
|
|
$this->expectExceptionMessage('The queue obtained by the context'); |
|
47
|
|
|
|
|
48
|
|
|
$reflection = new ReflectionClass(TestQueueClass::class); |
|
49
|
|
|
$injector->createInjection($reflection, 'queue'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
private function createInjector(): QueueInjector |
|
53
|
|
|
{ |
|
54
|
|
|
$this->defaultQueue = m::mock(QueueInterface::class); |
|
55
|
|
|
$config = new QueueConfig([ |
|
56
|
|
|
'default' => 'sync', |
|
57
|
|
|
'aliases' => [ |
|
58
|
|
|
'mail-queue' => 'roadrunner', |
|
59
|
|
|
'rating-queue' => 'sync', |
|
60
|
|
|
'queue' => 'sync', |
|
61
|
|
|
'test' => 'test', |
|
62
|
|
|
], |
|
63
|
|
|
'driverAliases' => [], |
|
64
|
|
|
'connections' => [ |
|
65
|
|
|
'sync' => [ |
|
66
|
|
|
'driver' => 'sync', |
|
67
|
|
|
], |
|
68
|
|
|
'test' => [ |
|
69
|
|
|
'driver' => 'test', |
|
70
|
|
|
], |
|
71
|
|
|
'roadrunner' => [ |
|
72
|
|
|
'driver' => 'roadrunner', |
|
73
|
|
|
'default' => 'local', |
|
74
|
|
|
'pipelines' => [ |
|
75
|
|
|
'local' => [ |
|
76
|
|
|
'connector' => m::mock(QueueInterface::class), |
|
77
|
|
|
'consume' => true, |
|
78
|
|
|
], |
|
79
|
|
|
], |
|
80
|
|
|
], |
|
81
|
|
|
], |
|
82
|
|
|
]); |
|
83
|
|
|
$factory = m::mock(FactoryInterface::class); |
|
84
|
|
|
$factory->shouldReceive('make')->andReturnUsing(function (string $name): QueueInterface { |
|
|
|
|
|
|
85
|
|
|
$result = [ |
|
86
|
|
|
'sync' => $this->defaultQueue, |
|
87
|
|
|
'test' => new TestQueueClass(), |
|
88
|
|
|
][$name] ?? null; |
|
89
|
|
|
if ($result === null) { |
|
90
|
|
|
throw new NotFoundException(); |
|
91
|
|
|
} |
|
92
|
|
|
return $result; |
|
93
|
|
|
}); |
|
94
|
|
|
$manager = new QueueManager($config, $factory); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
return new QueueInjector($manager, $config); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.