Completed
Push — master ( b902ad...a16ed8 )
by Guillaume
02:37
created

TemplateControllerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 35
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testPostValide() 0 17 1
A testPostInvalide() 0 12 1
1
<?php
2
3
namespace Starkerxp\CampagneBundle\Tests\Manager;
4
5
use Starkerxp\StructureBundle\Tests\WebTest;
6
7
class TemplateControllerTest extends WebTest
8
{
9
10
    public function testPostValide()
11
    {
12
        // create our http client (Guzzle)
13
        $client = new \GuzzleHttp\Client(['base_uri' => 'http://web/']);
14
        $data = [
15
            'nom'     => "Mon nom",
16
            'sujet'   => "Mon sujet",
17
            'message' => "Mon message",
18
            'type'    => "email",
19
        ];
20
        $response = $client->post("app_test.php/templates", ['form_params' => $data]);
21
        $this->assertEquals(201, $response->getStatusCode());
22
23
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.template');
24
        $templates = $manager->findAll();
25
        $this->assertCount(1, $templates);
26
    }
27
28
    public function testPostInvalide()
29
    {
30
        // create our http client (Guzzle)
31
        $client = new \GuzzleHttp\Client(['base_uri' => 'http://web/']);
32
        $response = $client->post("app_test.php/templates", ['form_params' => [], "exceptions"=>false]);
33
        $this->assertEquals(400, $response->getStatusCode());
34
        $body = json_decode($response->getBody(), true)['payload'];
35
        $this->assertArrayHasKey("nom", $body);
36
        $this->assertArrayHasKey("sujet", $body);
37
        $this->assertArrayHasKey("message", $body);
38
        $this->assertArrayHasKey("type", $body);
39
    }
40
41
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
42