Exemplo n.º 1
0
 public function testPayload()
 {
     $payload = $this->createPayload();
     $this->assertInternalType('string', $payload->getMethod());
     $this->assertTrue(class_exists($payload->getResponseClass()));
     $expectedPayloadSerialized = json_encode($this->getExpectedPayloadData($payload));
     $actualPayloadSerialized = json_encode($this->payloadSerializer->serialize($payload));
     $this->assertEquals(json_decode($expectedPayloadSerialized, true), json_decode($actualPayloadSerialized, true));
 }
 public function testSerialize()
 {
     $payload = new MockPayload();
     $payload->setFoo('bar');
     $serializedPayload = $this->payloadSerializer->serialize($payload);
     $this->assertInternalType('array', $serializedPayload);
     $this->assertArrayHasKey('foo', $serializedPayload);
     $this->assertEquals('bar', $serializedPayload['foo']);
 }
Exemplo n.º 3
0
 /**
  * @test
  */
 public function it_can_be_serialized()
 {
     $payload = new PayloadMock();
     $payload->setFruit('apple');
     $serializedPayload = $this->payloadSerializer->serialize($payload);
     $this->assertInternalType('array', $serializedPayload);
     $this->assertArrayHasKey('fruit', $serializedPayload);
     $this->assertEquals($payload->getFruit(), $serializedPayload['fruit']);
 }
Exemplo n.º 4
0
 /**
  * @param PayloadInterface $payload The payload to send
  * @param string|null      $token   Optional token to use during the API-call,
  *                                  defaults to the one configured during construction
  *
  * @throws SlackException If the payload could not be sent
  *
  * @return PayloadResponseInterface Actual class depends on the payload used,
  *                                  e.g. chat.postMessage will return an instance of ChatPostMessagePayloadResponse
  */
 public function send(PayloadInterface $payload, $token = null)
 {
     try {
         if ($token === null && $this->token === null) {
             throw new \InvalidArgumentException('You must supply a token to send a payload, since you did not provide one during construction');
         }
         $serializedPayload = $this->payloadSerializer->serialize($payload);
         $responseData = $this->doSend($payload->getMethod(), $serializedPayload, $token);
         return $this->payloadResponseSerializer->deserialize($responseData, $payload->getResponseClass());
     } catch (\Exception $e) {
         throw new SlackException('Failed to send payload', null, $e);
     }
 }