1
|
|
|
<?php declare (strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Tests\EventDispatcher; |
4
|
|
|
|
5
|
|
|
use Illuminate\Container\Container; |
6
|
|
|
use Illuminate\Contracts\Config\Repository; |
7
|
|
|
use Illuminate\Queue\Capsule\Manager as Queue; |
8
|
|
|
use Illuminate\Support\Testing\Fakes\EventFake; |
9
|
|
|
use SmoothPhp\LaravelAdapter\QueuedEventDispatcher\QueuedEventDispatcher; |
10
|
|
|
use SmoothPhp\LaravelAdapter\QueuedEventDispatcher\QueuedEventHandler; |
11
|
|
|
use SmoothPhp\Serialization\ObjectSelfSerializer; |
12
|
|
|
use Tests\EventDispatcher\Helpers\TestEvent; |
13
|
|
|
use Tests\EventDispatcher\Helpers\TestHandler; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class PushEventThoughDispatcherQueueTest |
17
|
|
|
* @package Tests\EventDispatcher |
18
|
|
|
* @author Simon Bennett <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
final class PushEventThoughDispatcherQueueTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
public function test_pushing_event_to_queue() |
26
|
|
|
{ |
27
|
|
|
$container = new Container(); |
28
|
|
|
// $container->bind(\Illuminate\Contracts\Container\Container::class, $container); |
|
|
|
|
29
|
|
|
$queue = new Queue($container); |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
$queue->addConnection( |
33
|
|
|
[ |
34
|
|
|
'driver' => 'sync', |
35
|
|
|
] |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
$config = $this->getMockBuilder(Repository::class)->getMock(); |
40
|
|
|
$config->method('set')->with( |
41
|
|
|
$this->returnValueMap( |
42
|
|
|
[ |
43
|
|
|
// Config set values |
44
|
|
|
] |
45
|
|
|
) |
46
|
|
|
); |
47
|
|
|
$config->method('get')->will( |
48
|
|
|
$this->returnValueMap( |
49
|
|
|
[ |
50
|
|
|
// Config get values |
51
|
|
|
] |
52
|
|
|
) |
53
|
|
|
); |
54
|
|
|
$eventDispatcher = new QueuedEventDispatcher($queue->getConnection(), new ObjectSelfSerializer(), $config); |
55
|
|
|
|
56
|
|
|
$handler = new TestHandler(); |
57
|
|
|
|
58
|
|
|
$eventDispatcher->addSubscriber($handler); |
59
|
|
|
$eventDispatcher->addSubscriber($handler); |
60
|
|
|
|
61
|
|
|
$event = new TestEvent(uuid()); |
62
|
|
|
|
63
|
|
|
//$this->assertEquals(2,$handler->runCount); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$eventDispatcher->dispatch(strtr(get_class($event), '\\', '.'), [$event]); |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.