|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace codecept\configuration; |
|
4
|
|
|
|
|
5
|
|
|
use codecept\ApiTester; |
|
6
|
|
|
use Codeception\Util\HttpCode; |
|
7
|
|
|
use SlayerBirden\DataFlowServer\Doctrine\Hydrator\Strategy\ObscuredStrategy; |
|
8
|
|
|
|
|
9
|
|
|
class AddConfigCest |
|
10
|
|
|
{ |
|
11
|
|
|
public function addConfiguration(ApiTester $I) |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
$I->wantTo('create db configuration'); |
|
14
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
|
15
|
|
|
$I->sendPOST('/config', [ |
|
16
|
|
|
'title' => 'Test config', |
|
17
|
|
|
'url' => 'test_url', |
|
18
|
|
|
]); |
|
19
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
|
20
|
|
|
$I->seeResponseContainsJson([ |
|
21
|
|
|
'success' => true, |
|
22
|
|
|
'data' => [ |
|
23
|
|
|
'configuration' => [ |
|
24
|
|
|
'title' => 'Test config', |
|
25
|
|
|
'url' => 'test_url', |
|
26
|
|
|
] |
|
27
|
|
|
] |
|
28
|
|
|
]); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function addIncompleteConfig(ApiTester $I) |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
$I->wantTo('create incomplete db configuration'); |
|
34
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
|
35
|
|
|
$I->sendPOST('/config', [ |
|
36
|
|
|
'title' => 'Test config', |
|
37
|
|
|
'dbname' => 'test', |
|
38
|
|
|
]); |
|
39
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
|
40
|
|
|
$I->seeResponseContainsJson([ |
|
41
|
|
|
'success' => false, |
|
42
|
|
|
'data' => [ |
|
43
|
|
|
'validation' => [ |
|
44
|
|
|
[ |
|
45
|
|
|
'field' => 'user', |
|
46
|
|
|
] |
|
47
|
|
|
] |
|
48
|
|
|
] |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function addCompleteNonUrlConfig(ApiTester $I) |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
$I->wantTo('create incomplete db configuration'); |
|
55
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
|
56
|
|
|
$I->sendPOST('/config', [ |
|
57
|
|
|
'title' => 'Test config', |
|
58
|
|
|
'dbname' => 'test', |
|
59
|
|
|
'user' => 'test-user', |
|
60
|
|
|
'password' => 'test-pwd', |
|
61
|
|
|
'port' => '3306', |
|
62
|
|
|
'host' => 'localhost', |
|
63
|
|
|
'driver' => 'pdo_mysql' |
|
64
|
|
|
]); |
|
65
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
|
66
|
|
|
$I->seeResponseContainsJson([ |
|
67
|
|
|
'success' => true, |
|
68
|
|
|
'data' => [ |
|
69
|
|
|
'configuration' => [ |
|
70
|
|
|
'title' => 'Test config', |
|
71
|
|
|
'dbname' => 'test', |
|
72
|
|
|
'user' => 'test-user', |
|
73
|
|
|
'password' => ObscuredStrategy::OBSCURED_STRING, |
|
74
|
|
|
'port' => '3306', |
|
75
|
|
|
'host' => 'localhost', |
|
76
|
|
|
'driver' => 'pdo_mysql' |
|
77
|
|
|
] |
|
78
|
|
|
] |
|
79
|
|
|
]); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.