Laravel version update
Laravel version update
This commit is contained in:
		| @@ -1,217 +0,0 @@ | ||||
| <?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_Google | ||||
|  * @subpackage UnitTests | ||||
|  */ | ||||
|  | ||||
| namespace ZendServiceTest\Google\Gcm; | ||||
|  | ||||
| use Zend\Http\Client\Adapter\Test; | ||||
| use Zend\Http\Client as HttpClient; | ||||
| use ZendService\Google\Gcm\Client; | ||||
| use ZendService\Google\Gcm\Message; | ||||
| use ZendService\Google\Gcm\Response; | ||||
|  | ||||
| /** | ||||
|  * @category   ZendService | ||||
|  * @package    ZendService_Google | ||||
|  * @subpackage UnitTests | ||||
|  * @group      ZendService | ||||
|  * @group      ZendService_Google | ||||
|  * @group      ZendService_Google_Gcm | ||||
|  */ | ||||
| class ClientTest extends \PHPUnit_Framework_TestCase | ||||
| { | ||||
|     protected $httpAdapter; | ||||
|     protected $httpClient; | ||||
|     protected $gcmClient; | ||||
|     protected $message; | ||||
|  | ||||
|     protected function _createJSONResponse($id, $success, $failure, $ids, $results) | ||||
|     { | ||||
|         return json_encode(array( | ||||
|             'multicast_id' => $id, | ||||
|             'success' => $success, | ||||
|             'failure' => $failure, | ||||
|             'canonical_ids' => $ids, | ||||
|             'results' => $results | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     public function setUp() | ||||
|     { | ||||
|         $this->httpClient = new HttpClient(); | ||||
|         $this->httpAdapter = new Test(); | ||||
|         $this->httpClient->setAdapter($this->httpAdapter); | ||||
|         $this->gcmClient = new Client(); | ||||
|         $this->gcmClient->setHttpClient($this->httpClient); | ||||
|         $this->gcmClient->setApiKey('testing'); | ||||
|         $this->message = new Message(); | ||||
|         $this->message->addRegistrationId('testing'); | ||||
|         $this->message->addData('testKey', 'testValue'); | ||||
|     } | ||||
|  | ||||
|     public function testSetApiKeyThrowsExceptionOnNonString() | ||||
|     { | ||||
|         $this->setExpectedException('InvalidArgumentException'); | ||||
|         $this->gcmClient->setApiKey(array()); | ||||
|     } | ||||
|  | ||||
|     public function testSetApiKey() | ||||
|     { | ||||
|         $key = 'a-login-token'; | ||||
|         $this->gcmClient->setApiKey($key); | ||||
|         $this->assertEquals($key, $this->gcmClient->getApiKey()); | ||||
|     } | ||||
|  | ||||
|     public function testGetHttpClientReturnsDefault() | ||||
|     { | ||||
|         $gcm = new Client(); | ||||
|         $this->assertEquals('Zend\Http\Client', get_class($gcm->getHttpClient())); | ||||
|         $this->assertTrue($gcm->getHttpClient() instanceof HttpClient); | ||||
|     } | ||||
|  | ||||
|     public function testSetHttpClient() | ||||
|     { | ||||
|         $client = new HttpClient(); | ||||
|         $this->gcmClient->setHttpClient($client); | ||||
|         $this->assertEquals($client, $this->gcmClient->getHttpClient()); | ||||
|     } | ||||
|  | ||||
|     public function testSendThrowsExceptionWhenServiceUnavailable() | ||||
|     { | ||||
|         $this->setExpectedException('RuntimeException'); | ||||
|         $this->httpAdapter->setResponse('HTTP/1.1 503 Service Unavailable' . "\r\n\r\n"); | ||||
|         $this->gcmClient->send($this->message); | ||||
|     } | ||||
|  | ||||
|     public function testSendThrowsExceptionWhenServerUnavailable() | ||||
|     { | ||||
|         $this->setExpectedException('RuntimeException'); | ||||
|         $this->httpAdapter->setResponse('HTTP/1.1 500 Internal Server Error' . "\r\n\r\n"); | ||||
|         $this->gcmClient->send($this->message); | ||||
|     } | ||||
|  | ||||
|     public function testSendThrowsExceptionWhenInvalidAuthToken() | ||||
|     { | ||||
|         $this->setExpectedException('RuntimeException'); | ||||
|         $this->httpAdapter->setResponse('HTTP/1.1 401 Unauthorized' . "\r\n\r\n"); | ||||
|         $this->gcmClient->send($this->message); | ||||
|     } | ||||
|  | ||||
|     public function testSendThrowsExceptionWhenInvalidPayload() | ||||
|     { | ||||
|         $this->setExpectedException('RuntimeException'); | ||||
|         $this->httpAdapter->setResponse('HTTP/1.1 400 Bad Request' . "\r\n\r\n"); | ||||
|         $this->gcmClient->send($this->message); | ||||
|     } | ||||
|  | ||||
|     public function testSendResultInvalidRegistrationId() | ||||
|     { | ||||
|         $body = $this->_createJSONResponse(101, 0, 1, 0, array(array('error' => 'InvalidRegistration'))); | ||||
|         $this->httpAdapter->setResponse( | ||||
|             'HTTP/1.1 200 OK' . "\r\n" . | ||||
|             'Context-Type: text/html' . "\r\n\r\n" . | ||||
|             $body | ||||
|         ); | ||||
|         $response = $this->gcmClient->send($this->message); | ||||
|         $result = $response->getResults(); | ||||
|         $result = array_shift($result); | ||||
|         $this->assertEquals('InvalidRegistration', $result['error']); | ||||
|         $this->assertEquals(0, $response->getSuccessCount()); | ||||
|         $this->assertEquals(0, $response->getCanonicalCount()); | ||||
|         $this->assertEquals(1, $response->getFailureCount()); | ||||
|     } | ||||
|  | ||||
|     public function testSendResultMismatchSenderId() | ||||
|     { | ||||
|         $body = $this->_createJSONResponse(101, 0, 1, 0, array(array('error' => 'MismatchSenderId'))); | ||||
|         $this->httpAdapter->setResponse( | ||||
|             'HTTP/1.1 200 OK' . "\r\n" . | ||||
|             'Context-Type: text/html' . "\r\n\r\n" . | ||||
|             $body | ||||
|         ); | ||||
|         $response = $this->gcmClient->send($this->message); | ||||
|         $result = $response->getResults(); | ||||
|         $result = array_shift($result); | ||||
|         $this->assertEquals('MismatchSenderId', $result['error']); | ||||
|         $this->assertEquals(0, $response->getSuccessCount()); | ||||
|         $this->assertEquals(0, $response->getCanonicalCount()); | ||||
|         $this->assertEquals(1, $response->getFailureCount()); | ||||
|     } | ||||
|  | ||||
|     public function testSendResultNotRegistered() | ||||
|     { | ||||
|         $body = $this->_createJSONResponse(101, 0, 1, 0, array(array('error' => 'NotRegistered'))); | ||||
|         $this->httpAdapter->setResponse( | ||||
|             'HTTP/1.1 200 OK' . "\r\n" . | ||||
|             'Context-Type: text/html' . "\r\n\r\n" . | ||||
|             $body | ||||
|         ); | ||||
|         $response = $this->gcmClient->send($this->message); | ||||
|         $result = $response->getResults(); | ||||
|         $result = array_shift($result); | ||||
|         $this->assertEquals('NotRegistered', $result['error']); | ||||
|         $this->assertEquals(0, $response->getSuccessCount()); | ||||
|         $this->assertEquals(0, $response->getCanonicalCount()); | ||||
|         $this->assertEquals(1, $response->getFailureCount()); | ||||
|     } | ||||
|  | ||||
|     public function testSendResultMessageTooBig() | ||||
|     { | ||||
|         $body = $this->_createJSONResponse(101, 0, 1, 0, array(array('error' => 'MessageTooBig'))); | ||||
|         $this->httpAdapter->setResponse( | ||||
|             'HTTP/1.1 200 OK' . "\r\n" . | ||||
|             'Context-Type: text/html' . "\r\n\r\n" . | ||||
|             $body | ||||
|         ); | ||||
|         $response = $this->gcmClient->send($this->message); | ||||
|         $result = $response->getResults(); | ||||
|         $result = array_shift($result); | ||||
|         $this->assertEquals('MessageTooBig', $result['error']); | ||||
|         $this->assertEquals(0, $response->getSuccessCount()); | ||||
|         $this->assertEquals(0, $response->getCanonicalCount()); | ||||
|         $this->assertEquals(1, $response->getFailureCount()); | ||||
|     } | ||||
|  | ||||
|     public function testSendResultSuccessful() | ||||
|     { | ||||
|         $body = $this->_createJSONResponse(101, 1, 0, 0, array(array('message_id' => '1:2342'))); | ||||
|         $this->httpAdapter->setResponse( | ||||
|             'HTTP/1.1 200 OK' . "\r\n" . | ||||
|             'Context-Type: text/html' . "\r\n\r\n" . | ||||
|             $body | ||||
|         ); | ||||
|         $response = $this->gcmClient->send($this->message); | ||||
|         $result = $response->getResults(); | ||||
|         $result = array_shift($result); | ||||
|         $this->assertEquals('1:2342', $result['message_id']); | ||||
|         $this->assertEquals(1, $response->getSuccessCount()); | ||||
|         $this->assertEquals(0, $response->getCanonicalCount()); | ||||
|         $this->assertEquals(0, $response->getFailureCount()); | ||||
|     } | ||||
|  | ||||
|     public function testSendResultSuccessfulWithRegistrationId() | ||||
|     { | ||||
|         $body = $this->_createJSONResponse(101, 1, 0, 1, array(array('message_id' => '1:2342', 'registration_id' => 'testfoo'))); | ||||
|         $this->httpAdapter->setResponse( | ||||
|             'HTTP/1.1 200 OK' . "\r\n" . | ||||
|             'Context-Type: text/html' . "\r\n\r\n" . | ||||
|             $body | ||||
|         ); | ||||
|         $response = $this->gcmClient->send($this->message); | ||||
|         $result = $response->getResults(); | ||||
|         $result = array_shift($result); | ||||
|         $this->assertEquals('1:2342', $result['message_id']); | ||||
|         $this->assertEquals('testfoo', $result['registration_id']); | ||||
|         $this->assertEquals(1, $response->getSuccessCount()); | ||||
|         $this->assertEquals(1, $response->getCanonicalCount()); | ||||
|         $this->assertEquals(0, $response->getFailureCount()); | ||||
|     } | ||||
| } | ||||
| @@ -1,159 +0,0 @@ | ||||
| <?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_Google | ||||
|  * @subpackage UnitTests | ||||
|  */ | ||||
|  | ||||
| namespace ZendServiceTest\Google\Gcm; | ||||
|  | ||||
| use ZendService\Google\Gcm\Message; | ||||
|  | ||||
| /** | ||||
|  * @category   ZendService | ||||
|  * @package    ZendService_Google | ||||
|  * @subpackage UnitTests | ||||
|  * @group      ZendService | ||||
|  * @group      ZendService_Google | ||||
|  * @group      ZendService_Google_Gcm | ||||
|  */ | ||||
| class MessageTest extends \PHPUnit_Framework_TestCase | ||||
| { | ||||
|     protected $validRegistrationIds = array('1234567890', '0987654321'); | ||||
|     protected $validData = array('key' => 'value', 'key2' => array('value')); | ||||
|  | ||||
|     public function setUp() | ||||
|     { | ||||
|         $this->m = new Message(); | ||||
|     } | ||||
|  | ||||
|     public function testExpectedRegistrationIdBehavior() | ||||
|     { | ||||
|         $this->assertEquals($this->m->getRegistrationIds(), array()); | ||||
|         $this->assertNotContains('registration_ids', $this->m->toJson()); | ||||
|         $this->m->setRegistrationIds($this->validRegistrationIds); | ||||
|         $this->assertEquals($this->m->getRegistrationIds(), $this->validRegistrationIds); | ||||
|         foreach ($this->validRegistrationIds as $id) { | ||||
|             $this->m->addRegistrationId($id); | ||||
|         } | ||||
|         $this->assertEquals($this->m->getRegistrationIds(), $this->validRegistrationIds); | ||||
|         $this->assertContains('registration_ids', $this->m->toJson()); | ||||
|         $this->m->clearRegistrationIds(); | ||||
|         $this->assertEquals($this->m->getRegistrationIds(), array()); | ||||
|         $this->assertNotContains('registration_ids', $this->m->toJson()); | ||||
|         $this->m->addRegistrationId('1029384756'); | ||||
|         $this->assertEquals($this->m->getRegistrationIds(), array('1029384756')); | ||||
|         $this->assertContains('registration_ids', $this->m->toJson()); | ||||
|     } | ||||
|  | ||||
|     public function testInvalidRegistrationIdThrowsException() | ||||
|     { | ||||
|         $this->setExpectedException('InvalidArgumentException'); | ||||
|         $this->m->addRegistrationId(array('1234')); | ||||
|     } | ||||
|  | ||||
|     public function testExpectedCollapseKeyBehavior() | ||||
|     { | ||||
|         $this->assertEquals($this->m->getCollapseKey(), null); | ||||
|         $this->assertNotContains('collapse_key', $this->m->toJson()); | ||||
|         $this->m->setCollapseKey('my collapse key'); | ||||
|         $this->assertEquals($this->m->getCollapseKey(), 'my collapse key'); | ||||
|         $this->assertContains('collapse_key', $this->m->toJson()); | ||||
|         $this->m->setCollapseKey(null); | ||||
|         $this->assertEquals($this->m->getCollapseKey(), null); | ||||
|         $this->assertNotContains('collapse_key', $this->m->toJson()); | ||||
|     } | ||||
|  | ||||
|     public function testInvalidCollapseKeyThrowsException() | ||||
|     { | ||||
|         $this->setExpectedException('InvalidArgumentException'); | ||||
|         $this->m->setCollapseKey(array('1234')); | ||||
|     } | ||||
|  | ||||
|     public function testExpectedDataBehavior() | ||||
|     { | ||||
|         $this->assertEquals($this->m->getData(), array()); | ||||
|         $this->assertNotContains('data', $this->m->toJson()); | ||||
|         $this->m->setData($this->validData); | ||||
|         $this->assertEquals($this->m->getData(), $this->validData); | ||||
|         $this->assertContains('data', $this->m->toJson()); | ||||
|         $this->m->clearData(); | ||||
|         $this->assertEquals($this->m->getData(), array()); | ||||
|         $this->assertNotContains('data', $this->m->toJson()); | ||||
|         $this->m->addData('mykey', 'myvalue'); | ||||
|         $this->assertEquals($this->m->getData(), array('mykey' => 'myvalue')); | ||||
|         $this->assertContains('data', $this->m->toJson()); | ||||
|     } | ||||
|  | ||||
|     public function testInvalidDataThrowsException() | ||||
|     { | ||||
|         $this->setExpectedException('InvalidArgumentException'); | ||||
|         $this->m->addData(array('1234'), 'value'); | ||||
|     } | ||||
|  | ||||
|     public function testDuplicateDataKeyThrowsException() | ||||
|     { | ||||
|         $this->setExpectedException('RuntimeException'); | ||||
|         $this->m->setData($this->validData); | ||||
|         $this->m->addData('key', 'value'); | ||||
|     } | ||||
|  | ||||
|     public function testExpectedDelayWhileIdleBehavior() | ||||
|     { | ||||
|         $this->assertEquals($this->m->getDelayWhileIdle(), false); | ||||
|         $this->assertNotContains('delay_while_idle', $this->m->toJson()); | ||||
|         $this->m->setDelayWhileIdle(true); | ||||
|         $this->assertEquals($this->m->getDelayWhileIdle(), true); | ||||
|         $this->assertContains('delay_while_idle', $this->m->toJson()); | ||||
|         $this->m->setDelayWhileIdle(false); | ||||
|         $this->assertEquals($this->m->getDelayWhileIdle(), false); | ||||
|         $this->assertNotContains('delay_while_idle', $this->m->toJson()); | ||||
|     } | ||||
|  | ||||
|     public function testExpectedTimeToLiveBehavior() | ||||
|     { | ||||
|         $this->assertEquals($this->m->getTimeToLive(), 2419200); | ||||
|         $this->assertNotContains('time_to_live', $this->m->toJson()); | ||||
|         $this->m->setTimeToLive(12345); | ||||
|         $this->assertEquals($this->m->getTimeToLive(), 12345); | ||||
|         $this->assertContains('time_to_live', $this->m->toJson()); | ||||
|         $this->m->setTimeToLive(2419200); | ||||
|         $this->assertEquals($this->m->getTimeToLive(), 2419200); | ||||
|         $this->assertNotContains('time_to_live', $this->m->toJson()); | ||||
|     } | ||||
|  | ||||
|     public function testExpectedRestrictedPackageBehavior() | ||||
|     { | ||||
|         $this->assertEquals($this->m->getRestrictedPackageName(), null); | ||||
|         $this->assertNotContains('restricted_package_name', $this->m->toJson()); | ||||
|         $this->m->setRestrictedPackageName('my.package.name'); | ||||
|         $this->assertEquals($this->m->getRestrictedPackageName(), 'my.package.name'); | ||||
|         $this->assertContains('restricted_package_name', $this->m->toJson()); | ||||
|         $this->m->setRestrictedPackageName(null); | ||||
|         $this->assertEquals($this->m->getRestrictedPackageName(), null); | ||||
|         $this->assertNotContains('restricted_package_name', $this->m->toJson()); | ||||
|     } | ||||
|  | ||||
|     public function testInvalidRestrictedPackageThrowsException() | ||||
|     { | ||||
|         $this->setExpectedException('InvalidArgumentException'); | ||||
|         $this->m->setRestrictedPackageName(array('1234')); | ||||
|     } | ||||
|  | ||||
|     public function testExpectedDryRunBehavior() | ||||
|     { | ||||
|         $this->assertEquals($this->m->getDryRun(), false); | ||||
|         $this->assertNotContains('dry_run', $this->m->toJson()); | ||||
|         $this->m->setDryRun(true); | ||||
|         $this->assertEquals($this->m->getDryRun(), true); | ||||
|         $this->assertContains('dry_run', $this->m->toJson()); | ||||
|         $this->m->setDryRun(false); | ||||
|         $this->assertEquals($this->m->getDryRun(), false); | ||||
|         $this->assertNotContains('dry_run', $this->m->toJson()); | ||||
|     } | ||||
| } | ||||
| @@ -1,102 +0,0 @@ | ||||
| <?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_Google | ||||
|  * @subpackage UnitTests | ||||
|  */ | ||||
|  | ||||
| namespace ZendServiceTest\Google\Gcm; | ||||
|  | ||||
| use ZendService\Google\Gcm\Message; | ||||
| use ZendService\Google\Gcm\Response; | ||||
|  | ||||
| /** | ||||
|  * @category   ZendService | ||||
|  * @package    ZendService_Google | ||||
|  * @subpackage UnitTests | ||||
|  * @group      ZendService | ||||
|  * @group      ZendService_Google | ||||
|  * @group      ZendService_Google_Gcm | ||||
|  */ | ||||
| class ResponseTest extends \PHPUnit_Framework_TestCase | ||||
| { | ||||
|     public function setUp() | ||||
|     { | ||||
|         $this->m = new Message(); | ||||
|     } | ||||
|  | ||||
|     public function testConstructorExpectedBehavior() | ||||
|     { | ||||
|         $response = new Response(); | ||||
|         $this->assertNull($response->getResponse()); | ||||
|         $this->assertNull($response->getMessage()); | ||||
|  | ||||
|         $message = new Message(); | ||||
|         $response = new Response(null, $message); | ||||
|         $this->assertEquals($message, $response->getMessage()); | ||||
|         $this->assertNull($response->getResponse()); | ||||
|  | ||||
|         $message = new Message(); | ||||
|         $responseArray = array( | ||||
|             'results' => array( | ||||
|                 array('message_id' => '1:1234'), | ||||
|             ), | ||||
|             'success' => 1, | ||||
|             'failure' => 0, | ||||
|             'canonical_ids' => 0, | ||||
|             'multicast_id' => 1, | ||||
|         ); | ||||
|         $response = new Response($responseArray, $message); | ||||
|         $this->assertEquals($responseArray, $response->getResponse()); | ||||
|         $this->assertEquals($message, $response->getMessage()); | ||||
|     } | ||||
|  | ||||
|     public function testInvalidConstructorThrowsException() | ||||
|     { | ||||
|         $this->setExpectedException('PHPUnit_Framework_Error'); | ||||
|         $response = new Response('{bad'); | ||||
|     } | ||||
|  | ||||
|     public function testMessageExpectedBehavior() | ||||
|     { | ||||
|         $message = new Message(); | ||||
|         $response = new Response(); | ||||
|         $response->setMessage($message); | ||||
|         $this->assertEquals($message, $response->getMessage()); | ||||
|     } | ||||
|  | ||||
|     public function testResponse() | ||||
|     { | ||||
|         $responseArr = array( | ||||
|             'results' => array( | ||||
|                 array('message_id' => '1:234'), | ||||
|             ), | ||||
|             'success' => 1, | ||||
|             'failure' => 0, | ||||
|             'canonical_ids' => 0, | ||||
|             'multicast_id' => '123', | ||||
|         ); | ||||
|         $response = new Response(); | ||||
|         $response->setResponse($responseArr); | ||||
|         $this->assertEquals($responseArr, $response->getResponse()); | ||||
|         $this->assertEquals(1, $response->getSuccessCount()); | ||||
|         $this->assertEquals(0, $response->getFailureCount()); | ||||
|         $this->assertEquals(0, $response->getCanonicalCount()); | ||||
|         // test results non correlated | ||||
|         $expected = array(array('message_id' => '1:234')); | ||||
|         $this->assertEquals($expected, $response->getResults()); | ||||
|         $expected = array(0 => '1:234'); | ||||
|         $this->assertEquals($expected, $response->getResult(Response::RESULT_MESSAGE_ID)); | ||||
|  | ||||
|         $message = new Message(); | ||||
|         $message->setRegistrationIds(array('ABCDEF')); | ||||
|         $response->setMessage($message); | ||||
|         $expected = array('ABCDEF' => '1:234'); | ||||
|         $this->assertEquals($expected, $response->getResult(Response::RESULT_MESSAGE_ID)); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Manish Verma
					Manish Verma