Skip to content

Commit 5dfed5a

Browse files
updated test strcuture to test the exceptions
1 parent 9a8756a commit 5dfed5a

2 files changed

Lines changed: 20 additions & 60 deletions

File tree

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3970,12 +3970,8 @@ public function testDeleteBulkDocuments(): void
39703970
}
39713971
);
39723972
} catch (Exception $e) {
3973-
if ($e instanceof Exception) {
3974-
$this->assertInstanceOf(Exception::class, $e);
3975-
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
3976-
} else {
3977-
$this->fail("Caught value is not an Exception.");
3978-
}
3973+
$this->assertInstanceOf(Exception::class, $e);
3974+
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
39793975
}
39803976

39813977
$count = $database->deleteDocuments(
@@ -3993,12 +3989,8 @@ public function testDeleteBulkDocuments(): void
39933989
throw new Exception("Error thrown to test that deletion doesn't stop and error is caught");
39943990
},
39953991
onError:function ($e) {
3996-
if ($e instanceof Exception) {
3997-
$this->assertInstanceOf(Exception::class, $e);
3998-
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
3999-
} else {
4000-
$this->fail("Caught value is not an Exception.");
4001-
}
3992+
$this->assertInstanceOf(Exception::class, $e);
3993+
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
40023994
}
40033995
);
40043996

@@ -4008,12 +4000,8 @@ public function testDeleteBulkDocuments(): void
40084000
$this->assertEquals(8, $database->deleteDocuments('bulk_delete', onNext: function () {
40094001
throw new Exception("Error thrown to test that deletion doesn't stop and error is caught");
40104002
}, onError:function ($e) {
4011-
if ($e instanceof Exception) {
4012-
$this->assertInstanceOf(Exception::class, $e);
4013-
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
4014-
} else {
4015-
$this->fail("Caught value is not an Exception.");
4016-
}
4003+
$this->assertInstanceOf(Exception::class, $e);
4004+
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
40174005
}));
40184006

40194007
$docs = $database->find('bulk_delete');
@@ -4029,12 +4017,8 @@ public function testDeleteBulkDocuments(): void
40294017
$results[] = $doc;
40304018
throw new Exception("Error thrown to test that deletion doesn't stop and error is caught");
40314019
}, onError:function ($e) {
4032-
if ($e instanceof Exception) {
4033-
$this->assertInstanceOf(Exception::class, $e);
4034-
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
4035-
} else {
4036-
$this->fail("Caught value is not an Exception.");
4037-
}
4020+
$this->assertInstanceOf(Exception::class, $e);
4021+
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
40384022
});
40394023

40404024
$this->assertEquals(5, $count);
@@ -4107,12 +4091,8 @@ public function testDeleteBulkDocuments(): void
41074091
$database->deleteDocuments('bulk_delete', onNext: function () {
41084092
throw new Exception("Error thrown to test that deletion doesn't stop and error is caught");
41094093
}, onError:function ($e) {
4110-
if ($e instanceof Exception) {
4111-
$this->assertInstanceOf(Exception::class, $e);
4112-
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
4113-
} else {
4114-
$this->fail("Caught value is not an Exception.");
4115-
}
4094+
$this->assertInstanceOf(Exception::class, $e);
4095+
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
41164096
});
41174097

41184098
$this->assertEquals(0, \count($this->getDatabase()->find('bulk_delete')));
@@ -4161,24 +4141,16 @@ public function testDeleteBulkDocumentsQueries(): void
41614141
$this->assertEquals(5, $database->deleteDocuments('bulk_delete_queries', [Query::limit(5)], onNext: function () {
41624142
throw new Exception("Error thrown to test that deletion doesn't stop and error is caught");
41634143
}, onError:function ($e) {
4164-
if ($e instanceof Exception) {
4165-
$this->assertInstanceOf(Exception::class, $e);
4166-
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
4167-
} else {
4168-
$this->fail("Caught value is not an Exception.");
4169-
}
4144+
$this->assertInstanceOf(Exception::class, $e);
4145+
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
41704146
}));
41714147
$this->assertEquals(5, \count($database->find('bulk_delete_queries')));
41724148

41734149
$this->assertEquals(5, $database->deleteDocuments('bulk_delete_queries', [Query::limit(5)], onNext: function () {
41744150
throw new Exception("Error thrown to test that deletion doesn't stop and error is caught");
41754151
}, onError:function ($e) {
4176-
if ($e instanceof Exception) {
4177-
$this->assertInstanceOf(Exception::class, $e);
4178-
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
4179-
} else {
4180-
$this->fail("Caught value is not an Exception.");
4181-
}
4152+
$this->assertInstanceOf(Exception::class, $e);
4153+
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
41824154
}));
41834155
$this->assertEquals(0, \count($database->find('bulk_delete_queries')));
41844156

tests/e2e/Adapter/Scopes/Relationships/ManyToManyTests.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,12 +1584,8 @@ public function testDeleteBulkDocumentsManyToManyRelationship(): void
15841584
$this->getDatabase()->deleteDocuments('bulk_delete_person_m2m', onNext: function () {
15851585
throw new Exception("Error thrown to test that deletion doesn't stop and error is caught");
15861586
}, onError:function ($e) {
1587-
if ($e instanceof Exception) {
1588-
$this->assertInstanceOf(Exception::class, $e);
1589-
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
1590-
} else {
1591-
$this->fail("Caught value is not an Exception.");
1592-
}
1587+
$this->assertInstanceOf(Exception::class, $e);
1588+
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
15931589
});
15941590
$this->fail('Failed to throw exception');
15951591
} catch (RestrictedException $e) {
@@ -1601,24 +1597,16 @@ public function testDeleteBulkDocumentsManyToManyRelationship(): void
16011597
$this->getDatabase()->deleteDocuments('bulk_delete_library_m2m', onNext: function () {
16021598
throw new Exception("Error thrown to test that deletion doesn't stop and error is caught");
16031599
}, onError:function ($e) {
1604-
if ($e instanceof Exception) {
1605-
$this->assertInstanceOf(Exception::class, $e);
1606-
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
1607-
} else {
1608-
$this->fail("Caught value is not an Exception.");
1609-
}
1600+
$this->assertInstanceOf(Exception::class, $e);
1601+
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
16101602
});
16111603
$this->assertCount(0, $this->getDatabase()->find('bulk_delete_library_m2m'));
16121604

16131605
$this->getDatabase()->deleteDocuments('bulk_delete_person_m2m', onNext: function () {
16141606
throw new Exception("Error thrown to test that deletion doesn't stop and error is caught");
16151607
}, onError:function ($e) {
1616-
if ($e instanceof Exception) {
1617-
$this->assertInstanceOf(Exception::class, $e);
1618-
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
1619-
} else {
1620-
$this->fail("Caught value is not an Exception.");
1621-
}
1608+
$this->assertInstanceOf(Exception::class, $e);
1609+
$this->assertEquals("Error thrown to test that deletion doesn't stop and error is caught", $e->getMessage());
16221610
});
16231611
$this->assertCount(0, $this->getDatabase()->find('bulk_delete_person_m2m'));
16241612
}

0 commit comments

Comments
 (0)