Skip to content

Commit 9cc30b7

Browse files
committed
slightly cleaned up test cases
1 parent 0327d0c commit 9cc30b7

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

tests/UserBasicTest.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ class UserBasicTest extends
2323
public function setUp()
2424
{
2525
$this->connection = getConnection();
26+
$this->userHandler = new UserHandler($this->connection);
27+
28+
try {
29+
$this->userHandler->removeUser('testUser1');
30+
} catch (\Exception $e) {
31+
}
32+
33+
try {
34+
$this->userHandler->removeUser('testUser42');
35+
} catch (\Exception $e) {
36+
}
2637
}
2738

2839

@@ -31,8 +42,6 @@ public function setUp()
3142
*/
3243
public function testGrantPermission()
3344
{
34-
$this->userHandler = new UserHandler($this->connection);
35-
3645
$result = $this->userHandler->addUser('testUser42', 'testPasswd', true);
3746
static::assertTrue($result);
3847

@@ -65,8 +74,6 @@ public function testGrantPermission()
6574
*/
6675
public function testGrantAndRevokePermissions()
6776
{
68-
$this->userHandler = new UserHandler($this->connection);
69-
7077
$result = $this->userHandler->addUser('testUser42', 'testPasswd', true);
7178
static::assertTrue($result);
7279

@@ -95,13 +102,10 @@ public function testGrantAndRevokePermissions()
95102

96103

97104
/**
98-
* Test if Document and DocumentHandler instances can be initialized
105+
* Test if a user can be added, replaced, updated and removed
99106
*/
100107
public function testAddReplaceUpdateGetAndDeleteUserWithNullValues()
101108
{
102-
$this->userHandler = new UserHandler($this->connection);
103-
104-
105109
$result = $this->userHandler->addUser('testUser1', null, null, null);
106110
static::assertTrue($result);
107111

@@ -116,6 +120,14 @@ public function testAddReplaceUpdateGetAndDeleteUserWithNullValues()
116120

117121
$this->userHandler->removeUser('testUser1');
118122
static::assertTrue($result);
123+
124+
try {
125+
$this->userHandler->get('testUser1');
126+
} catch (\Exception $e) {
127+
// Just give us the $e
128+
static::assertEquals(404, $e->getCode(), 'Should get 404, instead got: ' . $e->getCode());
129+
}
130+
static::assertInstanceOf(ServerException::class, $e, 'should have gotten an exception');
119131
}
120132

121133

@@ -124,8 +136,6 @@ public function testAddReplaceUpdateGetAndDeleteUserWithNullValues()
124136
*/
125137
public function testAddReplaceUpdateGetAndDeleteUserWithNonNullValues()
126138
{
127-
$this->userHandler = new UserHandler($this->connection);
128-
129139
$result = $this->userHandler->addUser('testUser1', 'testPass1', true, ['level' => 1]);
130140
static::assertTrue($result);
131141

@@ -174,8 +184,6 @@ public function testAddReplaceUpdateGetAndDeleteUserWithNonNullValues()
174184
// test functions on non-existent user
175185
public function testFunctionsOnNonExistentUser()
176186
{
177-
$this->userHandler = new UserHandler($this->connection);
178-
179187
$e = null;
180188
try {
181189
$this->userHandler->removeUser('testUser1');

0 commit comments

Comments
 (0)