1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Codeception\Util\HttpCode; |
4
|
|
|
use SlayerBirden\DataFlowServer\Db\Entities\DbConfiguration; |
5
|
|
|
use SlayerBirden\DataFlowServer\Domain\Entities\User; |
6
|
|
|
|
7
|
|
|
class UpdateConfigCest |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
public function _before(ApiTester $I) |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
$I->haveInRepository(User::class, [ |
12
|
|
|
'id' => 1, |
13
|
|
|
'first' => 'Tester', |
14
|
|
|
'last' => 'Tester', |
15
|
|
|
'email' => '[email protected]', |
16
|
|
|
]); |
17
|
|
|
|
18
|
|
|
$user = $I->grabEntityFromRepository(User::class, ['id' => 1]); |
19
|
|
|
$I->haveInRepository(DbConfiguration::class, [ |
20
|
|
|
'id' => 1, |
21
|
|
|
'owner' => $user, |
22
|
|
|
'title' => 'sqlite config', |
23
|
|
|
'url' => 'sqlite:///data/db/db.sqlite', |
24
|
|
|
]); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function updateConfiguration(ApiTester $I) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$I->wantTo('update db configuration'); |
30
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
31
|
|
|
$I->sendPUT('/config/1', [ |
32
|
|
|
'title' => 'sqlite updated', |
33
|
|
|
'url' => 'sqlite:///data/db/db.sqlite', |
34
|
|
|
]); |
35
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
36
|
|
|
$I->seeResponseContainsJson([ |
37
|
|
|
'success' => true, |
38
|
|
|
'data' => [ |
39
|
|
|
'configuration' => [ |
40
|
|
|
'title' => 'sqlite updated', |
41
|
|
|
'url' => 'sqlite:///data/db/db.sqlite', |
42
|
|
|
] |
43
|
|
|
] |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function updateNonExistingConfig(ApiTester $I) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$I->wantTo('update non existing db configuration'); |
50
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
51
|
|
|
$I->sendPUT('/config/2', [ |
52
|
|
|
'title' => 'Test config', |
53
|
|
|
'url' => 'sqlite:///data/db/db.sqlite', |
54
|
|
|
]); |
55
|
|
|
$I->seeResponseCodeIs(HttpCode::NOT_FOUND); |
56
|
|
|
$I->seeResponseContainsJson([ |
57
|
|
|
'success' => false, |
58
|
|
|
'data' => [ |
59
|
|
|
'configuration' => null |
60
|
|
|
] |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function updateIncompleteConfig(ApiTester $I) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$I->wantTo('update incomplete db configuration'); |
67
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
68
|
|
|
$I->sendPOST('/config', [ |
69
|
|
|
'title' => 'Test config', |
70
|
|
|
]); |
71
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
72
|
|
|
$I->seeResponseContainsJson([ |
73
|
|
|
'success' => false, |
74
|
|
|
'data' => [ |
75
|
|
|
'validation' => [ |
76
|
|
|
[ |
77
|
|
|
'field' => 'user', |
78
|
|
|
] |
79
|
|
|
] |
80
|
|
|
] |
81
|
|
|
]); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.