|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace codecept\configuration; |
|
4
|
|
|
|
|
5
|
|
|
use codecept\ApiTester; |
|
6
|
|
|
use Codeception\Util\HttpCode; |
|
7
|
|
|
use SlayerBirden\DataFlowServer\Db\Entities\DbConfiguration; |
|
8
|
|
|
use SlayerBirden\DataFlowServer\Domain\Entities\User; |
|
9
|
|
|
|
|
10
|
|
|
class UpdateConfigCest |
|
11
|
|
|
{ |
|
12
|
|
|
public function _before(ApiTester $I) |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
$user = $I->grabEntityFromRepository(User::class, ['id' => 1]); |
|
15
|
|
|
$I->haveInRepository(DbConfiguration::class, [ |
|
16
|
|
|
'id' => 1, |
|
17
|
|
|
'owner' => $user, |
|
18
|
|
|
'title' => 'sqlite config', |
|
19
|
|
|
'url' => 'sqlite:///data/db/db.sqlite', |
|
20
|
|
|
]); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function updateConfiguration(ApiTester $I) |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
$I->wantTo('update db configuration'); |
|
26
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
|
27
|
|
|
$I->sendPUT('/config/1', [ |
|
28
|
|
|
'title' => 'sqlite updated', |
|
29
|
|
|
'url' => 'sqlite:///data/db/db.sqlite', |
|
30
|
|
|
]); |
|
31
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
|
32
|
|
|
$I->seeResponseContainsJson([ |
|
33
|
|
|
'success' => true, |
|
34
|
|
|
'data' => [ |
|
35
|
|
|
'configuration' => [ |
|
36
|
|
|
'title' => 'sqlite updated', |
|
37
|
|
|
'url' => 'sqlite:///data/db/db.sqlite', |
|
38
|
|
|
] |
|
39
|
|
|
] |
|
40
|
|
|
]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function updateNonExistingConfig(ApiTester $I) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
$I->wantTo('update non existing db configuration'); |
|
46
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
|
47
|
|
|
$I->sendPUT('/config/0', [ |
|
48
|
|
|
'title' => 'Test config', |
|
49
|
|
|
'url' => 'sqlite:///data/db/db.sqlite', |
|
50
|
|
|
]); |
|
51
|
|
|
$I->seeResponseCodeIs(HttpCode::NOT_FOUND); |
|
52
|
|
|
$I->seeResponseContainsJson([ |
|
53
|
|
|
'success' => false, |
|
54
|
|
|
'data' => [ |
|
55
|
|
|
'configuration' => null |
|
56
|
|
|
] |
|
57
|
|
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function updateIncompleteConfig(ApiTester $I) |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
$I->wantTo('update incomplete db configuration'); |
|
63
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
|
64
|
|
|
$I->sendPUT('/config/1', [ |
|
65
|
|
|
'title' => 'Test config', |
|
66
|
|
|
]); |
|
67
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
|
68
|
|
|
$I->seeResponseContainsJson([ |
|
69
|
|
|
'success' => false, |
|
70
|
|
|
'data' => [ |
|
71
|
|
|
'validation' => [ |
|
72
|
|
|
[ |
|
73
|
|
|
'field' => 'user', |
|
74
|
|
|
] |
|
75
|
|
|
] |
|
76
|
|
|
] |
|
77
|
|
|
]); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
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.