Skip to content

Commit 38711da

Browse files
committed
Merge branch 'main' of github.com:hypervel/components
2 parents 754c25f + 9ea79aa commit 38711da

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

src/queue/src/Queue.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,10 @@ public function getContainer(): ContainerInterface
372372
/**
373373
* Set the IoC container instance.
374374
*/
375-
public function setContainer(ContainerInterface $container): void
375+
public function setContainer(ContainerInterface $container): static
376376
{
377377
$this->container = $container;
378+
379+
return $this;
378380
}
379381
}

src/queue/src/QueueManager.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,11 @@ public function connection(?string $name = null): Queue
139139
// If the connection has not been resolved yet we will resolve it now as all
140140
// of the connections are resolved when they are actually needed so we do
141141
// not make any unnecessary connection to the various queue end-points.
142-
if (! isset($this->connections[$name])) {
143-
$this->connections[$name] = $this->resolve($name);
144-
145-
/* @phpstan-ignore-next-line */
146-
$this->connections[$name]->setContainer($this->app);
142+
if ($queue = $this->connections[$name] ?? null) {
143+
return $queue;
147144
}
148145

149-
return $this->connections[$name];
146+
return $this->connections[$name] = $this->resolve($name);
150147
}
151148

152149
/**
@@ -162,9 +159,11 @@ protected function resolve(string $name): Queue
162159
throw new InvalidArgumentException("The [{$name}] queue connection has not been configured.");
163160
}
164161

162+
/** @phpstan-ignore-next-line */
165163
$resolver = fn () => $this->getConnector($config['driver'])
166164
->connect($config)
167-
->setConnectionName($name);
165+
->setConnectionName($name)
166+
->setContainer($this->app);
168167

169168
if (in_array($config['driver'], $this->poolables)) {
170169
return $this->createPoolProxy(

tests/Queue/QueueManagerTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public function testDefaultConnectionCanBeResolved()
4141
$connector = m::mock(ConnectorInterface::class);
4242
$queue = m::mock(Queue::class);
4343
$queue->shouldReceive('setConnectionName')->once()->with('sync')->andReturnSelf();
44+
$queue->shouldReceive('setContainer')->once()->with($container)->andReturnSelf();
4445
$connector->shouldReceive('connect')->once()->with(['driver' => 'sync'])->andReturn($queue);
4546
$manager->addConnector('sync', function () use ($connector) {
4647
return $connector;
4748
});
4849

49-
$queue->shouldReceive('setContainer')->once()->with($container);
5050
$this->assertSame($queue, $manager->connection('sync'));
5151
}
5252

@@ -65,7 +65,7 @@ public function testOtherConnectionCanBeResolved()
6565
$manager->addConnector('bar', function () use ($connector) {
6666
return $connector;
6767
});
68-
$queue->shouldReceive('setContainer')->once()->with($container);
68+
$queue->shouldReceive('setContainer')->once()->with($container)->andReturnSelf();
6969

7070
$this->assertSame($queue, $manager->connection('foo'));
7171
}
@@ -84,7 +84,7 @@ public function testNullConnectionCanBeResolved()
8484
$manager->addConnector('null', function () use ($connector) {
8585
return $connector;
8686
});
87-
$queue->shouldReceive('setContainer')->once()->with($container);
87+
$queue->shouldReceive('setContainer')->once()->with($container)->andReturnSelf();
8888

8989
$this->assertSame($queue, $manager->connection('null'));
9090
}
@@ -98,14 +98,10 @@ public function testAddPoolableConnector()
9898

9999
$manager = new QueueManager($container);
100100
$connector = m::mock(ConnectorInterface::class);
101-
$queue = m::mock(Queue::class);
102-
$queue->shouldReceive('setConnectionName')->once()->with('foo')->andReturnSelf();
103-
$connector->shouldReceive('connect')->once()->with(['driver' => 'bar'])->andReturn($queue);
104101
$manager->addConnector('bar', function () use ($connector) {
105102
return $connector;
106103
});
107104
$manager->addPoolable('bar');
108-
$queue->shouldReceive('setContainer')->once()->with($container);
109105

110106
$this->assertInstanceOf(QueuePoolProxy::class, $manager->connection('foo'));
111107
}

0 commit comments

Comments
 (0)