Skip to content

Commit 8c8e457

Browse files
committed
Update tests for new client
1 parent b7888f6 commit 8c8e457

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/lib/PubSub/Topic.php

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function publish(mixed $event, ?array $metadata = null, string $content_t
3939
$this->client->logger->debug('Sending {event} to {topic}', ['event' => $event, 'topic' => $this->topic]);
4040
}
4141
if ($event instanceof CloudEvent) {
42+
$content_type = 'application/cloudevents+json';
4243
$this->client->extra_headers = [
4344
'Content-Type: application/cloudevents+json',
4445
];

tests/PublishTest.php

+38-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use Dapr\DaprClient;
43
use Dapr\PubSub\CloudEvent;
54
use Dapr\PubSub\Publish;
65
use Dapr\PubSub\Topic;
@@ -21,15 +20,27 @@ class PublishTest extends DaprTests
2120
public function testSimplePublish()
2221
{
2322
$client = $this->get_new_client();
24-
$client->expects($this->once())->method('publishEvent')->with();
23+
$client->expects($this->once())->method('publishEvent')->with(
24+
$this->equalTo('pubsub'),
25+
$this->equalTo('topic'),
26+
$this->equalTo(['my' => 'event']),
27+
$this->equalTo([]),
28+
$this->equalTo('application/json')
29+
);
2530
$topic = new Topic('pubsub', 'topic', $client);
2631
$topic->publish(['my' => 'event']);
2732
}
2833

2934
public function testBinaryPublish()
3035
{
3136
$client = $this->get_new_client();
32-
$client->expects($this->once())->method('publishEvent');
37+
$client->expects($this->once())->method('publishEvent')->with(
38+
$this->equalTo('pubsub'),
39+
$this->equalTo('test'),
40+
$this->equalTo('data'),
41+
$this->equalTo([]),
42+
$this->equalTo('application/octet-stream')
43+
);
3344
$topic = new Topic('pubsub', 'test', $client);
3445
$topic->publish('data', content_type: 'application/octet-stream');
3546
}
@@ -40,7 +51,6 @@ public function testBinaryPublish()
4051
*/
4152
public function testCloudEventPublish()
4253
{
43-
$publisher = $this->container->make(Publish::class, ['pubsub' => 'pubsub']);
4454
$event = new CloudEvent();
4555
$event->data = ['my' => 'event'];
4656
$event->type = 'type';
@@ -49,6 +59,30 @@ public function testCloudEventPublish()
4959
$event->data_content_type = 'application/json';
5060
$event->source = 'source';
5161
$event->time = new DateTime('2020-12-12T20:47:00+00:00Z');
62+
63+
$client = $this->get_new_client();
64+
$client->expects($this->once())->method('publishEvent')->with(
65+
$this->equalTo('pubsub'),
66+
$this->equalTo('test'),
67+
$this->equalTo([
68+
'id' => 'id',
69+
'source' => 'source',
70+
'specversion' => '1.0',
71+
'type' => 'type',
72+
'datacontenttype' => 'application/json',
73+
'subject' => 'subject',
74+
'time' => '2020-12-12T20:47:00+00:00Z',
75+
'data' => [
76+
'my' => 'event',
77+
],
78+
]),
79+
$this->equalTo([]),
80+
$this->equalTo('application/cloudevents+json')
81+
);
82+
$topic = new Topic('pubsub', 'test', $client);
83+
$topic->publish($event);
84+
85+
$publisher = $this->container->make(Publish::class, ['pubsub' => 'pubsub']);
5286
$this->get_client()->register_post(
5387
'/publish/pubsub/topic',
5488
200,

0 commit comments

Comments
 (0)