Merge pull request #10 from utopia-php/error.2

Error.2
This commit is contained in:
Shmuel Fogel authored and GitHub committed 2022-12-25 12:13:30 +02:00
commit 3411d8d732
4 files changed
+86 -59

No files matched your search

+27 -26
View File
@@ -1,28 +1,29 @@
<?php
namespace Utopia\Mongo\Adapter;
use Utopia\Mongo\Adapter;
class SwooleClient extends Adapter
{
public function isConnected(): bool
{
// TODO: Implement isConnected() method.
}
public function connect(string $host, int $port = null, float $timeout = null): bool
{
// TODO: Implement connect() method.
}
public function send(mixed $data): int|bool
{
// TODO: Implement send() method.
}
public function recv(int $timeout = null): string|bool
{
// TODO: Implement recv() method.
}
}
//
//namespace Utopia\Mongo\Adapter;
//
//use Utopia\Mongo\Adapter;
//
//class SwooleClient extends Adapter
//{
// public function isConnected(): bool
// {
// // TODO: Implement isConnected() method.
// }
//
// public function connect(string $host, int $port = null, float $timeout = null): bool
// {
// // TODO: Implement connect() method.
// }
//
// public function send(mixed $data): int|bool
// {
// // TODO: Implement send() method.
// }
//
// public function recv(int $timeout = null): string|bool
// {
// // TODO: Implement recv() method.
// }
//}
+27 -26
View File
@@ -1,28 +1,29 @@
<?php
namespace Utopia\Mongo\Adapter;
use Utopia\Mongo\Adapter;
class SwooleCoroutineClient extends Adapter
{
public function isConnected(): bool
{
// TODO: Implement isConnected() method.
}
public function connect(string $host, int $port = null, float $timeout = null): bool
{
// TODO: Implement connect() method.
}
public function send(mixed $data): int|bool
{
// TODO: Implement send() method.
}
public function recv(int $timeout = null): string|bool
{
// TODO: Implement recv() method.
}
}
//
//namespace Utopia\Mongo\Adapter;
//
//use Utopia\Mongo\Adapter;
//
//class SwooleCoroutineClient extends Adapter
//{
// public function isConnected(): bool
// {
// // TODO: Implement isConnected() method.
// }
//
// public function connect(string $host, int $port = null, float $timeout = null): bool
// {
// // TODO: Implement connect() method.
// }
//
// public function send(mixed $data): int|bool
// {
// // TODO: Implement send() method.
// }
//
// public function recv(int $timeout = null): string|bool
// {
// // TODO: Implement recv() method.
// }
//}
+9 -6
View File
@@ -202,14 +202,21 @@ class Client
$result = BSON\toPHP(substr($res, 21, $responseLength - 21));
if (property_exists($result, "writeErrors")) {
// Throws a Utopia\Mongo\Exception with Code Error
// Throws Utopia\Mongo\Exception
throw new Exception(
$result->writeErrors[0]->errmsg,
$result->writeErrors[0]->code
);
}
if (property_exists($result, 'errmsg')) {
// Throws Utopia\Mongo\Exception
throw new Exception(
'E'.$result->code.' '.$result->codeName.': '.$result->errmsg,
$result->code
);
}
if (property_exists($result, "n") && $result->ok === 1.0) {
return $result->n;
}
@@ -218,10 +225,6 @@ class Client
return $result;
}
if (property_exists($result, 'errmsg')) {
throw new Exception($result->errmsg);
}
if ($result->ok === 1.0) {
return $result;
}
+23 -1
View File
@@ -106,9 +106,31 @@ class MongoTest extends TestCase
self::assertIsArray($doc->array);
self::assertIsString($doc->date_string);
self::assertIsObject($doc->date_object); // Todo: This is not working can't retrieve the object back
}
public function testDriverException()
{
self::expectException('MongoDB\Driver\Exception\InvalidArgumentException');
self::expectExceptionCode(0);
new ObjectId('triggerAnError');
}
public function testDuplicationException()
{
self::expectException(Exception::class);
self::expectExceptionCode(11000);
$this->getDatabase()->insert('movies', ['_id' => 999, 'b' => 'Duplication']);
$this->getDatabase()->insert('movies', ['_id' => 999]);
}
public function testExceedTimeException()
{
self::expectException(Exception::class);
self::expectExceptionCode(50);
$this->getDatabase()->find(
'movies',
['$where' => 'sleep(1000) || true'],
['maxTimeMS'=> 1]
)->cursor->firstBatch ?? [];
}
}