Completed
Push — master ( 8c5aef...11380b )
by Guillaume
03:14
created

WebTest::generateUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
namespace Starkerxp\StructureBundle\Tests;
4
5
use Liip\FunctionalTestBundle\Test\WebTestCase;
6
use Starkerxp\UtilisateurBundle\Entity\Utilisateur;
7
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
8
9
abstract class WebTest extends WebTestCase
10
{
11
    protected $identifiant = "[email protected]";
12
    protected $motDePasse = "motMotDePasse";
13
14
    /**
15
     * Erase all database data.
16
     */
17
    public function setUp()
18
    {
19
        $this->loadFixtureFiles([]);
20
    }
21
22
    /**
23
     * Retourne l'entity manager de la connexion defaut.
24
     *
25
     * @return \Doctrine\Common\Persistence\ObjectManager|object
26
     */
27
    public function getEntityManager()
28
    {
29
        return $this->getContainer()->get('doctrine')->getManager();
30
    }
31
32
    public function getAuthClient()
33
    {
34
        $client = static::createClient();
35
        $client->request(
36
            'POST',
37
            '/api/login_check',
38
            [
39
                'identifiant' => $this->identifiant,
40
                'motDePasse'  => $this->motDePasse,
41
            ]
42
        );
43
        $dataHeader = json_decode($client->getResponse()->getContent(), true);
44
45
        $client = static::createClient();
46
        $client->setServerParameter('HTTP_Authorization', sprintf('Bearer %s', $dataHeader['token']));
47
        return $client;
48
    }
49
50
    /**
51
     * Generates a URL from the given parameters.
52
     *
53
     * @param string $route         The name of the route
54
     * @param mixed  $parameters    An array of parameters
55
     * @param int    $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
56
     *
57
     * @return string The generated URL
58
     *
59
     * @see UrlGeneratorInterface
60
     */
61
    protected function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
62
    {
63
        return $this->getContainer()->get('router')->generate($route, $parameters, $referenceType);
64
    }
65
}
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...
66