Skip to content

Commit

Permalink
Created a lot of PHPUnit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ramlev committed Mar 21, 2016
1 parent c51ea69 commit 2e22f04
Show file tree
Hide file tree
Showing 9 changed files with 545 additions and 12 deletions.
191 changes: 183 additions & 8 deletions tests/AeroGearPush/Tests/AeroGearPushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
namespace AeroGearPush\Tests;

use Napp\AeroGearPush\AeroGearPush;
use Napp\AeroGearPush\Request\CreateAndroidVariantRequest;
use Napp\AeroGearPush\Request\CreateApplicationRequest;
use Napp\AeroGearPush\Request\CreateIosVariantRequest;
use Napp\AeroGearPush\Request\CreateSimplePushVariantRequest;
use Napp\AeroGearPush\Request\DeleteApplicationRequest;
use Napp\AeroGearPush\Request\GetMetricsDashboardRequest;
use Napp\AeroGearPush\Request\GetMetricsMessagesRequest;
use Napp\AeroGearPush\Request\GetSysInfoHealthRequest;
use Napp\AeroGearPush\Request\SenderPushRequest;
use Napp\AeroGearPush\Request\UpdateApplicationRequest;

/**
* Class AeroGearPushTest
Expand All @@ -21,19 +30,21 @@
*/
class AeroGearPushTest extends \PHPUnit_Framework_TestCase
{

public function testAeroGearPushClient()
{
$client = new AeroGearPush('https://url.com/endpoint', [
$client = new AeroGearPush(
'https://url.com/endpoint', [
'verifySSL' => true,
'array' => [
'key1' => 1,
'key2' => 2,
],
]);
]
);

$this->assertEquals('https://url.com/endpoint', $client->serverUrl);
$this->assertEquals(true, $client->verifySSL);
$this->assertEquals(1, $client->array['key1']);
$this->assertInstanceOf(
'Napp\AeroGearPush\Client\CurlClient',
$client->curlClient
);
}

public function testCreateApplicationRequest()
Expand All @@ -43,4 +54,168 @@ public function testCreateApplicationRequest()
$this->assertEquals('applications', $request->endpoint);
$this->assertEquals('POST', $request->method);
}
}

public function testCreateAndroidApplicationRequest()
{
$pushApplicationID = uniqid();
$request = new CreateAndroidVariantRequest(
$pushApplicationID
);

$this->assertEquals($pushApplicationID, $request->pushAppId);
$this->assertEquals('POST', $request->method);
}

public function testCreateIosApplicationRequest()
{
$pushApplicationID = uniqid();
$request = new CreateIosVariantRequest($pushApplicationID);

$this->assertEquals($pushApplicationID, $request->pushAppId);
$this->assertEquals('POST', $request->method);

$this->assertTrue(empty($request->data['developer']));
$request->setDeveloper('Me Myself');
$this->assertEquals('Me Myself', $request->data['developer']);

$pass = uniqid();
$request->setPassphrase($pass);
$this->assertEquals($pass, $request->data['passphrase']);

$certificate = uniqid();
$request->setCertificate($certificate);
$this->assertEquals($certificate, $request->data['certificate']);

$this->assertTrue(empty($request->data['production']));
$request->setProduction(true);
$this->assertTrue($request->data['production']);
}

public function testCreateSimplePushApplicationRequest()
{
$pushApplicationID = uniqid();
$request = new CreateSimplePushVariantRequest(
$pushApplicationID
);

$this->assertEquals($pushApplicationID, $request->pushAppId);
$this->assertEquals('POST', $request->method);
}

public function testDeleteApplicationRequest()
{
$pushApplicationID = uniqid();
$request = new DeleteApplicationRequest($pushApplicationID);

$this->assertEquals($pushApplicationID, $request->pushAppId);
$this->assertEquals('DELETE', $request->method);
}

public function testUpdateApplicationRequest()
{
$pushApplicationID = uniqid();
$request = new UpdateApplicationRequest($pushApplicationID);
$this->assertEquals($pushApplicationID, $request->pushAppId);
$this->assertEquals('PUT', $request->method);

$this->assertEmpty($request->data);

$request->setName('New application name');
$this->assertArrayHasKey('name', $request->data);
$this->assertEquals('New application name', $request->data['name']);

$this->assertArrayNotHasKey('description', $request->data);
$request->setDescription('A description');
$this->assertEquals('A description', $request->data['description']);
}

public function testSenderPushRequest()
{
$request = new SenderPushRequest();
$this->assertEquals('POST', $request->method);

$pushAppId = uniqid();
$masterSecret = uniqid();

$request->setAuth($pushAppId, $masterSecret);
$this->assertCount(2, $request->auth);
$this->assertEquals($pushAppId, $request->auth[0]);
$this->assertEquals($masterSecret, $request->auth[1]);

$this->assertNull($request->message);
$message = uniqid();
$request->setMessage([$message]);
$this->assertEquals($message, $request->message[0]);

$criteria = [
'alias' => ['me', 'myself', 'i'],
];
$this->assertNull($request->criteria);
$request->setCriteria($criteria);
$this->assertArrayHasKey('alias', $request->criteria);

$config = [
'ttl' => 80,
];

$this->assertNull($request->config);
$request->setConfig($config);
$this->assertArrayHasKey('ttl', $request->config);
$this->assertEquals(80, $request->config['ttl']);
}

