Skip to content

Commit 0fcd124

Browse files
committed
feat(legacy-create-video): [golden-master] add characterization test
1 parent 08c6f52 commit 0fcd124

File tree

1 file changed

+64
-0
lines changed
  • exercises/legacy_create_video/solutions/codely_php-symfony_golden-master/src/AppBundle/Tests/Controller

1 file changed

+64
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace AppBundle\Tests\Controller;
4+
5+
use Bazinga\Bundle\RestExtraBundle\Test\WebTestCase;
6+
use PDO;
7+
8+
class VideoControllerTest extends WebTestCase
9+
{
10+
private $connection;
11+
12+
protected function setUp()
13+
{
14+
$this->connection = $this->getClient()->getContainer()->get('database_connection');
15+
$this->connection->query("TRUNCATE video");
16+
}
17+
18+
public function testPostVideo()
19+
{
20+
$client = $this->getClient(true);
21+
22+
$client->request('POST', '/videos.json', [
23+
'title' => 'Testing en frontend',
24+
'url' => 'https://pro.codely.tv/library/testing-frontend',
25+
'course_id' => 5
26+
]);
27+
$response = $client->getResponse();
28+
29+
$this->assertJsonResponse($response);
30+
$expectedId = "1";
31+
$expectedTitle = "Testing en frontend";
32+
$expectedUrl = "https://pro.codely.tv/library/testing-frontend";
33+
$expectedCourseId = 5;
34+
$expectedResponse = [
35+
"id" => $expectedId,
36+
"title" => $expectedTitle,
37+
"url" => $expectedUrl,
38+
"course_id" => $expectedCourseId
39+
];
40+
41+
$this->assertEquals(json_encode($expectedResponse), $response->getContent());
42+
43+
$stmt = $this->connection->prepare("SELECT * FROM video WHERE id = 1");
44+
$stmt->execute();
45+
$result = $stmt->fetch(PDO::FETCH_ASSOC);
46+
47+
$this->assertEquals($expectedTitle, $result['title']);
48+
$this->assertEquals($expectedUrl, $result['url']);
49+
$this->assertEquals($expectedCourseId, $result['course_id']);
50+
}
51+
52+
private function getClient($authenticated = false)
53+
{
54+
$params = array();
55+
if ($authenticated) {
56+
$params = array_merge($params, array(
57+
'PHP_AUTH_USER' => 'restapi',
58+
'PHP_AUTH_PW' => 'secretpw',
59+
));
60+
}
61+
62+
return static::createClient(array(), $params);
63+
}
64+
}

0 commit comments

Comments
 (0)