|  | 
| 1 | 1 | <?php | 
| 2 | 2 | 
 | 
|  | 3 | +use Dapr\DaprClient; | 
| 3 | 4 | use Dapr\PubSub\CloudEvent; | 
| 4 | 5 | use Dapr\PubSub\Publish; | 
| 5 | 6 | use DI\DependencyException; | 
| @@ -27,6 +28,15 @@ public function testSimplePublish() | 
| 27 | 28 |  $publisher->topic('topic')->publish(['my' => 'event']); | 
| 28 | 29 |  } | 
| 29 | 30 | 
 | 
|  | 31 | + public function testBinaryPublish() | 
|  | 32 | + { | 
|  | 33 | + $publisher = $this->container->make(Publish::class, ['pubsub' => 'pubsub']); | 
|  | 34 | + $this->get_client()->register_post('/publish/pubsub/topic', 200, null, 'data'); | 
|  | 35 | + $publisher->topic('topic')->publish('data', content_type: 'application/octet-stream'); | 
|  | 36 | + $client = $this->container->get(DaprClient::class); | 
|  | 37 | + $this->assertSame(['Content-Type: application/octet-stream'], $client->extra_headers); | 
|  | 38 | + } | 
|  | 39 | + | 
| 30 | 40 |  /** | 
| 31 | 41 |  * @throws DependencyException | 
| 32 | 42 |  * @throws NotFoundException | 
| @@ -83,4 +93,24 @@ public function testParsingCloudEvent() | 
| 83 | 93 |  $this->assertTrue($event->validate()); | 
| 84 | 94 |  $this->assertSame('https://example.com/message', $event->source); | 
| 85 | 95 |  } | 
|  | 96 | + | 
|  | 97 | + public function testParsingBinaryEvent() | 
|  | 98 | + { | 
|  | 99 | + $eventjson = <<<JSON | 
|  | 100 | +{ | 
|  | 101 | + "specversion" : "1.0", | 
|  | 102 | + "type" : "xml.message", | 
|  | 103 | + "source" : "https://example.com/message", | 
|  | 104 | + "subject" : "Test binary Message", | 
|  | 105 | + "id" : "id-1234-5678-9101", | 
|  | 106 | + "time" : "2020-09-23T06:23:21Z", | 
|  | 107 | + "datacontenttype" : "application/octet-stream", | 
|  | 108 | + "data" : "ZGF0YQ==", | 
|  | 109 | + "data_base64": "ZGF0YQ==" | 
|  | 110 | +} | 
|  | 111 | +JSON; | 
|  | 112 | + $event = CloudEvent::parse($eventjson); | 
|  | 113 | + $this->assertTrue($event->validate()); | 
|  | 114 | + $this->assertSame('data', $event->data); | 
|  | 115 | + } | 
| 86 | 116 | } | 
0 commit comments