Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Database/Validator/QueryValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Utopia\Database\Validator;

use Utopia\Validator;
use Utopia\Database\Document;
use Utopia\Database\Query;

class QueryValidator extends Validator
Expand Down Expand Up @@ -34,11 +35,13 @@ class QueryValidator extends Validator
/**
* Expression constructor
*
* @param array $schema
* @param Document[] $attributes
*/
public function __construct($schema)
public function __construct(array $attributes)
{
$this->schema = $schema;
foreach ($attributes as $attribute) {
$this->schema[] = $attribute->getArrayCopy();
}
}

/**
Expand Down
8 changes: 7 additions & 1 deletion tests/Database/Validator/QueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ class QueriesTest extends TestCase

public function setUp(): void
{
$this->queryValidator = new QueryValidator($this->collection['attributes']);
// Query validator expects Document[]
$attributes = []; /** @var Document[] $attributes */
foreach ($this->collection['attributes'] as $attribute) {
$attributes[] = new Document($attribute);
}

$this->queryValidator = new QueryValidator($attributes);

$query1 = Query::parse('title.notEqual("Iron Man", "Ant Man")');
$query2 = Query::parse('description.equal("Best movie ever")');
Expand Down
14 changes: 12 additions & 2 deletions tests/Database/Validator/QueryValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
use Utopia\Database\Validator\QueryValidator;
use PHPUnit\Framework\TestCase;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Query;

class QueryValidatorTest extends TestCase
{
/**
* @var array
* @var Document[]
*/
protected $schema = [
protected $schema;

/**
* @var array
*/
protected $attributes = [
[
'$id' => 'title',
'key' => 'title',
Expand Down Expand Up @@ -77,6 +83,10 @@ class QueryValidatorTest extends TestCase

public function setUp(): void
{
// Query validator expects Document[]
foreach ($this->attributes as $attribute) {
$this->schema[] = new Document($attribute);
}
}

public function tearDown(): void
Expand Down