Skip to content

Commit

Permalink
minor #27100 [Messenger] Late collect & clone messages (ogizanagi)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.1-dev branch.

Discussion
----------

[Messenger] Late collect & clone messages

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see below -->
| Bug fix?      | no
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | N/A   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A

Commits
-------

eb94361 [Messenger] Late collect & clone messages
  • Loading branch information
sroze committed Apr 30, 2018
2 parents e224548 + eb94361 commit 74aa515
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
use Symfony\Component\Messenger\TraceableMessageBus;

/**
* @author Samuel Roze <samuel.roze@gmail.com>
*
* @experimental in 4.1
*/
class MessengerDataCollector extends DataCollector
class MessengerDataCollector extends DataCollector implements LateDataCollectorInterface
{
private $traceableBuses = array();

Expand All @@ -34,6 +35,14 @@ public function registerBus(string $name, TraceableMessageBus $bus)
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
// Noop. Everything is collected live by the traceable buses & cloned as late as possible.
}

/**
* {@inheritdoc}
*/
public function lateCollect()
{
$this->data = array('messages' => array());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace Symfony\Component\Messenger\Tests\DataCollector;

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\DataCollector\MessengerDataCollector;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
Expand Down Expand Up @@ -43,7 +41,7 @@ public function testHandle($returnedValue, $expected)

$bus->dispatch($message);

$collector->collect(Request::create('/'), new Response());
$collector->lateCollect();

$messages = $collector->getMessages();
$this->assertCount(1, $messages);
Expand Down Expand Up @@ -120,7 +118,7 @@ public function testHandleWithException()
// Ignore.
}

$collector->collect(Request::create('/'), new Response());
$collector->lateCollect();

$messages = $collector->getMessages();
$this->assertCount(1, $messages);
Expand Down

0 comments on commit 74aa515

Please sign in to comment.