This repository has been archived by the owner on Oct 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJsonApiAsArrayTestCase.php
73 lines (61 loc) · 2.17 KB
/
JsonApiAsArrayTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace EveryCheck\TestApiRestBundle\Controller;
use EveryCheck\TestApiRestBundle\Entity\TestDataChunk;
use EveryCheck\TestApiRestBundle\ControllerTestTrait\DatabaseTestTrait;
use EveryCheck\TestApiRestBundle\ControllerTestTrait\ApiCallTestTrait;
use EveryCheck\TestApiRestBundle\ControllerTestTrait\EmailTestTrait;
class JsonApiAsArrayTestCase extends AbstractBaseControllerTestClass
{
use DatabaseTestTrait;
use ApiCallTestTrait;
use EmailTestTrait;
const JSON_HEADER = 'application/json';
const PDF_HEADER = 'application/pdf';
const PNG_HEADER = 'image/png';
protected $env = [];
protected $current;
public function onNotSuccessfulTest(\Throwable $t){
if($this->current instanceof TestDataChunk)
{
dump($this->current->data);
}
parent::onNotSuccessfulTest($t);
}
public function genericTestAPICall(TestDataChunk $dataTest)
{
$this->payloadsDir = $this->client->getKernel()->getContainer()->getParameter('test_api_rest.directory.payloads');
$this->responsesDir = $this->client->getKernel()->getContainer()->getParameter('test_api_rest.directory.responses');
$this->current = $dataTest;
if($dataTest->kind == TestDataChunk::KIND_SCENARIO)
{
foreach ($dataTest->data as $subDataTest)
{
$this->genericTestAPICall($subDataTest);
}
}
else if($dataTest->kind == TestDataChunk::KIND_DATABASE)
{
$this->assertDatabase($dataTest);
}
else if($dataTest->kind == TestDataChunk::KIND_UNIT_TEST)
{
$this->assertApiRestCall($dataTest);
}
}
protected function extractValueFromEnvIfNeeded(&$array)
{
foreach ($array as $key => $value)
{
$array[$key] = $this->getReferencedEnvVariableOrValue($value);
}
}
protected function getReferencedEnvVariableOrValue($value)
{
$match = [];
while (preg_match('/#(\w+)#/', $value,$match))
{
$value = str_replace('#'.$match[1].'#', $this->env[$match[1]], $value);
}
return $value;
}
}