Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
messerli90 committed Jan 2, 2017
1 parent 8ecb9c0 commit e7a7a8f
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 18 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/vendor
/vendor
composer.phar
composer.lock
.DS_Store
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

#branches:
# only:
# - master

before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-source

script:
- ./vendor/bin/phpunit
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
IGDB (Internet Game Database)
=========

[![Build Status](https://travis-ci.org/messerli90/igdb.svg?branch=master)](https://travis-ci.org/messerli90/igdb)

Laravel PHP Facade/Wrapper for the IGDB API

You need to create an application and create your access token in the [Mashape Marketplace](https://market.mashape.com/igdbcom/internet-game-database).
Expand Down Expand Up @@ -120,7 +122,7 @@ $themes = IGDB::searchThemes('warfare');

```

## (TODO) Run Unit Test
## Run Unit Test
If you have PHPUnit installed in your environment, run:

```bash
Expand All @@ -146,5 +148,12 @@ The returned JSON is decoded as PHP objects (not Array).
##Credits
Built on code from alaouy's [Youtube](https://github.com/alaouy/Youtube).

##Contribute
If you'd like to contribute feel free to fork and submit a PR.
## Contribute
If you'd like to contribute feel free to fork and submit a PR. I'll be updating the Todo list below with new feature ideas

## TODO

- Improve test coverage
- Image facade


8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
}
],
"autoload": {
"psr-4": {
"Messerli90\\IGDB\\": "src/messerli90/igdb"
"psr-0": {
"Messerli90\\IGDB\\": "src/"
}
},
"require": {
"php": ">=5.5.0",
"illuminate/support": ">= 5.0"
"php": ">=5.3.0"
},
"require-dev": {
"orchestra/testbench": "~3.0",
"phpunit/phpunit": "~5.0"
},
"autoload-dev": {
Expand Down
15 changes: 6 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="IGDB Test Suite">
<directory suffix="Test.php">./tests</directory>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
63 changes: 63 additions & 0 deletions tests/IGDBTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Messerli90\Tests;

require_once __DIR__ . '/../vendor/autoload.php';

use Messerli90\IGDB\IGDB;

class IGDBTest extends \PHPUnit_Framework_TestCase
{
/**
* @var igdb
*/
public $igdb;

public function setUp()
{
$TEST_API_KEY = 'xbHBrXHDBVmshH3pw1DVPhS7WAn1p12FAofjsnz8li0LSV3d7o';
$this->igdb = new IGDB($TEST_API_KEY);
}

public function tearDown()
{
$this->youtube = null;
}

/** @expectException */
public function invalid_api_key_throws_error ()
{
$this->igdb = new IGDB(['key' => 'nonsense']);
$game_id = 9630;
$this->igdb->getGame($game_id);

$this->expectException('\Exception');
}

/** @test */
public function get_company_info ()
{
$id = 7041;
$response = $this->igdb->getCompany($id);

$this->assertEquals($id, $response->id);
$this->assertNotNull('response');

$this->assertObjectHasAttribute('name', $response);
$this->assertObjectHasAttribute('slug', $response);
$this->assertObjectHasAttribute('url', $response);
}

/** @test */
public function search_companies ()
{
$search = 'ubisoft';
$response = $this->igdb->searchCompanies($search);

$this->assertNotNull('response');

$this->assertObjectHasAttribute('name', $response[0]);
$this->assertObjectHasAttribute('slug', $response[0]);
$this->assertObjectHasAttribute('url', $response[0]);
}
}

0 comments on commit e7a7a8f

Please sign in to comment.