Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -0,0 +1,226 @@
<?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
*/
namespace ZendServiceTest\Google\Gcm;
use PHPUnit\Framework\TestCase;
use Zend\Http\Client\Adapter\Test;
use Zend\Http\Client as HttpClient;
use ZendService\Google\Gcm\Client;
use ZendService\Google\Gcm\Message;
/**
* @category ZendService
* @group ZendService
* @group ZendService_Google
* @group ZendService_Google_Gcm
*/
class ClientTest extends TestCase
{
/**
* @var Test
*/
protected $httpAdapter;
/**
* @var HttpClient
*/
protected $httpClient;
/**
* @var Client
*/
protected $gcmClient;
/**
* @var Message
*/
protected $message;
protected function createJSONResponse($id, $success, $failure, $ids, $results)
{
return json_encode([
'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->expectException('InvalidArgumentException');
$this->gcmClient->setApiKey([]);
}
public function testSetApiKey()
{
$key = 'a-login-token';
$this->gcmClient->setApiKey($key);
self::assertEquals($key, $this->gcmClient->getApiKey());
}
public function testGetHttpClientReturnsDefault()
{
self::assertInstanceOf('Zend\Http\Client', (new Client())->getHttpClient());
}
public function testSetHttpClient()
{
$client = new HttpClient();
$this->gcmClient->setHttpClient($client);
self::assertEquals($client, $this->gcmClient->getHttpClient());
}
public function testSendThrowsExceptionWhenServiceUnavailable()
{
$this->expectException('RuntimeException');
$this->httpAdapter->setResponse('HTTP/1.1 503 Service Unavailable'."\r\n\r\n");
$this->gcmClient->send($this->message);
}
public function testSendThrowsExceptionWhenServerUnavailable()
{
$this->expectException('RuntimeException');
$this->httpAdapter->setResponse('HTTP/1.1 500 Internal Server Error'."\r\n\r\n");
$this->gcmClient->send($this->message);
}
public function testSendThrowsExceptionWhenInvalidAuthToken()
{
$this->expectException('RuntimeException');
$this->httpAdapter->setResponse('HTTP/1.1 401 Unauthorized'."\r\n\r\n");
$this->gcmClient->send($this->message);
}
public function testSendThrowsExceptionWhenInvalidPayload()
{
$this->expectException('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, [['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);
self::assertEquals('InvalidRegistration', $result['error']);
self::assertEquals(0, $response->getSuccessCount());
self::assertEquals(0, $response->getCanonicalCount());
self::assertEquals(1, $response->getFailureCount());
}
public function testSendResultMismatchSenderId()
{
$body = $this->createJSONResponse(101, 0, 1, 0, [['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);
self::assertEquals('MismatchSenderId', $result['error']);
self::assertEquals(0, $response->getSuccessCount());
self::assertEquals(0, $response->getCanonicalCount());
self::assertEquals(1, $response->getFailureCount());
}
public function testSendResultNotRegistered()
{
$body = $this->createJSONResponse(101, 0, 1, 0, [['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);
self::assertEquals('NotRegistered', $result['error']);
self::assertEquals(0, $response->getSuccessCount());
self::assertEquals(0, $response->getCanonicalCount());
self::assertEquals(1, $response->getFailureCount());
}
public function testSendResultMessageTooBig()
{
$body = $this->createJSONResponse(101, 0, 1, 0, [['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);
self::assertEquals('MessageTooBig', $result['error']);
self::assertEquals(0, $response->getSuccessCount());
self::assertEquals(0, $response->getCanonicalCount());
self::assertEquals(1, $response->getFailureCount());
}
public function testSendResultSuccessful()
{
$body = $this->createJSONResponse(101, 1, 0, 0, [['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);
self::assertEquals('1:2342', $result['message_id']);
self::assertEquals(1, $response->getSuccessCount());
self::assertEquals(0, $response->getCanonicalCount());
self::assertEquals(0, $response->getFailureCount());
}
public function testSendResultSuccessfulWithRegistrationId()
{
$body = $this->createJSONResponse(101, 1, 0, 1, [['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);
self::assertEquals('1:2342', $result['message_id']);
self::assertEquals('testfoo', $result['registration_id']);
self::assertEquals(1, $response->getSuccessCount());
self::assertEquals(1, $response->getCanonicalCount());
self::assertEquals(0, $response->getFailureCount());
}
}

View File

@@ -0,0 +1,186 @@
<?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
*/
namespace ZendServiceTest\Google\Gcm;
use PHPUnit\Framework\TestCase;
use ZendService\Google\Gcm\Message;
/**
* @category ZendService
* @group ZendService
* @group ZendService_Google
* @group ZendService_Google_Gcm
*/
class MessageTest extends TestCase
{
protected $validRegistrationIds = [
'1234567890',
'0987654321',
];
protected $validData = [
'key' => 'value',
'key2' => [
'value',
],
];
/**
* @var Message
*/
private $m;
public function setUp()
{
$this->m = new Message();
}
public function testExpectedRegistrationIdBehavior()
{
self::assertEquals($this->m->getRegistrationIds(), []);
self::assertNotContains('registration_ids', $this->m->toJson());
$this->m->setRegistrationIds($this->validRegistrationIds);
self::assertEquals($this->m->getRegistrationIds(), $this->validRegistrationIds);
foreach ($this->validRegistrationIds as $id) {
$this->m->addRegistrationId($id);
}
self::assertEquals($this->m->getRegistrationIds(), $this->validRegistrationIds);
self::assertContains('registration_ids', $this->m->toJson());
$this->m->clearRegistrationIds();
self::assertEquals($this->m->getRegistrationIds(), []);
self::assertNotContains('registration_ids', $this->m->toJson());
$this->m->addRegistrationId('1029384756');
self::assertEquals($this->m->getRegistrationIds(), ['1029384756']);
self::assertContains('registration_ids', $this->m->toJson());
}
public function testInvalidRegistrationIdThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->m->addRegistrationId(['1234']);
}
public function testExpectedCollapseKeyBehavior()
{
self::assertEquals($this->m->getCollapseKey(), null);
self::assertNotContains('collapse_key', $this->m->toJson());
$this->m->setCollapseKey('my collapse key');
self::assertEquals($this->m->getCollapseKey(), 'my collapse key');
self::assertContains('collapse_key', $this->m->toJson());
$this->m->setCollapseKey(null);
self::assertEquals($this->m->getCollapseKey(), null);
self::assertNotContains('collapse_key', $this->m->toJson());
}
public function testInvalidCollapseKeyThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->m->setCollapseKey(['1234']);
}
public function testExpectedDataBehavior()
{
self::assertEquals($this->m->getData(), []);
self::assertNotContains('data', $this->m->toJson());
$this->m->setData($this->validData);
self::assertEquals($this->m->getData(), $this->validData);
self::assertContains('data', $this->m->toJson());
$this->m->clearData();
self::assertEquals($this->m->getData(), []);
self::assertNotContains('data', $this->m->toJson());
$this->m->addData('mykey', 'myvalue');
self::assertEquals($this->m->getData(), ['mykey' => 'myvalue']);
self::assertContains('data', $this->m->toJson());
}
public function testExpectedNotificationBehavior()
{
$this->assertEquals($this->m->getNotification(), []);
$this->assertNotContains('notification', $this->m->toJson());
$this->m->setNotification($this->validData);
$this->assertEquals($this->m->getNotification(), $this->validData);
$this->assertContains('notification', $this->m->toJson());
$this->m->clearNotification();
$this->assertEquals($this->m->getNotification(), []);
$this->assertNotContains('notification', $this->m->toJson());
$this->m->addNotification('mykey', 'myvalue');
$this->assertEquals($this->m->getNotification(), ['mykey' => 'myvalue']);
$this->assertContains('notification', $this->m->toJson());
}
public function testInvalidDataThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->m->addData(['1234'], 'value');
}
public function testDuplicateDataKeyThrowsException()
{
$this->expectException(\RuntimeException::class);
$this->m->setData($this->validData);
$this->m->addData('key', 'value');
}
public function testExpectedDelayWhileIdleBehavior()
{
self::assertEquals($this->m->getDelayWhileIdle(), false);
self::assertNotContains('delay_while_idle', $this->m->toJson());
$this->m->setDelayWhileIdle(true);
self::assertEquals($this->m->getDelayWhileIdle(), true);
self::assertContains('delay_while_idle', $this->m->toJson());
$this->m->setDelayWhileIdle(false);
self::assertEquals($this->m->getDelayWhileIdle(), false);
self::assertNotContains('delay_while_idle', $this->m->toJson());
}
public function testExpectedTimeToLiveBehavior()
{
self::assertEquals($this->m->getTimeToLive(), 2419200);
self::assertNotContains('time_to_live', $this->m->toJson());
$this->m->setTimeToLive(12345);
self::assertEquals($this->m->getTimeToLive(), 12345);
self::assertContains('time_to_live', $this->m->toJson());
$this->m->setTimeToLive(2419200);
self::assertEquals($this->m->getTimeToLive(), 2419200);
self::assertNotContains('time_to_live', $this->m->toJson());
}
public function testExpectedRestrictedPackageBehavior()
{
self::assertEquals($this->m->getRestrictedPackageName(), null);
self::assertNotContains('restricted_package_name', $this->m->toJson());
$this->m->setRestrictedPackageName('my.package.name');
self::assertEquals($this->m->getRestrictedPackageName(), 'my.package.name');
self::assertContains('restricted_package_name', $this->m->toJson());
$this->m->setRestrictedPackageName(null);
self::assertEquals($this->m->getRestrictedPackageName(), null);
self::assertNotContains('restricted_package_name', $this->m->toJson());
}
public function testInvalidRestrictedPackageThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->m->setRestrictedPackageName(['1234']);
}
public function testExpectedDryRunBehavior()
{
self::assertEquals($this->m->getDryRun(), false);
self::assertNotContains('dry_run', $this->m->toJson());
$this->m->setDryRun(true);
self::assertEquals($this->m->getDryRun(), true);
self::assertContains('dry_run', $this->m->toJson());
$this->m->setDryRun(false);
self::assertEquals($this->m->getDryRun(), false);
self::assertNotContains('dry_run', $this->m->toJson());
}
}

View File

@@ -0,0 +1,119 @@
<?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
*/
namespace ZendServiceTest\Google\Gcm;
use PHPUnit\Framework\TestCase;
use ZendService\Google\Gcm\Message;
use ZendService\Google\Gcm\Response;
/**
* @category ZendService
* @group ZendService
* @group ZendService_Google
* @group ZendService_Google_Gcm
*/
class ResponseTest extends TestCase
{
/**
* @var Message
*/
private $m;
public function setUp()
{
$this->m = new Message();
}
public function testConstructorExpectedBehavior()
{
$response = new Response();
self::assertNull($response->getResponse());
self::assertNull($response->getMessage());
$message = new Message();
$response = new Response(null, $message);
self::assertEquals($message, $response->getMessage());
self::assertNull($response->getResponse());
$message = new Message();
$responseArray = [
'results' => [
['message_id' => '1:1234'],
],
'success' => 1,
'failure' => 0,
'canonical_ids' => 0,
'multicast_id' => 1,
];
$response = new Response($responseArray, $message);
self::assertEquals($responseArray, $response->getResponse());
self::assertEquals($message, $response->getMessage());
}
public function testInvalidConstructorThrowsException()
{
if (PHP_VERSION_ID < 70000) {
self::markTestSkipped('PHP 7 required.');
}
$this->expectException(\TypeError::class);
new Response('{bad');
}
public function testInvalidConstructorThrowsExceptionOnPhp7()
{
if (PHP_VERSION_ID >= 70000) {
self::markTestSkipped('PHP >=5.5 required.');
}
$this->expectException(\PHPUnit_Framework_Error::class);
new Response('{bad');
}
public function testMessageExpectedBehavior()
{
$message = new Message();
$response = new Response();
$response->setMessage($message);
self::assertEquals($message, $response->getMessage());
}
public function testResponse()
{
$responseArr = [
'results' => [
['message_id' => '1:234'],
],
'success' => 1,
'failure' => 0,
'canonical_ids' => 0,
'multicast_id' => '123',
];
$response = new Response();
$response->setResponse($responseArr);
self::assertEquals($responseArr, $response->getResponse());
self::assertEquals(1, $response->getSuccessCount());
self::assertEquals(0, $response->getFailureCount());
self::assertEquals(0, $response->getCanonicalCount());
// test results non correlated
$expected = [['message_id' => '1:234']];
self::assertEquals($expected, $response->getResults());
$expected = [0 => '1:234'];
self::assertEquals($expected, $response->getResult(Response::RESULT_MESSAGE_ID));
$message = new Message();
$message->setRegistrationIds(['ABCDEF']);
$response->setMessage($message);
$expected = ['ABCDEF' => '1:234'];
self::assertEquals($expected, $response->getResult(Response::RESULT_MESSAGE_ID));
}
}