|
3 | 3 | use Dapr\PubSub\CloudEvent;
|
4 | 4 | use Dapr\PubSub\Publish;
|
5 | 5 | use Dapr\PubSub\Topic;
|
| 6 | +use CloudEvents\V1\CloudEvent as NewCloudEvent; |
6 | 7 | use DI\DependencyException;
|
7 | 8 | use DI\NotFoundException;
|
8 | 9 |
|
@@ -107,6 +108,60 @@ public function testCloudEventPublish()
|
107 | 108 | );
|
108 | 109 | }
|
109 | 110 |
|
| 111 | + /** |
| 112 | + * @throws DependencyException |
| 113 | + * @throws NotFoundException |
| 114 | + */ |
| 115 | + public function testNewCloudEventPublish() |
| 116 | + { |
| 117 | + $container = $this->get_http_client_stack([new \GuzzleHttp\Psr7\Response(204)]); |
| 118 | + $client = $this->get_new_client_with_http($container->client); |
| 119 | + |
| 120 | + $event = new NewCloudEvent( |
| 121 | + 'id', |
| 122 | + 'source', |
| 123 | + 'type', |
| 124 | + ['my' => 'event'], |
| 125 | + 'application/json', |
| 126 | + null, |
| 127 | + 'subject', |
| 128 | + new DateTimeImmutable('2020-12-12T20:47:00+00:00Z'), |
| 129 | + ); |
| 130 | + |
| 131 | + $topic = new Topic('pubsub', 'test', $client); |
| 132 | + $topic->publish($event); |
| 133 | + |
| 134 | + $publisher = $this->container->make(Publish::class, ['pubsub' => 'pubsub']); |
| 135 | + $this->get_client()->register_post( |
| 136 | + '/publish/pubsub/topic', |
| 137 | + 200, |
| 138 | + null, |
| 139 | + [ |
| 140 | + 'id' => 'id', |
| 141 | + 'source' => 'source', |
| 142 | + 'specversion' => '1.0', |
| 143 | + 'type' => 'type', |
| 144 | + 'datacontenttype' => 'application/json', |
| 145 | + 'subject' => 'subject', |
| 146 | + 'time' => '2020-12-12T20:47:00+00:00Z', |
| 147 | + 'data' => [ |
| 148 | + 'my' => 'event', |
| 149 | + ], |
| 150 | + ] |
| 151 | + ); |
| 152 | + $publisher->topic('topic')->publish($event); |
| 153 | + |
| 154 | + $request = $container->history[0]['request']; |
| 155 | + $this->assertRequestMethod('POST', $request); |
| 156 | + $this->assertRequestUri('/v1.0/publish/pubsub/test', $request); |
| 157 | + $this->assertRequestQueryString('', $request); |
| 158 | + $this->assertRequestHasHeaders(['Content-Type' => 'application/cloudevents+json'], $request); |
| 159 | + $this->assertRequestBody( |
| 160 | + '{"id":"id","source":"source","specversion":"1.0","type":"type","datacontenttype":"application\/json","subject":"subject","time":"2020-12-12T20:47:00+00:00Z","data":{"my":"event"}}', |
| 161 | + $request |
| 162 | + ); |
| 163 | + } |
| 164 | + |
110 | 165 | /**
|
111 | 166 | * @throws Exception
|
112 | 167 | */
|
|
0 commit comments