1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests; |
4
|
|
|
|
5
|
|
|
use JsonSchema\Validator; |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
trait AbstractAppTest |
9
|
|
|
{ |
10
|
|
|
public function createApplication() |
11
|
|
|
{ |
12
|
|
|
// print_r("DBG creao app"); |
|
|
|
|
13
|
|
|
//$app = require_once __DIR__.'/../../src/App.php'; |
|
|
|
|
14
|
|
|
$config = require_once ROOT_PATH.'/config.php'; |
|
|
|
|
15
|
|
|
$app = require_once ROOT_PATH.'/src/App.php'; |
16
|
|
|
$app['debug'] = true; |
17
|
|
|
$app['session.test'] = true; |
18
|
|
|
#unset($app['exception_handler']); |
|
|
|
|
19
|
|
|
return $app; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function logIn($client) |
23
|
|
|
{ |
24
|
|
|
$client->request( |
25
|
|
|
'POST', |
26
|
|
|
'/api/v1/security/login', |
27
|
|
|
[], |
28
|
|
|
[], |
29
|
|
|
['CONTENT_TYPE' => 'application/json'], |
30
|
|
|
'{"authMode":"Email","email":"[email protected]","name":"ugo","surname":"ugo","password":"cane"}'); |
31
|
|
|
return $client; |
32
|
|
|
} |
33
|
|
|
public function logIn2($client) |
34
|
|
|
{ |
35
|
|
|
$client->request( |
36
|
|
|
'POST', |
37
|
|
|
'/api/v1/security/login', |
38
|
|
|
[], |
39
|
|
|
[], |
40
|
|
|
['CONTENT_TYPE' => 'application/json'], |
41
|
|
|
'{"authMode":"Email","email":"ugo2","name":"ugo2","surname":"ugo2","password":"cane"}'); |
42
|
|
|
return $client; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $schema |
47
|
|
|
*/ |
48
|
|
|
public function askValidation($data, $schema) |
49
|
|
|
{ |
50
|
|
|
$validator = new \JsonSchema\Validator; |
51
|
|
|
$js_schema = (object)['$ref' => 'file://'.$schema]; |
52
|
|
|
$validator->check(json_decode($data), $js_schema); |
53
|
|
|
return $validator; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function evalValidation($validator) { |
57
|
|
|
$assert = false; |
|
|
|
|
58
|
|
|
if ($validator->isValid()) { |
59
|
|
|
echo "The supplied JSON validates against the schema.\n"; |
60
|
|
|
$assert = true; |
61
|
|
|
} else { |
62
|
|
|
echo "JSON does not validate. Violations:\n"; |
63
|
|
|
foreach ($validator->getErrors() as $error) { |
64
|
|
|
echo "[{$error['property']}] {$error['message']}\n"; |
65
|
|
|
} |
66
|
|
|
$assert = false; |
67
|
|
|
} |
68
|
|
|
return $assert; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.