From 1e97f66cdf97ac3bd4c0d0a3339bafd8389beab4 Mon Sep 17 00:00:00 2001 From: beau-dev Date: Sat, 23 Nov 2024 16:55:33 +0100 Subject: [PATCH] fix: issue when using Future class --- src/Cbor/Types/Future.php | 2 +- tests/core/cbor/FutureTest.php | 21 +++++++++++++++++++++ tests/protocols/http/QueryTest.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/core/cbor/FutureTest.php diff --git a/src/Cbor/Types/Future.php b/src/Cbor/Types/Future.php index e25c994..b7fb2e1 100644 --- a/src/Cbor/Types/Future.php +++ b/src/Cbor/Types/Future.php @@ -25,6 +25,6 @@ public function __toString(): string public function toString(): string { - return " { $this->inner }"; + return " $this->inner"; } } \ No newline at end of file diff --git a/tests/core/cbor/FutureTest.php b/tests/core/cbor/FutureTest.php new file mode 100644 index 0000000..e04a428 --- /dev/null +++ b/tests/core/cbor/FutureTest.php @@ -0,0 +1,21 @@ +assertEquals(" time::now()", $future->__toString()); + } + + public function testJsonSerialize() + { + $future = new Future("time::now()"); + $this->assertEquals(" time::now()", $future->jsonSerialize()); + } +} \ No newline at end of file diff --git a/tests/protocols/http/QueryTest.php b/tests/protocols/http/QueryTest.php index 18b7ef9..8a12b78 100644 --- a/tests/protocols/http/QueryTest.php +++ b/tests/protocols/http/QueryTest.php @@ -5,6 +5,7 @@ use Beau\CborPHP\exceptions\CborException; use Exception; use PHPUnit\Framework\TestCase; +use Surreal\Cbor\Types\Future; use Surreal\Cbor\Types\None; use Surreal\Cbor\Types\Record\RecordId; use Surreal\Cbor\Types\Table; @@ -184,4 +185,31 @@ function: "fn::greet", $db->close(); } + + public function testFutureQuery(): void + { + $db = $this->getDb(); + + $future = new Future("duration::years(time::now() - birthday) >= 18"); + $db->let("canDrive", $future); + + $response = $db->query(' + CREATE future_test + SET + birthday = "2000-06-22", + can_drive = $canDrive + '); + + $this->assertIsArray($response); + + [$data] = $response; + + $this->assertArrayHasKey("result", $data); + $this->assertArrayHasKey("time", $data); + $this->assertArrayHasKey("status", $data); + + $this->assertEquals("OK", $data["status"]); + + $db->close(); + } } \ No newline at end of file