-
Notifications
You must be signed in to change notification settings - Fork 16
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
8 changed files
with
305 additions
and
381 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,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); | ||
} | ||
} |
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,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); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.