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
|
|
|
} |
|
|
|
|
66
|
|
|
|
This check marks files that end in a newline character, i.e. an empy line.