update v1.0.7.9 R.C.

This is a Release Candidate. We are still testing.
This commit is contained in:
Sujit Prasad
2016-08-03 20:04:36 +05:30
parent 8b6b924d09
commit ffa56a43cb
3830 changed files with 181529 additions and 495353 deletions

View File

@@ -0,0 +1,2 @@
phpunit.xml
TestConfiguration.php

View File

@@ -0,0 +1,93 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend
*/
/*
* Set error reporting to the level to which Zend Framework code must comply.
*/
error_reporting(E_ALL | E_STRICT);
if (class_exists('PHPUnit_Runner_Version', true)) {
$phpUnitVersion = PHPUnit_Runner_Version::id();
if ('@package_version@' !== $phpUnitVersion && version_compare($phpUnitVersion, '3.7.0', '<')) {
echo 'This version of PHPUnit (' . PHPUnit_Runner_Version::id() . ') is not supported in Zend Framework 2.x unit tests.' . PHP_EOL;
exit(1);
}
unset($phpUnitVersion);
}
/*
* Determine the root, library, and tests directories of the framework
* distribution.
*/
$zfRoot = realpath(dirname(__DIR__));
$zfCoreLibrary = "$zfRoot/library";
$zfCoreTests = "$zfRoot/tests";
/*
* Prepend the Zend Framework library/ and tests/ directories to the
* include_path. This allows the tests to run out of the box and helps prevent
* loading other copies of the framework code and tests that would supersede
* this copy.
*/
$path = array(
$zfCoreLibrary,
$zfCoreTests,
get_include_path(),
);
set_include_path(implode(PATH_SEPARATOR, $path));
/**
* Setup autoloading
*/
include __DIR__ . '/_autoload.php';
/*
* Load the user-defined test configuration file, if it exists; otherwise, load
* the default configuration.
*/
if (is_readable($zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php')) {
require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php';
} else {
require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php.dist';
}
if (defined('TESTS_GENERATE_REPORT') && TESTS_GENERATE_REPORT === true) {
$codeCoverageFilter = new PHP_CodeCoverage_Filter();
$lastArg = end($_SERVER['argv']);
if (is_dir($zfCoreTests . '/' . $lastArg)) {
$codeCoverageFilter->addDirectoryToWhitelist($zfCoreLibrary . '/' . $lastArg);
} elseif (is_file($zfCoreTests . '/' . $lastArg)) {
$codeCoverageFilter->addDirectoryToWhitelist(dirname($zfCoreLibrary . '/' . $lastArg));
} else {
$codeCoverageFilter->addDirectoryToWhitelist($zfCoreLibrary);
}
/*
* Omit from code coverage reports the contents of the tests directory
*/
$codeCoverageFilter->addDirectoryToBlacklist($zfCoreTests, '');
$codeCoverageFilter->addDirectoryToBlacklist(PEAR_INSTALL_DIR, '');
$codeCoverageFilter->addDirectoryToBlacklist(PHP_LIBDIR, '');
unset($codeCoverageFilter);
}
/**
* Start output buffering, if enabled
*/
if (defined('TESTS_ZEND_OB_ENABLED') && constant('TESTS_ZEND_OB_ENABLED')) {
ob_start();
}
/*
* Unset global variables that are no longer needed.
*/
unset($zfRoot, $zfCoreLibrary, $zfCoreTests, $path);

View File

@@ -0,0 +1,45 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package UnitTests
*/
/**
* This file defines configuration for running the unit tests for the Zend
* Framework. Some tests have dependencies to PHP extensions or databases
* which may not necessary installed on the target system. For these cases,
* the ability to disable or configure testing is provided below. Tests for
* components which should run universally are always run by the master
* suite and cannot be disabled.
*
* Do not edit this file. Instead, copy this file to TestConfiguration.php,
* and edit the new file. Never commit passwords to the source code repository.
*/
/**
* Use the notation:
*
* defined(...) || define(...);
*
* This ensures that, when a test is marked to run in a separate process,
* PHP will not complain of a constant already being defined.
*/
/**
* GENERAL SETTINGS
*
* OB_ENABLED should be enabled for some tests to check if all functionality
* works as expected. Such tests include those for Zend\Soap and Zend\Session,
* which require that headers not be sent in order to work.
*/
defined('TESTS_ZEND_OB_ENABLED') || define('TESTS_ZEND_OB_ENABLED', false);
/**
* PHPUnit Code Coverage / Test Report
*/
defined('TESTS_GENERATE_REPORT') || define('TESTS_GENERATE_REPORT', false);
defined('TESTS_GENERATE_REPORT_TARGET') || define('TESTS_GENERATE_REPORT_TARGET', '/path/to/target');

View File

@@ -0,0 +1,20 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package UnitTests
*/
/**
* This file defines specific configuration that differs from the standard configuration
* for running the unit tests with Travis-CI (http://www.travis-ci.org)
*
* See TestConfiguration.php.dist to get more details.
*
* Never commit passwords to the source code repository.
*/
require_once __DIR__ . '/TestConfiguration.php.dist';

View File

@@ -0,0 +1,48 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Service
*/
namespace ZendServiceTest\Apple\Apns;
use ZendServiceTest\Apple\Apns\TestAsset\FeedbackClient;
/**
* @category ZendService
* @package ZendService_Apple
* @subpackage UnitTests
* @group ZendService
* @group ZendService_Apple
* @group ZendService_Apple_Apns
*/
class FeedbackClientTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->apns = new FeedbackClient();
}
protected function setupValidBase()
{
$this->apns->open(FeedbackClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
}
public function testFeedback()
{
$this->setupValidBase();
$time = time();
$token = 'abc123';
$length = strlen($token) / 2;
$this->apns->setReadResponse(pack('NnH*', $time, $length, $token));
$response = $this->apns->feedback();
$this->assertCount(1, $response);
$feedback = array_shift($response);
$this->assertEquals($time, $feedback->getTime());
$this->assertEquals($token, $feedback->getToken());
}
}

