Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b83603d
Started initial refactor
B3none Mar 27, 2019
2ff6d7d
Renamed models, removed iterable helper.
B3none Mar 27, 2019
e084a49
Refactored models and implemented GroupedModel class to extend from.
B3none Mar 27, 2019
5e77325
Removed silly spacing
B3none Mar 27, 2019
5e5753d
Added write listeners for grouped variables
B3none Mar 27, 2019
866c135
Throw APIErrorException if there's a gametime endpoint error
B3none Mar 27, 2019
f051502
Fixed wording in readme
B3none Mar 27, 2019
928b862
Removed redundant PHP versions from Travis setup
B3none Mar 27, 2019
5fc3668
Altered .gitignore
B3none Mar 27, 2019
7f53799
Fixed PHPCBF errors.
B3none Mar 28, 2019
eeec4cd
More slight refinements, fixed unit test error
B3none Mar 28, 2019
f9d4199
Updated unit tests
B3none Mar 28, 2019
ec26cc5
Switched to Client
B3none Mar 28, 2019
10fdccd
Switched GroupedModel to abstract class
B3none Mar 28, 2019
0e10d77
Call correct class in unit tests
B3none Mar 28, 2019
e891fb9
Removed more spacing
B3none Mar 28, 2019
9e14c06
Switched example user to caf!!! to fix the erroring unit tests.
B3none Mar 28, 2019
f9c6183
Switched to PHPUnit 7 and updated Unit Tests to test the bans whether…
B3none Mar 28, 2019
d60deba
Added deprecated tag to the version function
B3none Mar 28, 2019
d13fc7a
Added Rules endpoint.
B3none Mar 28, 2019
48e88e1
Fixed rules.
B3none Mar 28, 2019
195f0d5
Altered client, fixed rules.
B3none Mar 28, 2019
baeb46d
Updated unit tests to include rules model and added some more assertions
B3none Mar 28, 2019
059bb93
Switched to using getters and setters to remove unstable dependency.
B3none Mar 28, 2019
f33eb63
We now call the endpoints based on the function name
B3none Mar 28, 2019
48596e0
Removed unstable dependency
B3none Mar 28, 2019
ba042f5
Composer update
B3none Mar 28, 2019
0d4e08a
Update readme to describe new style.
B3none Mar 28, 2019
805f7b9
Readme wording updates
B3none Mar 28, 2019
864f382
Updated unit tests to use new format
B3none Mar 28, 2019
b97a76e
Added the ability to pass an index to get functions for groupedModels
B3none Mar 28, 2019
238f852
Put getGroupedValue logic all in the same place
B3none Mar 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
### Composer ###
# Composer
composer.phar
/vendor/

# PHPStorm
/.idea/

# Unit Tests
/Tests/cache/


2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ cache:
- $HOME/.composer/cache

php:
- 5.6
- 7.0
- 7.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add 7.2 and (maybe) 7.3, remove hhvm

- hhvm

Expand Down
105 changes: 68 additions & 37 deletions Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,97 +3,128 @@
namespace TruckersMP\Tests\API;

use Carbon\Carbon;
use TruckersMP\API\APIClient;
use TruckersMP\Types\Ban;
use TruckersMP\Types\Bans;
use TruckersMP\Types\Player;

class ClientTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
use TruckersMP\Client;
use TruckersMP\Models\BanModel;
use TruckersMP\Models\BansModel;
use TruckersMP\Models\GameTimeModel;
use TruckersMP\Models\PlayerModel;
use TruckersMP\Models\RulesModel;

