Skip to content

Commit

Permalink
поправил тесты
Browse files Browse the repository at this point in the history
  • Loading branch information
visavi committed Jul 26, 2018
1 parent bea0da8 commit d632d5e
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 381 deletions.
281 changes: 91 additions & 190 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vendor/bin/phpunit
### Реализованные классы

* Query.php - состоит из 5 методов,
* get - Получает данныеб может как принимать данные GET так и отправлять POST (PATCH, PUT, DELETE)
* get - Получает данные, может как принимать данные GET так и отправлять POST (PATCH, PUT, DELETE)
* send - Отправка данных
* run - Вспомогательный метод, запрашивает данные, получает сессию и куки для повторного запроса
* getRid - Вспомогательный метод, получает уникальный ключ RID (REQUEST_ID)
Expand Down
12 changes: 1 addition & 11 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="RZD-API Test Suite">
<directory>./tests/</directory>
Expand Down
153 changes: 153 additions & 0 deletions tests/ApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

use PHPUnit\Framework\TestCase;
use Rzd\Api;

class ApiTest extends TestCase
{
/**
* var Api
*/
private $api;

/**
* @var string
*/
private $date0;

/**
* @var string
*/
private $date1;

/**
* @throws Exception
*/
protected function setUp()
{
$this->api = new Api();

$start = new DateTime();
$this->date0 = $start->modify('+1 day');
$this->date1 = $start->modify('+5 day');
}

/**
* Тест получения маршрутов
*/
public function testTrainRoutes(): void
{
$params = [
'dir' => 0,
'tfl' => 3,
'checkSeats' => 1,
'code0' => '2004000',
'code1' => '2000000',
'dt0' => $this->date0->format('d.m.Y'),
];

$trainRoutes = json_decode($this->api->trainRoutes($params), true);

$this->assertInternalType('array', $trainRoutes);
$this->assertArrayHasKey('route0', $trainRoutes[0]);
$this->assertContains('С-ПЕТЕР-ГЛ', $trainRoutes[0]['route0']);
}

/**
* Тест получения маршрутов туда-обратно
*/
public function testTrainRoutesReturn(): void
{
$params = [
'dir' => 1,
'tfl' => 3,
'checkSeats' => 1,
'code0' => '2004000',
'code1' => '2000000',
'dt0' => $this->date0->format('d.m.Y'),
'dt1' => $this->date1->format('d.m.Y'),
];

$trainRoutesReturn = json_decode($this->api->trainRoutesReturn($params), true);

$this->assertInternalType('array', $trainRoutesReturn[0]);
$this->assertArrayHasKey('route0', $trainRoutesReturn[0][0]);
$this->assertContains('С-ПЕТЕР-ГЛ', $trainRoutesReturn[0][0]['route0']);
}

/**
* Тест получения вагонов
*/
public function testTrainCarriages(): void
{
$params = [
'dir' => 0,
'tfl' => 3,
'checkSeats' => 1,
'code0' => '2004000',
'code1' => '2000000',
'dt0' => $this->date0->format('d.m.Y'),
];

$routes = $this->api->trainRoutes($params);

if ($routes) {
$routes = json_decode($routes);

$params = [
'dir' => 0,
'code0' => '2004000',
'code1' => '2000000',
'dt0' => $this->date0->format('d.m.Y'),
'time0' => $routes[0]->trTime0,
'tnum0' => $routes[0]->number,
];

$trainCarriages = json_decode($this->api->trainCarriages($params), true);

$this->assertInternalType('array', $trainCarriages);
$this->assertArrayHasKey('cars', $trainCarriages);
$this->assertArrayHasKey('cnumber', $trainCarriages['cars'][0]);
}
}

/**
* Тест просмотра станций
*/
public function testTrainStationList(): void
{
$params = [
'train_num' => '072Е',
'date' => $this->date0->format('d.m.Y'),
];

$trainStationList = json_decode($this->api->trainStationList($params), true);

$this->assertInternalType('array', $trainStationList);
$this->assertArrayHasKey('train', $trainStationList);
$this->assertContains('072Е', $trainStationList['train']['Number']);
}

/**
* Тест кодов станций
*/
public function testStationCode(): void
{
$params = [
'stationNamePart' => 'ЧЕБ',
'lang' => 'ru',
'compactMode' => 'y',
];

$stationCode = json_decode($this->api->stationCode($params), true);

$this->assertInternalType('array', $stationCode);

$cities = [];
foreach($stationCode as $station) {
$cities[] = $station['station'];
}

$this->assertContains('ЧЕБОКСАРЫ', $cities);
}
}
57 changes: 57 additions & 0 deletions tests/AuthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

use PHPUnit\Framework\TestCase;
use Rzd\Auth;

class AuthTest extends TestCase
{
/**
* @var Auth
*/
private $auth;

/**
* @throws Exception
*/
protected function setUp()
{
$config = new Rzd\Config();
$config->setAuth(USERNAME, PASSWORD);

$this->auth = new Auth($config);
}

/**
* Тест авторизации
*/
public function testLogin(): void
{
// Проверка авторизации
if (empty(USERNAME) || empty(PASSWORD)) {
$this->markTestSkipped('Установите логин и пароль в файле bootstrap.php');
} else {
$this->assertTrue($this->auth->login());
}
}

/**
* Тест получения данных
*
* @throws Exception
*/
public function testProfile(): void
{
$this->auth->login();
$profile = $this->auth->getProfile();

if (! $profile) {
$this->markTestSkipped('Не удалось авторизоваться на сайте');
} else {

$profile = json_decode($profile, true);

$this->assertInternalType('array', $profile);
$this->assertArrayHasKey('uid', $profile);
}
}
}
115 changes: 0 additions & 115 deletions tests/TrainTest.php

This file was deleted.

Loading

0 comments on commit d632d5e

Please sign in to comment.