Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Messenger][FrameworkBundle] Move collector, command into the component & minor tweaks #26816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[Messenger] Move data collector & command into the component
  • Loading branch information
ogizanagi committed Apr 5, 2018
commit f9c9ca0514a91cde76435df492a0244d81c912d8
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<tag name="console.command" command="debug:event-dispatcher" />
</service>

<service id="console.command.messenger_consume_messages" class="Symfony\Bundle\FrameworkBundle\Command\MessengerConsumeMessagesCommand">
<service id="console.command.messenger_consume_messages" class="Symfony\Component\Messenger\Command\ConsumeMessagesCommand">
<argument type="service" id="message_bus" />
<argument type="service" id="messenger.receiver_locator" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<tag name="monolog.logger" channel="messenger" />
</service>

<service id="data_collector.messenger" class="Symfony\Bundle\FrameworkBundle\DataCollector\MessengerDataCollector">
<service id="data_collector.messenger" class="Symfony\Component\Messenger\DataCollector\MessengerDataCollector">
<tag name="data_collector" template="@WebProfiler/Collector/messenger.html.twig" id="messenger" priority="100" />
<tag name="message_bus_middleware" />
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Command;
namespace Symfony\Component\Messenger\Command;

use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Command\Command;
Expand All @@ -24,8 +24,10 @@

/**
* @author Samuel Roze <samuel.roze@gmail.com>
*
* @experimental in 4.1
*/
class MessengerConsumeMessagesCommand extends Command
class ConsumeMessagesCommand extends Command
{
protected static $defaultName = 'messenger:consume-messages';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\DataCollector;
namespace Symfony\Component\Messenger\DataCollector;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -18,6 +18,8 @@

/**
* @author Samuel Roze <samuel.roze@gmail.com>
*
* @experimental in 4.1
*/
class MessengerDataCollector extends DataCollector implements MiddlewareInterface
{
Expand All @@ -26,7 +28,7 @@ class MessengerDataCollector extends DataCollector implements MiddlewareInterfac
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
return $this->data;
// noop
}

/**
Expand Down Expand Up @@ -61,25 +63,25 @@ public function handle($message, callable $next)
try {
$result = $next($message);

if (is_object($result)) {
if (\is_object($result)) {
$debugRepresentation['result'] = array(
'type' => get_class($result),
'type' => \get_class($result),
'object' => $this->cloneVar($result),
);
} elseif (is_array($result)) {
} elseif (\is_array($result)) {
$debugRepresentation['result'] = array(
'type' => 'array',
'object' => $this->cloneVar($result),
);
} else {
$debugRepresentation['result'] = array(
'type' => gettype($result),
'type' => \gettype($result),
'value' => $result,
);
}
} catch (\Throwable $exception) {
$debugRepresentation['exception'] = array(
'type' => get_class($exception),
'type' => \get_class($exception),
'message' => $exception->getMessage(),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Messenger\Tests\DataCollector;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\DataCollector\MessengerDataCollector;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/
class MessengerDataCollectorTest extends TestCase
{
use VarDumperTestTrait;

/**
* @dataProvider getHandleTestData
*/
public function testHandle($returnedValue, $expected)
{
$collector = new MessengerDataCollector();
$message = new DummyMessage('dummy message');

$next = $this->createPartialMock(\stdClass::class, array('__invoke'));
$next->expects($this->once())->method('__invoke')->with($message)->willReturn($returnedValue);

$this->assertSame($returnedValue, $collector->handle($message, $next));

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

$this->assertDumpMatchesFormat($expected, $messages[0]);
}

public function getHandleTestData()
{
$messageDump = <<<DUMP
"message" => array:2 [
"type" => "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage"
"object" => Symfony\Component\VarDumper\Cloner\Data {%A
%A+class: "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage"%A
}
]
DUMP;

yield 'no returned value' => array(
null,
<<<DUMP
array:2 [
$messageDump
"result" => array:2 [
"type" => "NULL"
"value" => null
]
]
DUMP
);

yield 'scalar returned value' => array(
'returned value',
<<<DUMP
array:2 [
$messageDump
"result" => array:2 [
"type" => "string"
"value" => "returned value"
]
]
DUMP
);

yield 'array returned value' => array(
array('returned value'),
<<<DUMP
array:2 [
$messageDump
"result" => array:2 [
"type" => "array"
"object" => Symfony\Component\VarDumper\Cloner\Data {%A
]
]
DUMP
);
}

public function testHandleWithException()
{
$collector = new MessengerDataCollector();
$message = new DummyMessage('dummy message');

$expectedException = new \RuntimeException('foo');
$next = $this->createPartialMock(\stdClass::class, array('__invoke'));
$next->expects($this->once())->method('__invoke')->with($message)->willThrowException($expectedException);

try {
$collector->handle($message, $next);
} catch (\Throwable $actualException) {
$this->assertSame($expectedException, $actualException);
}

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

$this->assertDumpMatchesFormat(<<<DUMP
array:2 [
"message" => array:2 [
"type" => "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage"
"object" => Symfony\Component\VarDumper\Cloner\Data {%A
%A+class: "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage"%A
}
]
"exception" => array:2 [
"type" => "RuntimeException"
"message" => "foo"
]
]
DUMP
, $messages[0]);
}
}
4 changes: 3 additions & 1 deletion 4 src/Symfony/Component/Messenger/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"require-dev": {
"symfony/serializer": "~3.4|~4.0",
"symfony/dependency-injection": "~3.4.6|~4.0",
"symfony/property-access": "~3.4|~4.0"
"symfony/http-kernel": "~3.4|~4.0",
"symfony/property-access": "~3.4|~4.0",
"symfony/var-dumper": "~3.4|~4.0"
},
"suggest": {
"sroze/enqueue-bridge": "For using the php-enqueue library as an adapter."
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.