View File

@@ -0,0 +1,176 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @category ZendService
* @package ZendService_Apple
* @subpackage UnitTests
*/
namespace ZendServiceTest\Apple\Apns;
use ZendServiceTest\Apple\Apns\TestAsset\MessageClient;
use ZendService\Apple\Apns\Message;
use ZendService\Apple\Apns\Response\Message as MessageResponse;
/**
* @category ZendService
* @package ZendService_Apple
* @subpackage UnitTests
* @group ZendService
* @group ZendService_Apple
* @group ZendService_Apple_Apns
*/
class MessageClientTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->apns = new MessageClient();
$this->message = new Message();
}
protected function setupValidBase()
{
$this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
$this->message->setToken('662cfe5a69ddc65cdd39a1b8f8690647778204b064df7b264e8c4c254f94fdd8');
$this->message->setId(time());
$this->message->setAlert('bar');
}
public function testConnectThrowsExceptionOnInvalidEnvironment()
{
$this->setExpectedException('InvalidArgumentException');
$this->apns->open(5, __DIR__ . '/TestAsset/certificate.pem');
}
public function testSetCertificateThrowsExceptionOnNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, array('foo'));
}
public function testSetCertificateThrowsExceptionOnMissingFile()
{
$this->setExpectedException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, 'foo');
}
public function testSetCertificatePassphraseThrowsExceptionOnNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, __DIR__ . '/TestAsset/certificate.pem', array('foo'));
}
public function testOpen()
{
$ret = $this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
$this->assertEquals($this->apns, $ret);
$this->assertTrue($this->apns->isConnected());
}
public function testClose()
{
$this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
$this->apns->close();
$this->assertFalse($this->apns->isConnected());
}
public function testOpenWhenAlreadyOpenThrowsException()
{
$this->setExpectedException('RuntimeException');
$this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
$this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
}
public function testSendReturnsTrueOnSuccess()
{
$this->setupValidBase();
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_OK, $response->getCode());
$this->assertNull($response->getId());
}
public function testSendResponseOnProcessingError()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 1, 1, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_PROCESSING_ERROR, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnMissingToken()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 2, 2, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_MISSING_TOKEN, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnMissingTopic()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 3, 3, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_MISSING_TOPIC, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnMissingPayload()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 4, 4, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_MISSING_PAYLOAD, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnInvalidTokenSize()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 5, 5, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_INVALID_TOKEN_SIZE, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnInvalidTopicSize()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 6, 6, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_INVALID_TOPIC_SIZE, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnInvalidPayloadSize()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 7, 7, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_INVALID_PAYLOAD_SIZE, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnInvalidToken()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 8, 8, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_INVALID_TOKEN, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnUnknownError()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 255, 255, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_UNKNOWN_ERROR, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
}

