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 DeleteConfigCest |
11
|
|
|
{ |
12
|
|
|
public function _before(ApiTester $I) |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$user = $I->grabEntityFromRepository(User::class, ['id' => 1]); |
15
|
|
|
$I->haveInRepository(DbConfiguration::class, [ |
16
|
|
|
'owner' => $user, |
17
|
|
|
'title' => 'Test config', |
18
|
|
|
'url' => 'sqlite:///data/db/db.sqlite', |
19
|
|
|
]); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function deleteConfiguration(ApiTester $I) |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$I->wantTo('delete db configuration'); |
25
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
26
|
|
|
$I->sendDELETE('/config/1'); |
27
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
28
|
|
|
$I->seeResponseContainsJson([ |
29
|
|
|
'data' => [ |
30
|
|
|
'configuration' => [ |
31
|
|
|
'title' => 'Test config', |
32
|
|
|
] |
33
|
|
|
] |
34
|
|
|
]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function deleteNonExistingConfiguration(ApiTester $I) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$I->wantTo('delete non-existing db configuration'); |
40
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
41
|
|
|
$I->sendDELETE('/config/0'); |
42
|
|
|
$I->seeResponseCodeIs(HttpCode::NOT_FOUND); |
43
|
|
|
$I->seeResponseContainsJson([ |
44
|
|
|
'data' => [ |
45
|
|
|
'configuration' => null |
46
|
|
|
] |
47
|
|
|
]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function deleteSomeoneElsesConfiguration(ApiTester $I) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$userId = $I->haveInRepository(User::class, [ |
53
|
|
|
'first' => 'Tester2', |
54
|
|
|
'last' => 'Tester2', |
55
|
|
|
'email' => '[email protected]', |
56
|
|
|
]); |
57
|
|
|
$user = $I->grabEntityFromRepository(User::class, ['id' => $userId]); |
58
|
|
|
$I->haveInRepository(DbConfiguration::class, [ |
59
|
|
|
'owner' => $user, |
60
|
|
|
'title' => 'Test config 2', |
61
|
|
|
'url' => 'sqlite:///data/db/db2.sqlite', |
62
|
|
|
]); |
63
|
|
|
|
64
|
|
|
$I->wantTo('delete someone elses db configuration'); |
65
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
66
|
|
|
$I->sendDELETE('/config/2'); |
67
|
|
|
$I->seeResponseCodeIs(HttpCode::FORBIDDEN); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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.