public function testGetSysInfoHealthRequest()
{
$request = new GetSysInfoHealthRequest();

$bearer = uniqid();
$request->setHeader('Authorization', 'Bearer '.$bearer);
$this->assertEquals(
'Bearer '.$bearer,
$request->headers['headers']['Authorization']
);

$this->assertTrue(empty($request->OAuthToken));
$oAuthToken = uniqid();
$request->setOAuthToken($oAuthToken);
$this->assertEquals($oAuthToken, $request->OAuthToken);

$this->assertEquals('sys/info/health', $request->endpoint);
$this->assertEquals('GET', $request->method);
}

public function testGetMetricsDashBoardRequest()
{
$request = new GetMetricsDashboardRequest();

$this->assertEquals('metrics/dashboard', $request->endpoint);
$this->assertEquals('GET', $request->method);

$this->assertNull($request->type);
$request->setType('active');
$this->assertEquals('active', $request->type);

$request->setType('warnings');
$this->assertEquals('warnings', $request->type);
}

public function testGetMetricsMessagesRequest()
{
$pushAppId = uniqid();

$request = new GetMetricsMessagesRequest($pushAppId);

$this->assertEquals('metrics/messages/application', $request->endpoint);
$this->assertEquals('GET', $request->method);

$request->setPageNumber(8);
$request->setPerPage(10);
$request->setSort('ASC');
$request->setSearch('android');

$this->assertEquals(8, $request->queryParam['page']);
$this->assertEquals(10, $request->queryParam['per_page']);
$this->assertEquals('ASC', $request->queryParam['sort']);
$this->assertEquals('android', $request->queryParam['search']);
}
}
55 changes: 55 additions & 0 deletions tests/AeroGearPush/Tests/CreateAndroidVariantTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* This file is part of the AeroGearPush package.
*
* (c) NAPP <http://napp.dk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace AeroGearPush\Tests;

use Napp\AeroGearPush\Client\DummyClient;

/**
* Class CreateAndroidVariantTest
*
* @package AeroGearPush\Tests
* @author Hasse Ramlev Hansen <[email protected]>
*/
class CreateAndroidVariantTest extends \PHPUnit_Framework_TestCase
{
/**
* @throws \Napp\AeroGearPush\Exception\AeroGearAuthErrorException
* @throws \Napp\AeroGearPush\Exception\AeroGearBadRequestException
* @throws \Napp\AeroGearPush\Exception\AeroGearNotFoundException
* @throws \Napp\AeroGearPush\Exception\AeroGearPushException
*/
public function testCreateAndroidVariant()
{
$client = new DummyClient();

$response = $client->call(
'POST',
'https://host.com/rest',
'applications/6d917118/android',
[],
[],
[]
);

$response = json_decode($response);

$this->assertEquals(
'a69d2e3f-1447-4bfc-b355-42439e2c2ab9',
$response->id
);
$this->assertEquals(
'a6d35fa9-8ed4-459d-a1f9-c8d0a3c9c34f',
$response->variantID
);
$this->assertEquals('{GOOGLE_KEY}', $response->googleKey);
$this->assertEquals('android', $response->type);
}
}
21 changes: 17 additions & 4 deletions tests/AeroGearPush/Tests/CreateApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,25 @@ public function testCreateApplication()
{
$client = new DummyClient();

$response = $client->call('POST', 'https://host.com/rest', 'applications', [], [], []);
$response = $client->call(
'POST',
'https://host.com/rest',
'applications',
[],
[],
[]
);

$response = json_decode($response);

$this->assertEquals('3aad1e92-3255-461b-8129-854025a5e7ab', $response->id);
$this->assertEquals('dc5df3f3-2609-4547-9cc5-a844fc3b09e3', $response->pushApplicationID);
$this->assertEquals(
'3aad1e92-3255-461b-8129-854025a5e7ab',
$response->id
);
$this->assertEquals(
'dc5df3f3-2609-4547-9cc5-a844fc3b09e3',
$response->pushApplicationID
);
$this->assertEmpty($response->variants);
}
}
}
50 changes: 50 additions & 0 deletions tests/AeroGearPush/Tests/CreateIosVariantTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* This file is part of the AeroGearPush package.
*
* (c) NAPP <http://napp.dk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace AeroGearPush\Tests;

use Napp\AeroGearPush\Client\DummyClient;

/**
* Class CreateIosVariantTest
*
* @package AeroGearPush\Tests
* @author Hasse Ramlev Hansen <[email protected]>
*/
class CreateIosVariantTest extends \PHPUnit_Framework_TestCase
{

public function testCreateIosVariant()
{
$client = new DummyClient();

$response = $client->call(
'POST',
'https://host.com/rest',
'applications/6d917118/ios',
[],
[],
[]
);

$response = json_decode($response);

$this->assertEquals(
'22debd80-04ab-4213-ac6f-18d6c0c106fe',
$response->id
);
$this->assertEquals(
'13f663bc-6321-4fc0-b8e1-77429d6c180c',
$response->variantID
);
$this->assertEquals(false, $response->production);
$this->assertEquals('ios', $response->type);
}
}
Loading

0 comments on commit 2e22f04

Please sign in to comment.