Skip to content

Commit

Permalink
fix: issue when using Future class
Browse files Browse the repository at this point in the history
  • Loading branch information
welpie21 committed Nov 23, 2024
1 parent 9f4f0b7 commit 1e97f66
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Cbor/Types/Future.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function __toString(): string

public function toString(): string
{
return "<future> { $this->inner }";
return "<future> $this->inner";
}
}
21 changes: 21 additions & 0 deletions tests/core/cbor/FutureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace core\cbor;

use PHPUnit\Framework\TestCase;
use Surreal\Cbor\Types\Future;

class FutureTest extends TestCase
{
public function testToString()
{
$future = new Future("time::now()");
$this->assertEquals("<future> time::now()", $future->__toString());
}

public function testJsonSerialize()
{
$future = new Future("time::now()");
$this->assertEquals("<future> time::now()", $future->jsonSerialize());
}
}
28 changes: 28 additions & 0 deletions tests/protocols/http/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = <datetime> "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();
}
}

0 comments on commit 1e97f66

Please sign in to comment.