44use Aws \Sqs \SqsClient ;
55use Dusterio \PlainSqs \Jobs \DispatcherJob ;
66use Dusterio \PlainSqs \Sqs \Queue ;
7+ use Illuminate \Container \Container ;
8+ use Illuminate \Contracts \Config \Repository ;
79
810/**
911 * Class QueueTest
1012 * @package Dusterio\PlainSqs\Tests
1113 */
1214class QueueTest extends \PHPUnit_Framework_TestCase
1315{
16+ /**
17+ * @var \PHPUnit_Framework_MockObject_MockObject|SqsClient
18+ */
19+ private $ sqsClientMock ;
20+
21+ /**
22+ * @var \PHPUnit_Framework_MockObject_MockObject|Container
23+ */
24+ private $ containerMock ;
25+
26+ /**
27+ * @var \PHPUnit_Framework_MockObject_MockObject|\Illuminate\Contracts\Config\Repository
28+ */
29+ private $ configMock ;
30+
31+ /**
32+ * @var string
33+ */
34+ private $ version ;
35+
36+ protected function setUp ()
37+ {
38+ parent ::setUp ();
39+
40+ $ this ->sqsClientMock = $ this
41+ ->getMockBuilder (SqsClient::class)
42+ ->disableOriginalConstructor ()
43+ ->setMethods (['receiveMessage ' ])
44+ ->getMock ();
45+
46+ $ this ->configMock = $ this
47+ ->getMockBuilder (Repository::class)
48+ ->setMethods (['has ' , 'set ' , 'get ' , 'all ' , 'prepend ' , 'push ' ])
49+ ->getMock ();
50+
51+ $ this ->containerMock = $ this
52+ ->getMockBuilder (Container::class)
53+ ->setMethods (['version ' , 'offsetGet ' ])
54+ ->getMock ();
55+
56+ $ this ->containerMock
57+ ->expects ($ this ->any ())
58+ ->method ('offsetGet ' )
59+ ->will ($ this ->returnValue ($ this ->configMock ));
60+
61+ preg_match ("#^\d.\d# " , phpversion (), $ match );
62+
63+ $ this ->version = '5.8.0 ' ;
64+ switch ($ match [0 ]) {
65+ case '5.5 ' :
66+ $ this ->version = '5.0.0 ' ;
67+ break ;
68+ }
69+
70+ $ this ->containerMock
71+ ->expects ($ this ->any ())
72+ ->method ('version ' )
73+ ->will ($ this ->returnValue ($ this ->version ));
74+ }
75+
1476 /**
1577 * @test
1678 */
@@ -35,4 +97,44 @@ public function class_named_is_derived_from_queue_name()
3597
3698 //$response = $method->invokeArgs($queue, [$job]);
3799 }
38- }
100+
101+ public function testSettingJobDisplayName ()
102+ {
103+
104+ $ this ->sqsClientMock
105+ ->expects ($ this ->once ())
106+ ->method ('receiveMessage ' )
107+ ->will ($ this ->returnValue ([
108+ 'Messages ' => [
109+ json_encode ([
110+ 'Body ' => json_encode ([
111+ 'data ' => [
112+ 'foo ' => 'bar '
113+ ]
114+ ])
115+ ])
116+ ]
117+ ]));
118+
119+
120+ $ this ->configMock
121+ ->expects ($ this ->any ())
122+ ->method ('get ' )
123+ ->with ('sqs-plain.handlers ' )
124+ ->will ($ this ->returnValue ([
125+ 'default-queue ' => 'SomeClass '
126+ ]));
127+
128+ $ queue = new Queue ($ this ->sqsClientMock , 'default-queue ' );
129+
130+ $ queue ->setContainer ($ this ->containerMock );
131+
132+ if ($ this ->version !== '5.0.0 ' ) {
133+ $ queue ->setConnectionName ('default-connection ' );
134+ }
135+
136+ $ result = $ queue ->pop ();
137+
138+ $ this ->assertEquals ('SomeClass ' , $ result ->resolveName ());
139+ }
140+ }
0 commit comments