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
|
|
|
'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
|
|
|
'data' => [ |
53
|
|
|
'configuration' => null |
54
|
|
|
] |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function updatePartialConfig(ApiTester $I) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$I->wantTo('update only 1 field'); |
61
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
62
|
|
|
$I->sendPUT('/config/1', [ |
63
|
|
|
'title' => 'Test config', |
64
|
|
|
]); |
65
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
66
|
|
|
$I->seeResponseContainsJson([ |
67
|
|
|
'data' => [ |
68
|
|
|
'configuration' => [ |
69
|
|
|
'title' => 'Test config', |
70
|
|
|
] |
71
|
|
|
] |
72
|
|
|
]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function updateIncompleteConfig(ApiTester $I) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$I->wantTo('update incomplete db configuration'); |
78
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
79
|
|
|
$I->sendPOST('/config', [ |
80
|
|
|
'title' => 'Test config', |
81
|
|
|
'dbname' => 'test', |
82
|
|
|
'url' => null, |
83
|
|
|
]); |
84
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.