Created
February 21, 2016 17:03
-
-
Save cawa87/41e7c1e6122f0f447e06 to your computer and use it in GitHub Desktop.
Unit test
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
<?php | |
namespace AppBundle\Tests\Controller; | |
use AppBundle\Test\WebTestCase; | |
/** | |
* Тест контроллера городов | |
* | |
* Class CitiesControllerTest | |
* @package AppBundle\Tests\Controller | |
*/ | |
class CitiesControllerTest extends WebTestCase | |
{ | |
/** | |
* Получение | |
*/ | |
public function testGetCitiesAction() | |
{ | |
$client = static::createClient(); | |
$client->request('GET', $this->generateRoute('get_cities')); | |
$response = $client->getResponse(); | |
$this->assertTrue($response->isOk()); | |
$response = json_decode($response->getContent()); | |
$this->assertInternalType('array', $response); | |
} | |
public function testGetNearestCitiesAction() | |
{ | |
$client =static::createClient(); | |
$stmt = $client | |
->getContainer() | |
->get('doctrine.dbal.default_connection') | |
->prepare('select lat, lon from cities order by rand() limit 1'); | |
$stmt->execute(); | |
$coords = $stmt->fetchAll()[0]; | |
$client->request('GET', $this->generateRoute('get_city_nearest', [ | |
'lat' => $coords['lat'], | |
'lon' => $coords['lon'] | |
])); | |
$response = $client->getResponse(); | |
$this->assertTrue($response->isOk()); | |
$content = json_decode($response->getContent(), true); | |
$this->assertInternalType('array', $content); | |
$this->assertArrayHasKey('slug', $content); | |
$this->assertArrayHasKey('currency_code', $content); | |
} | |
} |
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
<?php | |
namespace AppBundle\Tests\Controller; | |
use AppBundle\Test\WebTestCase; | |
/** | |
* Тест типов товаров | |
* | |
* Class ItemTypesControllerTest | |
* @package AppBundle\Tests\Controller | |
*/ | |
class ItemTypesControllerTest extends WebTestCase | |
{ | |
public function testGetItemTypesAction() | |
{ | |
$client = static::createClient(); | |
$client->request( | |
'GET', | |
$this->generateRoute('get_item_types') | |
); | |
$response = $client->getResponse(); | |
$this->assertTrue($response->isOk()); | |
$content = json_decode($response->getContent(), true)[0]; | |
$this->assertInternalType('array', $content); | |
$this->assertArrayHasKey('title', $content); | |
$this->assertArrayHasKey('slug', $content); | |
} | |
public function testGetItemTypeAction() | |
{ | |
$client = static::createClient(); | |
$client->request( | |
'GET', | |
$this->generateRoute('get_item_types') | |
); | |
$response = $client->getResponse(); | |
$content = json_decode($response->getContent(), true)[0]; | |
$client->request( | |
'GET', | |
$this->generateRoute('get_item_type', [ | |
'slug' => $content['slug'] | |
]) | |
); | |
$result = json_decode($client->getResponse()->getContent(), true); | |
$this->assertInternalType('array', $result); | |
$this->assertArrayHasKey('slug', $result); | |
$this->assertArrayHasKey('groups', $result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment