Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of unit test structure, minor refactor of autoloading
- Loading branch information
Showing
6 changed files
with
122 additions
and
10 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
<?php | |||
namespace Joindin\Service; | |||
|
|||
class Autoload | |||
{ | |||
/** | |||
* Autoloader for joind.in classes | |||
* | |||
* @param string $class Class name to load | |||
* | |||
* @return void | |||
*/ | |||
public static function autoload($class) | |||
{ | |||
if (in_array('Joindin', explode('\\', $class))) { | |||
// Convert namespace to directory separators | |||
|
|||
$path = str_replace('\\', '/', $class); | |||
|
|||
// Trim off Joindin | |||
$path = substr($path, 8); | |||
require_once(__DIR__ . '/../'.$path.'.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,77 @@ | |||
<?php | |||
namespace test\Model\API\Collection; | |||
|
|||
class EventTest extends \PHPUnit_Framework_TestCase | |||
{ | |||
/** | |||
* Tests that variables are properly set when retrieve is called with no parameters | |||
* | |||
* @return void | |||
* | |||
* @test | |||
*/ | |||
public function defaultRetrievalParametersAreSet() | |||
{ | |||
$mockEvent = $this->getMock('Joindin\Model\Collection\Event', array('apiGet')); | |||
$mockEvent->expects($this->once()) | |||
->method('apiGet') | |||
->with('http://api.joind.in/v2.1/events?resultsperpage=10&page=1') | |||
->will($this->returnValue(json_encode(array('events' => array(), 'meta' => array())))); | |||
|
|||
$mockEvent->retrieve(); | |||
} | |||
|
|||
/** | |||
* Ensures that setting a limit will make the URL correctly | |||
* | |||
* @return void | |||
* | |||
* @test | |||
*/ | |||
public function retrievalWithLimitSetsParamsCorrectly() | |||
{ | |||
$mockEvent = $this->getMock('Joindin\Model\Collection\Event', array('apiGet')); | |||
$mockEvent->expects($this->once()) | |||
->method('apiGet') | |||
->with('http://api.joind.in/v2.1/events?resultsperpage=75&page=1') | |||
->will($this->returnValue(json_encode(array('events' => array(), 'meta' => array())))); | |||
|
|||
$mockEvent->retrieve(75); | |||
} | |||
|
|||
/** | |||
* Ensures that asking for a different page sets params correctly | |||
* | |||
* @return void | |||
* | |||
* @test | |||
*/ | |||
public function retrievalWithPageValueSetsParamsCorrectly() | |||
{ | |||
$mockEvent = $this->getMock('Joindin\Model\Collection\Event', array('apiGet')); | |||
$mockEvent->expects($this->once()) | |||
->method('apiGet') | |||
->with('http://api.joind.in/v2.1/events?resultsperpage=32&page=6') | |||
->will($this->returnValue(json_encode(array('events' => array(), 'meta' => array())))); | |||
|
|||
$mockEvent->retrieve(32, 6); | |||
} | |||
|
|||
/** | |||
* Ensures that setting all 3 params sets everything correctly | |||
* | |||
* @return void | |||
* | |||
* @test | |||
*/ | |||
public function retrievalWithFilterSetsAllParamsCorrectly() | |||
{ | |||
$mockEvent = $this->getMock('Joindin\Model\Collection\Event', array('apiGet')); | |||
$mockEvent->expects($this->once()) | |||
->method('apiGet') | |||
->with('http://api.joind.in/v2.1/events?resultsperpage=16&page=3&filter=samoflange') | |||
->will($this->returnValue(json_encode(array('events' => array(), 'meta' => array())))); | |||
|
|||
$mockEvent->retrieve(16, 3, 'samoflange'); | |||
} | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
<?php | |||
require_once __DIR__ . '/../Service/Autoload.php'; | |||
|
|||
spl_autoload_register('Joindin\Service\Autoload::autoload'); | |||
|
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
<phpunit bootstrap="./bootstrap.php"> | |||
<testsuite name="Joind.in responsive Test Suite"> | |||
<directory>.</directory> | |||
</testsuite> | |||
|
|||
<filter> | |||
<whitelist processUncoveredFilesFromWhiteList="true"> | |||
<directory suffix=".php">.</directory> | |||
</whitelist> | |||
</filter> | |||
</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