Created
October 25, 2017 20:20
-
-
Save peterlafferty/2348af5bfff9910dda938b6ca2f8f903 to your computer and use it in GitHub Desktop.
unit test for silex controller
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 | |
use pl\tddcontroller\TddController; | |
use PHPUnit\Framework\TestCase; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
class TddControllerTest extends TestCase | |
{ | |
/** @var TddController */ | |
private $controller; | |
/** @var string */ | |
private $charset = 'UTF-8'; | |
public function setUp() | |
{ | |
$this->controller = new TddController( | |
$this->charset | |
); | |
} | |
public function testGetCity() | |
{ | |
$cityId = 583737; | |
$expected = '"' . $cityId . $this->charset . '"'; | |
/** @var JsonResponse $jsonResponse */ | |
$jsonResponse = $this->controller->get($cityId); | |
$this->assertEquals($expected, $jsonResponse->getContent()); | |
} | |
public function testCitiesWithQueryString() | |
{ | |
$queryString = ['returnsecondvalue' => 'true']; | |
$expected = '"value2' . $this->charset . '"'; | |
$jsonResponse = $this->controller->getAll($queryString); | |
$this->assertEquals( | |
$expected, | |
$jsonResponse->getContent() | |
); | |
} | |
public function testCitiesWithQueryStringNotTrue() | |
{ | |
$queryString = ['returnsecondvalue' => 'false']; | |
$expected = '"value1' . $this->charset . '"'; | |
$jsonResponse = $this->controller->getAll($queryString); | |
$this->assertEquals( | |
$expected, | |
$jsonResponse->getContent() | |
); | |
} | |
public function testCitiesWithOutQueryString() | |
{ | |
$queryString = []; | |
$expected = '"value1' . $this->charset . '"'; | |
$jsonResponse = $this->controller->getAll($queryString); | |
$this->assertEquals( | |
$expected, | |
$jsonResponse->getContent() | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment