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