Skip to content

Commit

Permalink
fix: issue when using Future class (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
welpie21 authored Dec 12, 2024
1 parent 21ded19 commit 3a3a6e2
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 4 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"phpstan": "vendor/bin/phpstan -c phpstan.neon",
"test-coverage-v1": "./vendor/bin/phpunit -c tests/phpunit_config_v1.xml",
"test-coverage-v2": "./vendor/bin/phpunit -c tests/phpunit_config_v2.xml",
"run-surreal-1.4.2": "docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:v1.4.2 start --auth --user root --pass root --allow-all --log trace ",
"run-surreal-1.5.4": "docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:v1.5.4 start --auth --user root --pass root --allow-all --log trace ",
"run-surreal-2.0.4": "docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:v2.0.4 start --username root --pass root --allow-all --log trace"
"run-surreal-1.4.2": "docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:v1.4.2 start --auth --user root --pass root --allow-all --strict --log trace ",
"run-surreal-1.5.4": "docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:v1.5.4 start --auth --user root --pass root --allow-all --strict --log trace ",
"run-surreal-2.0.4": "docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:v2.0.4 start --username root --pass root --allow-all --strict --log trace"
},
"authors": [
{
Expand Down
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";
}
}
22 changes: 22 additions & 0 deletions tests/core/cbor/FutureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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());
$this->assertEquals("<future> { time::now() }", $future->toString());
}

public function testJsonSerialize()
{
$future = new Future("{ time::now() }");
$this->assertEquals("<future> { time::now() }", $future->jsonSerialize());
}
}
1 change: 1 addition & 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
3 changes: 3 additions & 0 deletions tests/v1/assets/setup.surql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ DEFINE TABLE likes
DEFINE TABLE test
PERMISSIONS FULL;

DEFINE TABLE future_test
PERMISSIONS FULL;

DEFINE TABLE user
PERMISSIONS
FOR select WHERE id = $auth.id;
Expand Down
3 changes: 3 additions & 0 deletions tests/v2/assets/setup.surql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ DEFINE TABLE insert_relation
DEFINE TABLE upsert
PERMISSIONS FULL;

DEFINE TABLE future_test
PERMISSIONS FULL;

DEFINE TABLE user
PERMISSIONS
FOR select WHERE id = $auth.id;
Expand Down
56 changes: 56 additions & 0 deletions tests/v2/query/FutureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace v2\query;

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

class FutureTest extends TestCase
{
private function getDb(): Surreal
{
$db = new Surreal();
$db->connect("http://localhost:8000", [
"namespace" => "test",
"database" => "test"
]);

$token = $db->signin([
"user" => "root",
"pass" => "root"
]);

$this->assertIsString($token, "Token is not a string");

return $db;
}

public function testFutureQuery(): void
{
$db = $this->getDb();

$future = new Future("{ duration::years(time::now() - birthday) >= 18 }");
$db->let("canDrive", $future);

$response = $db->queryRaw('
CREATE future_test
SET
birthday = time::now(),
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"]);
$this->assertFalse($data["result"][0]["can_drive"]);

$db->close();
}
}

0 comments on commit 3a3a6e2

Please sign in to comment.