Skip to content

Commit c0b35a3

Browse files
committed
Add tests for ChainHandler class
1 parent 8500792 commit c0b35a3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Tests/Handler/ChainHandlerTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Tests\Handler;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Messenger\Handler\ChainHandler;
16+
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
17+
18+
class ChainHandlerTest extends TestCase
19+
{
20+
public function testItCallsTheHandlersAndReturnsAllResults()
21+
{
22+
$message = new DummyMessage('Hey');
23+
24+
$handler1 = $this->createPartialMock(\stdClass::class, array('__invoke'));
25+
$handler1
26+
->expects($this->once())
27+
->method('__invoke')
28+
->with($message)
29+
->willReturn('Hello')
30+
;
31+
$handler2 = $this->createPartialMock(\stdClass::class, array('__invoke'));
32+
$handler2
33+
->expects($this->once())
34+
->method('__invoke')
35+
->with($message)
36+
->willReturn('World')
37+
;
38+
39+
$results = (new ChainHandler(array($handler1, $handler2)))($message);
40+
41+
$this->assertSame(array('Hello', 'World'), $results);
42+
}
43+
44+
/**
45+
* @expectedException \InvalidArgumentException
46+
* @expectedExceptionMessage A collection of message handlers requires at least one handler.
47+
*/
48+
public function testInvalidArgumentExceptionOnEmptyHandlers()
49+
{
50+
new ChainHandler(array());
51+
}
52+
}

0 commit comments

Comments
 (0)