Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/queue/src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,10 @@ public function getContainer(): ContainerInterface
/**
* Set the IoC container instance.
*/
public function setContainer(ContainerInterface $container): void
public function setContainer(ContainerInterface $container): static
{
$this->container = $container;

return $this;
}
}
13 changes: 6 additions & 7 deletions src/queue/src/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,11 @@ public function connection(?string $name = null): Queue
// If the connection has not been resolved yet we will resolve it now as all
// of the connections are resolved when they are actually needed so we do
// not make any unnecessary connection to the various queue end-points.
if (! isset($this->connections[$name])) {
$this->connections[$name] = $this->resolve($name);

/* @phpstan-ignore-next-line */
$this->connections[$name]->setContainer($this->app);
if ($queue = $this->connections[$name] ?? null) {
return $queue;
}

return $this->connections[$name];
return $this->connections[$name] = $this->resolve($name);
}

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

/** @phpstan-ignore-next-line */
$resolver = fn () => $this->getConnector($config['driver'])
->connect($config)
->setConnectionName($name);
->setConnectionName($name)
->setContainer($this->app);

if (in_array($config['driver'], $this->poolables)) {
return $this->createPoolProxy(
Expand Down
10 changes: 3 additions & 7 deletions tests/Queue/QueueManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public function testDefaultConnectionCanBeResolved()
$connector = m::mock(ConnectorInterface::class);
$queue = m::mock(Queue::class);
$queue->shouldReceive('setConnectionName')->once()->with('sync')->andReturnSelf();
$queue->shouldReceive('setContainer')->once()->with($container)->andReturnSelf();
$connector->shouldReceive('connect')->once()->with(['driver' => 'sync'])->andReturn($queue);
$manager->addConnector('sync', function () use ($connector) {
return $connector;
});

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

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

$this->assertSame($queue, $manager->connection('foo'));
}
Expand All @@ -84,7 +84,7 @@ public function testNullConnectionCanBeResolved()
$manager->addConnector('null', function () use ($connector) {
return $connector;
});
$queue->shouldReceive('setContainer')->once()->with($container);
$queue->shouldReceive('setContainer')->once()->with($container)->andReturnSelf();

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

$manager = new QueueManager($container);
$connector = m::mock(ConnectorInterface::class);
$queue = m::mock(Queue::class);
$queue->shouldReceive('setConnectionName')->once()->with('foo')->andReturnSelf();
$connector->shouldReceive('connect')->once()->with(['driver' => 'bar'])->andReturn($queue);
$manager->addConnector('bar', function () use ($connector) {
return $connector;
});
$manager->addPoolable('bar');
$queue->shouldReceive('setContainer')->once()->with($container);

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