コード例 #1
0
 public function testReadLink()
 {
     $responseMock = $this->getMock('GuzzleHttp\\Psr7\\Response', ['getBody', 'getHeader'], [], '', false);
     $responseMock->expects(self::once())->method('getBody')->will(self::returnValue('body'));
     $responseMock->expects(self::once())->method('getHeader')->will(self::returnValue(array('text/html; UTF-8')));
     $clientMock = $this->getMock('GuzzleHttp\\Client');
     $clientMock->expects(self::once())->method('request')->will(self::returnValue($responseMock));
     $linkMock = $this->getMock('LinkPreview\\Model\\Link', null);
     $reader = new GeneralReader();
     $reader->setClient($clientMock);
     $reader->setLink($linkMock);
     $link = $reader->readLink();
     self::assertEquals('body', $link->getContent());
     self::assertEquals('text/html', $link->getContentType());
 }
コード例 #2
0
 public function testReadLink()
 {
     $responseMock = $this->getMock('Guzzle\\Http\\Message\\Response', ['getBody', 'getContentType', 'getEffectiveUrl'], [], '', false);
     $responseMock->expects(self::once())->method('getBody')->will(self::returnValue('body'));
     $responseMock->expects(self::once())->method('getContentType')->will(self::returnValue('text/html'));
     $responseMock->expects(self::once())->method('getEffectiveUrl')->will(self::returnValue('http://github.com'));
     $requestMock = $this->getMock('Guzzle\\Http\\Message\\Request', ['send'], [], '', false);
     $requestMock->expects(self::once())->method('send')->will(self::returnValue($responseMock));
     $clientMock = $this->getMock('Guzzle\\Http\\Client');
     $clientMock->expects(self::once())->method('get')->will(self::returnValue($requestMock));
     $linkMock = $this->getMock('LinkPreview\\Model\\Link', null);
     $reader = new GeneralReader();
     $reader->setClient($clientMock);
     $reader->setLink($linkMock);
     $link = $reader->readLink();
     self::assertEquals('body', $link->getContent());
     self::assertEquals('text/html', $link->getContentType());
     self::assertEquals('http://github.com', $link->getRealUrl());
 }