/**
  * @test
  */
 public function it_can_explain_every_error()
 {
     foreach ($this->getErrorExplanations() as $errorCode => $explanation) {
         $responseData = ['ok' => false, 'error' => $errorCode];
         /** @var PayloadResponseInterface $actualPayloadResponse */
         $actualPayloadResponse = $this->serializer->deserialize($responseData, $this->getResponseClass());
         $this->assertSame($explanation, $actualPayloadResponse->getErrorExplanation());
     }
 }
 public function testDeserialize()
 {
     $payloadResponse = ['ok' => true, 'error' => null, 'result' => []];
     $mockResponseClass = 'CL\\Slack\\Test\\Payload\\MockPayloadResponse';
     $serializedPayload = $this->payloadResponseSerializer->deserialize($payloadResponse, $mockResponseClass);
     $this->assertInstanceOf($mockResponseClass, $serializedPayload);
     $this->assertTrue($serializedPayload->isOk());
     $this->assertNull($serializedPayload->getError());
     $this->assertNull($serializedPayload->getErrorExplanation());
 }
 /**
  * @test
  */
 public function it_can_be_deserialized()
 {
     $payloadResponse = ['ok' => true, 'error' => null, 'result' => []];
     $mockResponseClass = MockPayloadResponse::class;
     $serializedPayload = $this->payloadResponseSerializer->deserialize($payloadResponse, $mockResponseClass);
     $this->assertInstanceOf($mockResponseClass, $serializedPayload);
     $this->assertTrue($serializedPayload->isOk());
     $this->assertNull($serializedPayload->getError());
     $this->assertNull($serializedPayload->getErrorExplanation());
 }
 /**
  * @test
  */
 public function it_can_be_deserialized()
 {
     $responseData = array_merge(['ok' => true], $this->createResponseData());
     /** @var PayloadResponseInterface $actualPayloadResponse */
     $actualPayloadResponse = $this->serializer->deserialize($responseData, $this->getResponseClass());
     $this->assertInstanceOf('CL\\Slack\\Payload\\PayloadResponseInterface', $actualPayloadResponse);
     $this->assertInstanceOf($this->getResponseClass(), $actualPayloadResponse);
     $this->assertEquals($responseData['ok'], $actualPayloadResponse->isOk());
     if (array_key_exists('error', $responseData)) {
         $this->assertEquals($responseData['error'], $actualPayloadResponse->getError());
         $this->assertInternalType('string', $actualPayloadResponse->getErrorExplanation());
     }
     $this->assertResponse($responseData, $actualPayloadResponse);
 }
Ejemplo n.º 5
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);
     }
 }
Ejemplo n.º 6
0
 /**
  * @param PayloadInterface $payload
  *
  * @return PayloadResponseInterface
  */
 private function sendWithFailure(PayloadInterface $payload)
 {
     $responseData = ['ok' => false, 'error' => 'faked.error'];
     return $this->payloadResponseSerializer->deserialize($responseData, $this->getResponseClass($payload));
 }