View File

@@ -0,0 +1,275 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Service
*/
namespace ZendServiceTest\Apple\Apns\TestAsset;
use ZendService\Apple\Apns\Message;
use ZendService\Apple\Apns\Message\Alert;
use Zend\Json\Encoder as JsonEncoder;
/**
* @category ZendService
* @package ZendService_Apple
* @subpackage UnitTests
* @group ZendService
* @group ZendService_Apple
* @group ZendService_Apple_Apns
*/
class MessageTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->alert = new Alert();
$this->message = new Message();
}
public function testSetAlertTextReturnsCorrectly()
{
$text = 'my alert';
$ret = $this->message->setAlert($text);
$this->assertInstanceOf('ZendService\Apple\Apns\Message', $ret);
$checkText = $this->message->getAlert();
$this->assertInstanceOf('ZendService\Apple\Apns\Message\Alert', $checkText);
$this->assertEquals($text, $checkText->getBody());
}
public function testSetAlertThrowsExceptionOnTextNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setAlert(array());
}
public function testSetAlertThrowsExceptionOnActionLocKeyNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->alert->setActionLocKey(array());
}
public function testSetAlertThrowsExceptionOnLocKeyNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->alert->setLocKey(array());
}
public function testSetAlertThrowsExceptionOnLaunchImageNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->alert->setLaunchImage(array());
}
public function testSetAlertThrowsExceptionOnTitleNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->alert->setTitle(array());
}
public function testSetAlertThrowsExceptionOnTitleLocKeyNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->alert->setTitleLocKey(array());
}
public function testSetBadgeReturnsCorrectNumber()
{
$num = 5;
$this->message->setBadge($num);
$this->assertEquals($num, $this->message->getBadge());
}
public function testSetBadgeNonNumericThrowsException()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setBadge('string!');
}
public function testSetBadgeAllowsNull()
{
$this->message->setBadge(null);
$this->assertNull($this->message->getBadge());
}
public function testSetExpireReturnsInteger()
{
$expire = 100;
$this->message->setExpire($expire);
$this->assertEquals($expire, $this->message->getExpire());
}
public function testSetExpireNonNumericThrowsException()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setExpire('sting!');
}
public function testSetSoundReturnsString()
{
$sound = 'test';
$this->message->setSound($sound);
$this->assertEquals($sound, $this->message->getSound());
}
public function testSetSoundThrowsExceptionOnNonScalar()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setSound(array());
}
public function testSetSoundThrowsExceptionOnNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setSound(12345);
}
public function testSetContentAvailableThrowsExceptionOnNonInteger()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setContentAvailable("string");
}
public function testGetContentAvailableReturnsCorrectInteger()
{
$value = 1;
$this->message->setContentAvailable($value);
$this->assertEquals($value, $this->message->getContentAvailable());
}
public function testSetContentAvailableResultsInCorrectPayload()
{
$value = 1;
$this->message->setContentAvailable($value);
$payload = $this->message->getPayload();
$this->assertEquals($value, $payload['aps']['content-available']);
}
public function testSetCategoryReturnsString()
{
$category = 'test';
$this->message->setCategory($category);
$this->assertEquals($category, $this->message->getCategory());
}
public function testSetCategoryThrowsExceptionOnNonScalar()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setCategory(array());
}
public function testSetCategoryThrowsExceptionOnNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setCategory(12345);
}
public function testSetUrlArgsReturnsString()
{
$urlArgs = array('path/to/somewhere');
$this->message->setUrlArgs($urlArgs);
$this->assertEquals($urlArgs, $this->message->getUrlArgs());
}
public function testSetCustomData()
{
$data = array('key' => 'val', 'key2' => array(1, 2, 3, 4, 5));
$this->message->setCustom($data);
$this->assertEquals($data, $this->message->getCustom());
}
public function testAlertConstructor()
{
$alert = new Alert(
'Foo wants to play Bar!',
'PLAY',
'GAME_PLAY_REQUEST_FORMAT',
array('Foo', 'Baz'),
'Default.png',
'Alert',
'ALERT',
array('Foo', 'Baz')
);
$this->assertEquals('Foo wants to play Bar!', $alert->getBody());
$this->assertEquals('PLAY', $alert->getActionLocKey());
$this->assertEquals('GAME_PLAY_REQUEST_FORMAT', $alert->getLocKey());
$this->assertEquals(array('Foo', 'Baz'), $alert->getLocArgs());
$this->assertEquals('Default.png', $alert->getLaunchImage());
$this->assertEquals('Alert', $alert->getTitle());
$this->assertEquals('ALERT', $alert->getTitleLocKey());
$this->assertEquals(array('Foo', 'Baz'), $alert->getTitleLocArgs());
}
public function testAlertJsonPayload()
{
$alert = new Alert(
'Foo wants to play Bar!',
'PLAY',
'GAME_PLAY_REQUEST_FORMAT',
array('Foo', 'Baz'),
'Default.png',
'Alert',
'ALERT',
array('Foo', 'Baz')
);
$payload = $alert->getPayload();
$this->assertArrayHasKey('body', $payload);
$this->assertArrayHasKey('action-loc-key', $payload);
$this->assertArrayHasKey('loc-key', $payload);
$this->assertArrayHasKey('loc-args', $payload);
$this->assertArrayHasKey('launch-image', $payload);
$this->assertArrayHasKey('title', $payload);
$this->assertArrayHasKey('title-loc-key', $payload);
$this->assertArrayHasKey('title-loc-args', $payload);
}
public function testAlertPayloadSendsOnlyBody()
{
$alert = new Alert('Foo wants Bar');
$payload = $alert->getPayload();
$this->assertEquals('Foo wants Bar', $payload);
}
public function testPayloadJsonFormedCorrectly()
{
$text = 'hi=привет';
$this->message->setAlert($text);
$this->message->setId(1);
$this->message->setExpire(100);
$this->message->setToken('0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');
$payload = $this->message->getPayload();
$this->assertEquals($payload, array('aps' => array('alert' => 'hi=привет')));
if (defined('JSON_UNESCAPED_UNICODE')) {
$payloadJson = json_encode($payload, JSON_UNESCAPED_UNICODE);
$this->assertEquals($payloadJson, '{"aps":{"alert":"hi=привет"}}');
$length = 35; // 23 + (2 * 6) because UTF-8 (Russian) "привет" contains 2 bytes per letter
$result = pack('CNNnH*', 1, $this->message->getId(), $this->message->getExpire(), 32, $this->message->getToken())
. pack('n', $length)
. $payloadJson;
$this->assertEquals($this->message->getPayloadJson(), $result);
} else {
$payloadJson = JsonEncoder::encode($payload);
$this->assertEquals($payloadJson, '{"aps":{"alert":"hi=\u043f\u0440\u0438\u0432\u0435\u0442"}}');
$length = 59; // (23 + (6 * 6) because UTF-8 (Russian) "привет" converts into 6 bytes per letter constructions
$result = pack('CNNnH*', 1, $this->message->getId(), $this->message->getExpire(), 32, $this->message->getToken())
. pack('n', $length)
. $payloadJson;
$this->assertEquals($this->message->getPayloadJson(), $result);
}
}
public function testCustomDataPayloadDoesNotIncludeEmptyApsData()
{
$data = array('custom' => 'data');
$this->message->setCustom($data);
$payload = $this->message->getPayload();
$this->assertEquals($payload, array('custom' => 'data'));
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Service
*/
namespace ZendServiceTest\Apple\Apns\TestAsset;
use ZendService\Apple\Apns\Exception;
use ZendService\Apple\Apns\Client\Feedback as ZfFeedbackClient;
/**
* Feedback Client Proxy
* This class is utilized for unit testing purposes
*
* @category ZendService
* @package ZendService_Apple
* @subpackage Apns
*/
class FeedbackClient extends ZfFeedbackClient
{
/**
* Read Response
*
* @var string
*/
protected $readResponse;
/**
* Write Response
*
* @var mixed
*/
protected $writeResponse;
/**
* Set the Response
*
* @param string $str
* @return FeedbackClient
*/
public function setReadResponse($str)
{
$this->readResponse = $str;
return $this;
}
/**
* Set the write response
*
* @param mixed $resp
* @return FeedbackClient
*/
public function setWriteResponse($resp)
{
$this->writeResponse = $resp;
return $this;
}
/**
* Connect to Host
*
* @return FeedbackClient
*/
protected function connect($host, array $ssl)
{
return $this;
}
/**
* Return Response
*
* @param string $length
* @return string
*/
protected function read($length = 1024)
{
if (!$this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to reading data');
}
$ret = substr($this->readResponse, 0, $length);
$this->readResponse = null;
return $ret;
}
/**
* Write and Return Length
*
* @param string $payload
* @return int
*/
protected function write($payload)
{
if (!$this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to writing data');
}
$ret = $this->writeResponse;
$this->writeResponse = null;
return (null === $ret) ? strlen($payload) : $ret;
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Service
*/
namespace ZendServiceTest\Apple\Apns\TestAsset;
use ZendService\Apple\Apns\Exception;
use ZendService\Apple\Apns\Client\Message as ZfMessageClient;
/**
* Message Client Proxy
* This class is utilized for unit testing purposes
*
* @category ZendService
* @package ZendService_Apple
* @subpackage Apns
*/
class MessageClient extends ZfMessageClient
{
/**
* Read Response
*
* @var string
*/
protected $readResponse;
/**
* Write Response
*
* @var mixed
*/
protected $writeResponse;
/**
* Set the Response
*
* @param string $str
* @return MessageClient
*/
public function setReadResponse($str)
{
$this->readResponse = $str;
return $this;
}
/**
* Set the write response
*
* @param mixed $resp
* @return MessageClient
*/
public function setWriteResponse($resp)
{
$this->writeResponse = $resp;
return $this;
}
/**
* Connect to Host
*
* @return MessageClient
*/
protected function connect($host, array $ssl)
{
return $this;
}
/**
* Return Response
*
* @param string $length
* @return string
*/
protected function read($length = 1024)
{
if (!$this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to reading data');
}
$ret = substr($this->readResponse, 0, $length);
$this->readResponse = null;
return $ret;
}
/**
* Write and Return Length
*
* @param string $payload
* @return int
*/
protected function write($payload)
{
if (!$this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to writing data');
}
$ret = $this->writeResponse;
$this->writeResponse = null;
return (null === $ret) ? strlen($payload) : $ret;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Setup autoloading
*/
if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
throw new RuntimeException('This component has dependencies that are unmet.
Please install composer (http://getcomposer.org), and run the following
command in the root of this project:
php /path/to/composer.phar install
After that, you should be able to run tests.');
}
include_once __DIR__ . '/../vendor/autoload.php';
spl_autoload_register(function ($class) {
if (0 !== strpos($class, 'ZendServiceTest\\')) {
return false;
}
$normalized = str_replace('ZendServiceTest\\', '', $class);
$filename = __DIR__ . '/ZendService/' . str_replace(array('\\', '_'), '/', $normalized) . '.php';
if (!file_exists($filename)) {
return false;
}
return include_once $filename;
});

View File

@@ -0,0 +1,13 @@
<phpunit bootstrap="./Bootstrap.php" colors="true">
<testsuites>
<testsuite name="ZendService Apple Apns Test Suite">
<directory>./ZendService</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>disable</group>
</exclude>
</groups>
</phpunit>