|
| 1 | +<?php |
| 2 | +
|
| 3 | +namespace Appwrite; |
| 4 | +
|
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +
|
| 7 | +final class BasicFilterQueryTest { |
| 8 | + public string $description; |
| 9 | + public mixed $value; |
| 10 | + public string $expectedValues; |
| 11 | +
|
| 12 | + public function __construct(string $description, mixed $value, string $expectedValues) { |
| 13 | + $this->description = $description; |
| 14 | + $this->value = $value; |
| 15 | + $this->expectedValues = $expectedValues; |
| 16 | + } |
| 17 | +} |
| 18 | +
|
| 19 | +final class QueryTest extends TestCase { |
| 20 | + /** |
| 21 | + * @var BasicFilterQueryTest[] $tests |
| 22 | + */ |
| 23 | + private array $tests; |
| 24 | +
|
| 25 | + function __construct(string $name) |
| 26 | + { |
| 27 | + parent::__construct($name); |
| 28 | + $this->tests = array( |
| 29 | + new BasicFilterQueryTest('with a string', 's', '["s"]'), |
| 30 | + new BasicFilterQueryTest('with a integer', 1, '[1]'), |
| 31 | + new BasicFilterQueryTest('with a double', 1.2, '[1.2]'), |
| 32 | + new BasicFilterQueryTest('with a whole number double', 1.0, '[1]'), |
| 33 | + new BasicFilterQueryTest('with a bool', false, '[false]'), |
| 34 | + new BasicFilterQueryTest('with a list', ['a', 'b', 'c'], '["a","b","c"]'), |
| 35 | + ); |
| 36 | + } |
| 37 | +
|
| 38 | + public function testBasicFilterEqual(): void { |
| 39 | + foreach($this->tests as $test) { |
| 40 | + $this->assertSame( |
| 41 | + "equal(\"attr\", $test->expectedValues)", |
| 42 | + Query::equal('attr', $test->value), |
| 43 | + $test->description, |
| 44 | + ); |
| 45 | + } |
| 46 | + } |
| 47 | +
|
| 48 | + public function testBasicFilterNotEqual(): void { |
| 49 | + foreach($this->tests as $test) { |
| 50 | + $this->assertSame( |
| 51 | + "notEqual(\"attr\", $test->expectedValues)", |
| 52 | + Query::notEqual('attr', $test->value), |
| 53 | + $test->description, |
| 54 | + ); |
| 55 | + } |
| 56 | + } |
| 57 | +
|
| 58 | + public function testBasicFilterLessThan(): void { |
| 59 | + foreach($this->tests as $test) { |
| 60 | + $this->assertSame( |
| 61 | + "lessThan(\"attr\", $test->expectedValues)", |
| 62 | + Query::lessThan('attr', $test->value), |
| 63 | + $test->description, |
| 64 | + ); |
| 65 | + } |
| 66 | + } |
| 67 | +
|
| 68 | + public function testBasicFilterLessThanEqual(): void { |
| 69 | + foreach($this->tests as $test) { |
| 70 | + $this->assertSame( |
| 71 | + "lessThanEqual(\"attr\", $test->expectedValues)", |
| 72 | + Query::lessThanEqual('attr', $test->value), |
| 73 | + $test->description, |
| 74 | + ); |
| 75 | + } |
| 76 | + } |
| 77 | +
|
| 78 | + public function testBasicFilterGreaterThan(): void { |
| 79 | + foreach($this->tests as $test) { |
| 80 | + $this->assertSame( |
| 81 | + "greaterThan(\"attr\", $test->expectedValues)", |
| 82 | + Query::greaterThan('attr', $test->value), |
| 83 | + $test->description, |
| 84 | + ); |
| 85 | + } |
| 86 | + } |
| 87 | +
|
| 88 | + public function testBasicFilterGreaterThanEqual(): void { |
| 89 | + foreach($this->tests as $test) { |
| 90 | + $this->assertSame( |
| 91 | + "greaterThanEqual(\"attr\", $test->expectedValues)", |
| 92 | + Query::greaterThanEqual('attr', $test->value), |
| 93 | + $test->description, |
| 94 | + ); |
| 95 | + } |
| 96 | + } |
| 97 | +
|
| 98 | + public function testSearch(): void { |
| 99 | + $this->assertSame('search("attr", ["keyword1 keyword2"])', Query::search('attr', 'keyword1 keyword2')); |
| 100 | + } |
| 101 | +
|
| 102 | + public function testIsNull(): void { |
| 103 | + $this->assertSame('isNull("attr")', Query::isNull('attr')); |
| 104 | + } |
| 105 | +
|
| 106 | + public function testIsNotNull(): void { |
| 107 | + $this->assertSame('isNotNull("attr")', Query::isNotNull('attr')); |
| 108 | + } |
| 109 | +
|
| 110 | + public function testBetweenWithIntegers(): void { |
| 111 | + $this->assertSame('between("attr", [1,2])', Query::between('attr', 1, 2)); |
| 112 | + } |
| 113 | +
|
| 114 | + public function testBetweenWithDoubles(): void { |
| 115 | + $this->assertSame('between("attr", [1,2])', Query::between('attr', 1.0, 2.0)); |
| 116 | + } |
| 117 | +
|
| 118 | + public function testBetweenWithStrings(): void { |
| 119 | + $this->assertSame('between("attr", ["a","z"])', Query::between('attr', 'a', 'z')); |
| 120 | + } |
| 121 | +
|
| 122 | + public function testSelect(): void { |
| 123 | + $this->assertSame('select(["attr1","attr2"])', Query::select(['attr1', 'attr2'])); |
| 124 | + } |
| 125 | +
|
| 126 | + public function testOrderAsc(): void { |
| 127 | + $this->assertSame('orderAsc("attr")', Query::orderAsc('attr')); |
| 128 | + } |
| 129 | +
|
| 130 | + public function testOrderDesc(): void { |
| 131 | + $this->assertSame('orderDesc("attr")', Query::orderDesc('attr')); |
| 132 | + } |
| 133 | +
|
| 134 | + public function testCursorBefore(): void { |
| 135 | + $this->assertSame('cursorBefore("attr")', Query::cursorBefore('attr')); |
| 136 | + } |
| 137 | +
|
| 138 | + public function testCursorAfter(): void { |
| 139 | + $this->assertSame('cursorAfter("attr")', Query::cursorAfter('attr')); |
| 140 | + } |
| 141 | +
|
| 142 | + public function testLimit(): void { |
| 143 | + $this->assertSame('limit(1)', Query::limit(1)); |
| 144 | + } |
| 145 | +
|
| 146 | + public function testOffset(): void { |
| 147 | + $this->assertSame('offset(1)', Query::offset(1)); |
| 148 | + } |
| 149 | +} |
0 commit comments