-
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.
- Loading branch information
Showing
9 changed files
with
216 additions
and
108 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
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
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
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 |
---|---|---|
@@ -1,57 +1,135 @@ | ||
<?php namespace Tests\Sifter; | ||
|
||
|
||
use Curl\Curl; | ||
use josegonzalez\Dotenv\Loader; | ||
use Sifter\Sifter; | ||
|
||
class SifterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private static $apiKey; | ||
private static $apiSubdomain; | ||
private static $baseUrl; | ||
private $sifterCurlMock; | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
$loader = new Loader(__DIR__.'/../../.env'); | ||
$loader->parse()->toEnv(); | ||
self::$apiKey = (isset($_ENV['SIFTER_API_KEY'])?$_ENV['SIFTER_API_KEY']:null); | ||
self::$apiSubdomain = (isset($_ENV['SIFTER_API_SUBDOMAIN'])?$_ENV['SIFTER_API_SUBDOMAIN']:null); | ||
self::$apiKey = '1234'; | ||
self::$apiSubdomain = 'example'; | ||
self::$baseUrl = 'https://example.sifterapp.com/api/'; | ||
} | ||
|
||
public function testEnvironmentSet() { | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
if ($this->sifterCurlMock === null) { | ||
$this->setUpSifterCurlMock(); | ||
} | ||
} | ||
|
||
public function testEnvironmentSet() | ||
{ | ||
$this->assertNotNull(self::$apiKey); | ||
$this->assertNotNull(self::$apiSubdomain); | ||
} | ||
|
||
public function testConstruct() { | ||
$sifter = new Sifter('1234', 'example'); | ||
|
||
$this->assertEquals('https://example.sifterapp.com/api/', $sifter->getApiBaseUrl()); | ||
public function testConstruct() | ||
{ | ||
$sifter = new Sifter($this->sifterCurlMock); | ||
} | ||
|
||
public function testAllProjects() { | ||
$sifter = new Sifter(self::$apiKey, self::$apiSubdomain); | ||
public function testAllProjects() | ||
{ | ||
$sifter = new Sifter($this->sifterCurlMock); | ||
$projects = $sifter->allProjects(); | ||
|
||
$this->assertTrue(is_array($projects)); | ||
} | ||
|
||
public function testProject() { | ||
public function testProject() | ||
{ | ||
|
||
} | ||
|
||
public function testIssuesThroughProject() { | ||
$sifter = new Sifter(self::$apiKey, self::$apiSubdomain); | ||
public function testIssuesThroughProject() | ||
{ | ||
$sifter = new Sifter($this->sifterCurlMock); | ||
$projects = $sifter->allProjects(); | ||
|
||
$this->assertTrue(is_array($projects)); | ||
$this->assertNotEmpty($projects); | ||
|
||
$issues = $projects[0]->issues(); | ||
|
||
/* @var $issue \Sifter\Model\Issue */ | ||
$issue = $issues->first(); | ||
|
||
$this->assertInstanceOf('Sifter\Resource\IssuesResource', $issues); | ||
$this->assertInstanceOf('Sifter\Model\Issue', $issue); | ||
$this->assertInstanceOf('Carbon\Carbon', $issue->getCreatedAt()); | ||
$this->assertInstanceOf('Carbon\Carbon', $issue->getUpdatedAt()); | ||
$this->assertEquals(57, $issue->getNumber()); | ||
$this->assertEquals('Enhancement', $issue->getCategoryName()); | ||
$this->assertEquals('Trivial', $issue->getPriority()); | ||
$this->assertEquals('Donec vel neque', $issue->getSubject()); | ||
$this->assertEquals('Nam id libero quis ipsum feugiat elementum. Vivamus vitae mauris ut ipsum mattis malesuada. Sed vel massa. Mauris lobortis. Nunc egestas, massa id scelerisque dapibus, urna mi accumsan purus, vel aliquam nunc sapien eget nisi. Quisque vitae nibh. Proin interdum mollis leo. Fusce sed nisi. Integer ut tortor.', $issue->getDescription()); | ||
$this->assertNull($issue->getMilestoneName()); | ||
$this->assertEquals('Adam Keys', $issue->getOpenerName()); | ||
$this->assertEquals('[email protected]', $issue->getOpenerEmail()); | ||
$this->assertEquals('Garrett Dimon', $issue->getAssigneeName()); | ||
$this->assertEquals('[email protected]', $issue->getAssigneeEmail()); | ||
$this->assertEquals(2, $issue->getCommentCount()); | ||
$this->assertEquals(1, $issue->getAttachmentCount()); | ||
$this->assertEquals('https://example.sifterapp.com/projects/1/issues/5', $issue->getUrl()); | ||
} | ||
|
||
private function createSifterCallbackClosure() { | ||
return function() { | ||
$args = func_get_args(); | ||
$url = $args[0]; | ||
switch ($url) { | ||
|
||
case self::$baseUrl . 'projects': | ||
$this->sifterCurlMock->response = $this->jsonTestString('projects.json'); | ||
$this->sifterCurlMock->error = 0; | ||
break; | ||
|
||
case self::$baseUrl . 'projects/1/issues': | ||
$this->sifterCurlMock->response = $this->jsonTestString('projects_1_issues.json'); | ||
$this->sifterCurlMock->error = 0; | ||
break; | ||
|
||
case self::$baseUrl . 'projects/1'; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
}; | ||
} | ||
|
||
private function setUpSifterCurlMock() | ||
{ | ||
$this->sifterCurlMock = $this->getMockBuilder('Sifter\SifterCurl') | ||
->setConstructorArgs([self::$apiKey, self::$apiSubdomain]) | ||
->getMock(); | ||
$this->sifterCurlMock | ||
->method('getBaseUrl') | ||
->willReturn(self::$baseUrl); | ||
|
||
// Set up the routes that are going to be called | ||
$sifterCurlCallback = $this->createSifterCallbackClosure(); | ||
|
||
$this->sifterCurlMock | ||
->expects($this->any()) | ||
->method('get') | ||
->will($this->returnCallback($sifterCurlCallback)); | ||
} | ||
|
||
private function jsonTestString($filename) | ||
{ | ||
return file_get_contents(__DIR__ . '/../json/' . $filename); | ||
} | ||
|
||
} |
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,13 @@ | ||
{ | ||
"name": "Elephant", | ||
"primary_company_name": "Apple", | ||
"archived": false, | ||
"url": "https://example.sifterapp.com/projects/1", | ||
"issues_url": "https://example.sifterapp.com/projects/1/issues", | ||
"milestones_url": "https://example.sifterapp.com/projects/1/milestones", | ||
"api_url": "https://example.sifterapp.com/api/projects/1", | ||
"api_issues_url": "https://example.sifterapp.com/api/projects/1/issues", | ||
"api_milestones_url": "https://example.sifterapp.com/api/projects/1/milestones", | ||
"api_categories_url": "https://example.sifterapp.com/api/projects/1/categories", | ||
"api_people_url": "https://example.sifterapp.com/api/projects/1/people" | ||
} |
Oops, something went wrong.