public function testFactoryLinkAccount()
 {
     $this->somock->shouldReceive('isValid')->once()->andReturn(true);
     $this->somock->shouldReceive('getType')->once()->andReturn(ResponseCardSO::TYPE_LINK_ACCOUNT);
     $this->somock->shouldReceive('getTitle')->never();
     $this->somock->shouldReceive('getContent')->never();
     $instance = ResponseCard::Factory($this->somock);
     $r = new ReflectionClass(ResponseCard::class);
     $p = $r->getProperty('type');
     $p->setAccessible(true);
     $this->assertEquals(ResponseCardSO::TYPE_LINK_ACCOUNT, $p->getValue($instance));
 }
Пример #2
0
 public function testWriteToJsonStreamAll()
 {
     $js = new StreamJSON();
     $r = new ReflectionClass(Response::class);
     $speechSO = new ResponseSpeechSO();
     $speechSO->setType(ResponseSpeechSO::TYPE_PLAIN_TEXT);
     $speechSO->setText('speech text');
     $speech = ResponseSpeech::Factory($speechSO);
     $repromptSO = new ResponseSpeechSO();
     $repromptSO->setType(ResponseSpeechSO::TYPE_SSML);
     $repromptSO->setSsml('<p>sample ssml</p>');
     $reprompt = ResponseSpeech::Factory($repromptSO);
     $cardSO = new ResponseCardSO();
     $cardSO->setType(ResponseCardSO::TYPE_SIMPLE);
     $cardSO->setTitle("Sample Title");
     $cardSO->setContent("this is the content");
     $card = ResponseCard::Factory($cardSO);
     /* @var Response */
     $instance = $r->newInstanceWithoutConstructor();
     $p0 = $r->getProperty('version');
     $p1 = $r->getProperty('sessionAttributes');
     $p2 = $r->getProperty('outputSpeech');
     $p3 = $r->getProperty('reprompt');
     $p4 = $r->getProperty('card');
     $p5 = $r->getProperty('endSession');
     $p0->setAccessible(true);
     $p1->setAccessible(true);
     $p2->setAccessible(true);
     $p3->setAccessible(true);
     $p4->setAccessible(true);
     $p5->setAccessible(true);
     $p0->setValue($instance, '1.0');
     $p1->setValue($instance, ["first" => ["a" => 1, "b" => "2"], "second" => ["c" => null, "d" => true]]);
     $p2->setValue($instance, $speech);
     $p3->setValue($instance, $reprompt);
     $p4->setValue($instance, $card);
     $p5->setValue($instance, true);
     $instance->writeToJsonStream($js);
     $this->assertEquals(json_encode(["version" => "1.0", "sessionAttributes" => ["first" => ["a" => 1, "b" => "2"], "second" => ["c" => null, "d" => true]], "response" => ["shouldEndSession" => true, "outputSpeech" => ["type" => ResponseSpeechSO::TYPE_PLAIN_TEXT, "text" => "speech text"], "reprompt" => ["type" => ResponseSpeechSO::TYPE_SSML, "ssml" => "<p>sample ssml</p>"], "card" => ["type" => ResponseCardSO::TYPE_SIMPLE, "title" => "Sample Title", "content" => "this is the content"]]]), (string) $js);
 }