class ClientTest extends TestCase
{
private $testAccount = 585204;
const TEST_ACCOUNT = 585204;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a proper test account for production (maybe even several accounts for checking private states)


private $client;
/**
* @var Client
*/
protected $client;

/**
* ClientTest constructor.
*
*/
public function __construct()
{
parent::__construct();

$this->client = new APIClient();
$this->client = new Client();
}

/**
* @throws \Exception
* @throws \Http\Client\Exception
*/
public function testPlayer()
public function testPlayer(): void
{
$player = $this->client->player($this->testAccount);
$player = $this->client->player(self::TEST_ACCOUNT);

$this->assertEquals($player->name, 'tuxytestaccount');
$this->assertEquals($player->groupID, 1);
$this->assertEquals($player->groupName, 'Player');
$this->assertEquals($player->getName(), 'tuxytestaccount');
$this->assertEquals($player->getGroupID(), 1);
$this->assertEquals($player->getGroupName(), 'Player');

$this->assertInstanceOf(Player::class, $player);
$this->assertInstanceOf(PlayerModel::class, $player);
}

/**
* @throws \Exception
* @throws \Http\Client\Exception
*/
public function testPlayerBans()
public function testPlayerBans(): void
{
$bans = $this->client->bans($this->testAccount);
$bans = $this->client->bans(self::TEST_ACCOUNT);

$this->assertEquals($bans[0]->expires, '2016-06-19 13:00:00');
$this->assertEquals($bans[0]->created, '2016-06-19 10:08:26');
$this->assertEquals($bans[0]->reason, 'Test ban');
if (count($bans->getBans()) > 0) {
$this->assertTrue(is_string($bans->getBans()[0]->getCreated()));
$this->assertTrue(is_string($bans->getBans()[0]->getExpires()));
$this->assertTrue(is_string($bans->getBans()[0]->getReason()));

$this->assertInstanceOf(Bans::class, $bans);
$this->assertInstanceOf(Ban::class, $bans[0]);
$this->assertInstanceOf(BanModel::class, $bans[0]);
} else {
$this->assertEquals($bans->getBans(), []);
}

$this->assertInstanceOf(BansModel::class, $bans);
}

/**
* @throws \Exception
* @throws \Http\Client\Exception
*/
public function testServers()
public function testServers(): void
{
$servers = $this->client->servers();

$this->assertEquals($servers[0]->name, 'Europe 1');
$this->assertEquals($servers->getServers()[0]->getName(), 'Europe 1 [Simulation]');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be streamlined for the cases if we will change server names.

}

/**
* @throws \Exception
* @throws \Http\Client\Exception
*/
public function testVersion()
public function testVersion(): void
{
$version = $this->client->version();

$this->assertNotEmpty($version->version->human);
$this->assertNotEmpty($version->version->stage);
$this->assertNotEmpty($version->version->nummeric);
$this->assertNotEmpty($version->getVersion()->human);
$this->assertNotEmpty($version->getVersion()->stage);
$this->assertNotEmpty($version->getVersion()->nummeric);

$this->assertNotEmpty($version->checksum->atsmp->dll);
$this->assertNotEmpty($version->checksum->atsmp->adb);
$this->assertNotEmpty($version->checksum->ets2mp->dll);
$this->assertNotEmpty($version->checksum->ets2mp->adb);
$this->assertNotEmpty($version->getChecksum()->atsmp->dll);
$this->assertNotEmpty($version->getChecksum()->atsmp->adb);
$this->assertNotEmpty($version->getChecksum()->ets2mp->dll);
$this->assertNotEmpty($version->getChecksum()->ets2mp->adb);

$this->assertInstanceOf(Carbon::class, $version->released);
$this->assertInstanceOf(Carbon::class, $version->getReleased());

$this->assertNotEmpty($version->support->ets2);
$this->assertNotEmpty($version->support->ats);
$this->assertNotEmpty($version->getSupport()->ets2);
$this->assertNotEmpty($version->getSupport()->ats);
}

public function testGameTime()
/**
* @throws \Http\Client\Exception
*/
public function testGameTime(): void
{
$time = $this->client->gameTime();

$this->assertNotEmpty($time);

$this->assertInstanceOf(Carbon::class, $time->getTime());

$this->assertInstanceOf(GameTimeModel::class, $time);
}

/**
* @throws \Http\Client\Exception
* @throws \TruckersMP\Exceptions\APIErrorException
*/
public function testRules(): void
{
$rules = $this->client->rules();

$this->assertTrue(is_string($rules->getRules()));
$this->assertTrue(is_int($rules->getRevision()));

$this->assertInstanceOf(RulesModel::class, $rules);
}
}
13 changes: 10 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@
"email": "me@cjmaxik.ru",
"homepage": "https://cjmaxik.ru",
"role": "IGA/Dev"
},
{
"name": "Alex Blackham (B3none)",
"email": "ablackham2000@gmail.com",
"homepage": "https://github.com/b3none",
"role": "Dev"
}
],
"require": {
"php": ">=5.6.0",
"php": ">=7.1.0",
"nesbot/carbon": "^1.21",
"php-http/message": "^1.2",
"guzzlehttp/psr7": "^1.3"
"guzzlehttp/psr7": "^1.3",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.3",
"phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer": "^2.6",
"php-http/guzzle6-adapter": "^1.0"
},
Expand Down
Loading