|
5 | 5 | use Utopia\Database\Database; |
6 | 6 | use Utopia\Database\Document; |
7 | 7 | use Utopia\Database\Exception; |
| 8 | +use Utopia\Database\Exception\Query as QueryException; |
8 | 9 | use Utopia\Database\Exception\Structure as StructureException; |
9 | 10 | use Utopia\Database\Helpers\ID; |
10 | 11 | use Utopia\Database\Helpers\Permission; |
@@ -840,6 +841,53 @@ public function testSpatialIndex(): void |
840 | 841 | } finally { |
841 | 842 | $database->deleteCollection($collNullIndex); |
842 | 843 | } |
| 844 | + |
| 845 | + $collUpdateNull = 'spatial_idx_req'; |
| 846 | + try { |
| 847 | + $database->createCollection($collUpdateNull); |
| 848 | + |
| 849 | + $database->createAttribute($collUpdateNull, 'loc', Database::VAR_POINT, 0, false); |
| 850 | + if (!$nullSupported) { |
| 851 | + try { |
| 852 | + $database->createIndex($collUpdateNull, 'idx_loc_required', Database::INDEX_SPATIAL, ['loc']); |
| 853 | + $this->fail('Expected exception when creating spatial index on NULL-able attribute'); |
| 854 | + } catch (\Throwable $e) { |
| 855 | + $this->assertInstanceOf(Exception::class, $e); |
| 856 | + } |
| 857 | + } else { |
| 858 | + $this->assertTrue($database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_SPATIAL, ['loc'])); |
| 859 | + } |
| 860 | + |
| 861 | + $database->updateAttribute($collUpdateNull, 'loc', required: true); |
| 862 | + |
| 863 | + $this->assertTrue($database->createIndex($collUpdateNull, 'idx_loc_req', Database::INDEX_SPATIAL, ['loc'])); |
| 864 | + } finally { |
| 865 | + $database->deleteCollection($collUpdateNull); |
| 866 | + } |
| 867 | + |
| 868 | + |
| 869 | + $collUpdateNull = 'spatial_idx_index_null_required_true'; |
| 870 | + try { |
| 871 | + $database->createCollection($collUpdateNull); |
| 872 | + |
| 873 | + $database->createAttribute($collUpdateNull, 'loc', Database::VAR_POINT, 0, false); |
| 874 | + if (!$nullSupported) { |
| 875 | + try { |
| 876 | + $database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_SPATIAL, ['loc']); |
| 877 | + $this->fail('Expected exception when creating spatial index on NULL-able attribute'); |
| 878 | + } catch (\Throwable $e) { |
| 879 | + $this->assertInstanceOf(Exception::class, $e); |
| 880 | + } |
| 881 | + } else { |
| 882 | + $this->assertTrue($database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_SPATIAL, ['loc'])); |
| 883 | + } |
| 884 | + |
| 885 | + $database->updateAttribute($collUpdateNull, 'loc', required: true); |
| 886 | + |
| 887 | + $this->assertTrue($database->createIndex($collUpdateNull, 'new index', Database::INDEX_SPATIAL, ['loc'])); |
| 888 | + } finally { |
| 889 | + $database->deleteCollection($collUpdateNull); |
| 890 | + } |
843 | 891 | } |
844 | 892 |
|
845 | 893 | public function testComplexGeometricShapes(): void |
@@ -2335,11 +2383,10 @@ public function testSpatialDistanceInMeterError(): void |
2335 | 2383 | ]); |
2336 | 2384 | $this->fail('Expected Exception not thrown for ' . implode(' vs ', $case['expected'])); |
2337 | 2385 | } catch (\Exception $e) { |
2338 | | - $this->assertInstanceOf(\Exception::class, $e); |
| 2386 | + $this->assertInstanceOf(QueryException::class, $e); |
2339 | 2387 |
|
2340 | 2388 | // Validate exception message contains correct type names |
2341 | 2389 | $msg = strtolower($e->getMessage()); |
2342 | | - var_dump($msg); |
2343 | 2390 | $this->assertStringContainsString($case['expected'][0], $msg, 'Attr type missing in exception'); |
2344 | 2391 | $this->assertStringContainsString($case['expected'][1], $msg, 'Geom type missing in exception'); |
2345 | 2392 | } |
|
0 commit comments