-
Notifications
You must be signed in to change notification settings - Fork 1
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
13 changed files
with
340 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7 | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --no-interaction --prefer-source | ||
|
||
script: | ||
- php vendor/phpunit/phpunit/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
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
stopOnError="false" | ||
stopOnIncomplete="false" | ||
stopOnSkipped="false" | ||
bootstrap="tests/Bootstrap.php" | ||
> | ||
<testsuites> | ||
<testsuite name="all"> | ||
<directory suffix="Test.php">tests/unit/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</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
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,40 @@ | ||
<?php | ||
|
||
namespace Youthweb\Api\Resource; | ||
|
||
/** | ||
* Get the stats | ||
* | ||
* @link https://github.com/youthweb/youthweb-api#stats | ||
*/ | ||
class Stats extends AbstractResource | ||
{ | ||
/** | ||
* Get the stats | ||
* | ||
* @link https://github.com/youthweb/youthweb-api#stats | ||
* | ||
* @param string $id | ||
* @return array the stats | ||
*/ | ||
public function show($id) | ||
{ | ||
$ids = array( | ||
'account' => 'account', | ||
'forum' => 'forum', | ||
'groups' => 'groups', | ||
); | ||
|
||
if ( ! isset($ids[$id]) ) | ||
{ | ||
throw new \InvalidArgumentException('The ressource id "' . $id . '" does not exists.'); | ||
} | ||
|
||
$params = array( | ||
'action' => 'stats', | ||
'cat' => $id, | ||
); | ||
|
||
return $this->get('', $params); | ||
} | ||
} |
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,11 @@ | ||
<?php | ||
|
||
include_once(__DIR__.'/../src/autoload.php'); | ||
|
||
if ( ! @include_once __DIR__.'/../vendor/autoload.php') | ||
{ | ||
exit("You must set up the project dependencies, run the following commands: | ||
> wget http://getcomposer.org/composer.phar | ||
> php composer.phar install | ||
"); | ||
} |
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,66 @@ | ||
<?php | ||
|
||
namespace Youthweb\Api\Fixtures; | ||
|
||
use Youthweb\Api\Client; | ||
|
||
/** | ||
* Mock client class | ||
*/ | ||
class MockClient extends Client | ||
{ | ||
/** | ||
* Return value the mocked runRequest method should return. | ||
* | ||
* @var mixed | ||
*/ | ||
public $runRequestReturnValue = null; | ||
|
||
/** | ||
* Return value the mocked runRequest method should return. | ||
* | ||
* @var mixed | ||
*/ | ||
public $useOriginalGetMethod = false; | ||
|
||
/** | ||
* Just return the data from runRequest(). | ||
* | ||
* @param string $path | ||
* @param array $data | ||
* | ||
* @return array | ||
*/ | ||
public function get($path, array $data = array()) | ||
{ | ||
if ( $this->useOriginalGetMethod ) | ||
{ | ||
return parent::get($path, $data); | ||
} | ||
|
||
return $this->runRequest($path, 'GET', $data); | ||
} | ||
|
||
/** | ||
* @param string $path | ||
* @param string $method | ||
* @param array $data | ||
* | ||
* @return string | ||
* | ||
* @throws \Exception If anything goes wrong on curl request | ||
*/ | ||
protected function runRequest($path, $method = 'GET', array $data = array()) | ||
{ | ||
if ( $this->runRequestReturnValue !== null ) | ||
{ | ||
return $this->runRequestReturnValue; | ||
} | ||
|
||
return array( | ||
'path' => $path, | ||
'method' => $method, | ||
'data' => $data, | ||
); | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
namespace Youthweb\Api\Tests; | ||
|
||
use Youthweb\Api\Client; | ||
use InvalidArgumentException; | ||
|
||
class ClientTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function testSetUrlReturnsClient() | ||
{ | ||
$client = new Client(); | ||
|
||
$this->assertInstanceOf('Youthweb\Api\Client', $client->setUrl('http://test.local')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function testGetUrlReturnsValueFromSetUrl() | ||
{ | ||
$client = (new Client())->setUrl('http://test.local'); | ||
|
||
$this->assertSame('http://test.local', $client->getUrl()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function testSetHttpClientReturnsClient() | ||
{ | ||
$client = new Client(); | ||
|
||
$stub = $this->getMock('Youthweb\Api\HttpClientInterface'); | ||
|
||
$this->assertInstanceOf('Youthweb\Api\Client', $client->setHttpClient($stub)); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider getResoursesClassesProvider | ||
*/ | ||
public function testGetApiInstance($resource_name, $class_name) | ||
{ | ||
$client = new Client(); | ||
|
||
$this->assertInstanceOf($class_name, $client->getResource($resource_name)); | ||
} | ||
|
||
public function getResoursesClassesProvider() | ||
{ | ||
return array( | ||
array('account', 'Youthweb\Api\Resource\Account'), | ||
array('stats', 'Youthweb\Api\Resource\Stats'), | ||
); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace Youthweb\Api\Tests\Resource; | ||
|
||
use Youthweb\Api\Fixtures\MockClient; | ||
use InvalidArgumentException; | ||
|
||
class AccountTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function testStatsReturnsArray() | ||
{ | ||
$client = new MockClient(); | ||
$client->useOriginalGetMethod = false; | ||
$client->runRequestReturnValue = json_decode('{"user_total":5503,"user_online":74}', false); | ||
|
||
$response = $client->getResource('account')->stats(); | ||
|
||
$this->assertTrue(is_array($response)); | ||
$this->assertSame(array('user_total' => 5503, 'user_online' => 74), $response); | ||
} | ||
} |
Oops, something went wrong.