forked from johannez/chargify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for the controller factory and products
- Loading branch information
Showing
4 changed files
with
145 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<var name="chargify_domain" value="2tabs"/> | ||
<var name="chargify_api_key" value="R3XvWkDgL8F7ENxpxL"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Chargify\Tests; | ||
use \Chargify\Controller\Factory; | ||
use \Chargify\Controller\Product; | ||
use \PHPUnit_Framework_TestCase; | ||
|
||
class ControllerFactoryTest extends PHPUnit_Framework_TestCase { | ||
|
||
public function testDomainIsSet() { | ||
$this->assertTrue($GLOBALS['chargify_domain'] !== 'DOMAIN', 'Domain is not set. Please update the phpunit.xml file.'); | ||
} | ||
|
||
public function testApiKeyIsSet() { | ||
$this->assertTrue($GLOBALS['chargify_api_key'] !== 'API_KEY', 'API key is not set. Please update the phpunit.xml file.'); | ||
} | ||
|
||
/** | ||
* @depends testDomainIsSet | ||
* @depends testApiKeyIsSet | ||
*/ | ||
public function testCanCreateController() { | ||
$resource_types = array('component', 'coupon', 'customer', 'product', 'subscription', 'transaction'); | ||
|
||
foreach ($resource_types as $type) { | ||
// Just take product as they are all the same. | ||
$controller = Factory::build($type, $GLOBALS['chargify_domain'], $GLOBALS['chargify_api_key']); | ||
|
||
$this->assertInstanceOf('Chargify\\Controller\\' . ucfirst($type), $controller, 'Can not initialize controller.'); | ||
} | ||
|
||
|
||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
tests/Chargify/Tests/Controllers/ProductControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Chargify\Tests; | ||
use \Chargify\Controller\Factory; | ||
use \Chargify\Controller\Product; | ||
use \Chargify\Resource\ProductResource; | ||
use \PHPUnit_Framework_TestCase; | ||
|
||
class ProductControllerTest extends PHPUnit_Framework_TestCase { | ||
|
||
public function testGetAll() { | ||
$controller = Factory::build('product', $GLOBALS['chargify_domain'], $GLOBALS['chargify_api_key']); | ||
$this->assertNotEmpty($controller->getAll()); | ||
} | ||
|
||
/** | ||
* @depends testGetAll | ||
*/ | ||
public function testGetByFamily() { | ||
$controller = Factory::build('product', $GLOBALS['chargify_domain'], $GLOBALS['chargify_api_key']); | ||
$products = $controller->getAll(); | ||
|
||
$this->assertNotEmpty($controller->getByFamily($products[0]->product_family->id)); | ||
} | ||
|
||
/** | ||
* @depends testGetAll | ||
*/ | ||
public function testGetById() { | ||
$controller = Factory::build('product', $GLOBALS['chargify_domain'], $GLOBALS['chargify_api_key']); | ||
$products = $controller->getAll(); | ||
|
||
$response = $controller->getById($products[0]->id); | ||
|
||
$this->assertNotNull($response); | ||
$this->assertInstanceOf('Chargify\Resource\ProductResource', $response); | ||
} | ||
|
||
/** | ||
* @depends testGetAll | ||
*/ | ||
public function testGetByHandle() { | ||
$controller = Factory::build('product', $GLOBALS['chargify_domain'], $GLOBALS['chargify_api_key']); | ||
$products = $controller->getAll(); | ||
|
||
$response = $controller->getByHandle($products[0]->handle); | ||
|
||
$this->assertNotNull($response); | ||
$this->assertInstanceOf('Chargify\Resource\ProductResource', $response); | ||
} | ||
|
||
/** | ||
* @depends testGetByFamily | ||
*/ | ||
public function testCreateProduct() { | ||
|
||
$controller = Factory::build('product', $GLOBALS['chargify_domain'], $GLOBALS['chargify_api_key']); | ||
$products = $controller->getAll(); | ||
|
||
$data = array( | ||
'product' => array( | ||
'name' => 'Basic Plan 123', | ||
'handle' => 'basic', | ||
'description' => 'This is our basic plan.', | ||
'accounting_code' => '123', | ||
'request_credit_card' => true, | ||
'price_in_cents' => 1000, | ||
'interval' => 1, | ||
'interval_unit' => 'month' | ||
) | ||
); | ||
|
||
$response = $controller->create($products[0]->product_family->id, $data); | ||
|
||
$this->assertNotNull($response); | ||
$this->assertInstanceOf('Chargify\Resource\ProductResource', $response); | ||
} | ||
|
||
} |