Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 58
added supportForAttributes in sql adapters#751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6185,4 +6185,182 @@ public function testCreateUpdateDocumentsMismatch(): void | ||
| $database->deleteCollection($colName); | ||
| } | ||
| public function testBypassStructureWithSupportForAttributes(): void | ||
| { | ||
| /** @var Database $database */ | ||
| $database = static::getDatabase(); | ||
| // for schemaless the validation will be automatically skipped | ||
| if (!$database->getAdapter()->getSupportForAttributes()) { | ||
| $this->expectNotToPerformAssertions(); | ||
| return; | ||
| } | ||
| $collectionId = 'successive_update_single'; | ||
| $database->createCollection($collectionId); | ||
| $database->createAttribute($collectionId, 'attrA', Database::VAR_STRING, 50, true); | ||
| $database->createAttribute($collectionId, 'attrB', Database::VAR_STRING, 50, true); | ||
| // bypass required | ||
| $database->disableValidation(); | ||
| $permissions = [Permission::read(Role::any()), Permission::write(Role::any()), Permission::update(Role::any()), Permission::delete(Role::any())]; | ||
| $docs = $database->createDocuments($collectionId, [ | ||
| new Document(['attrA' => null,'attrB' => 'B','$permissions' => $permissions]) | ||
| ]); | ||
| $docs = $database->find($collectionId); | ||
| foreach ($docs as $doc) { | ||
| $this->assertArrayHasKey('attrA', $doc->getAttributes()); | ||
| $this->assertNull($doc->getAttribute('attrA')); | ||
| $this->assertEquals('B', $doc->getAttribute('attrB')); | ||
| } | ||
| // reset | ||
| $database->enableValidation(); | ||
| try { | ||
| $database->createDocuments($collectionId, [ | ||
| new Document(['attrA' => null,'attrB' => 'B','$permissions' => $permissions]) | ||
| ]); | ||
| $this->fail('Failed to throw exception'); | ||
| } catch (Exception $e) { | ||
| $this->assertInstanceOf(StructureException::class, $e); | ||
| } | ||
| $database->deleteCollection($collectionId); | ||
| } | ||
ArnabChatterjee20k marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| public function testValidationGuardsWithNullRequired(): void | ||
| { | ||
| /** @var Database $database */ | ||
| $database = static::getDatabase(); | ||
| if (!$database->getAdapter()->getSupportForAttributes()) { | ||
| $this->expectNotToPerformAssertions(); | ||
| return; | ||
| } | ||
| // Base collection and attributes | ||
| $collection = 'validation_guard_all'; | ||
| $database->createCollection($collection, permissions: [ | ||
| Permission::read(Role::any()), | ||
| Permission::create(Role::any()), | ||
| Permission::update(Role::any()), | ||
| Permission::delete(Role::any()), | ||
| ], documentSecurity: true); | ||
| $database->createAttribute($collection, 'name', Database::VAR_STRING, 32, true); | ||
| $database->createAttribute($collection, 'age', Database::VAR_INTEGER, 0, true); | ||
| $database->createAttribute($collection, 'value', Database::VAR_INTEGER, 0, false); | ||
| // 1) createDocument with null required should fail when validation enabled, pass when disabled | ||
| try { | ||
| $database->createDocument($collection, new Document([ | ||
| '$permissions' => [Permission::read(Role::any()), Permission::create(Role::any())], | ||
| 'name' => null, | ||
| 'age' => null, | ||
| ])); | ||
| $this->fail('Failed to throw exception'); | ||
| } catch (Throwable $e) { | ||
| $this->assertInstanceOf(StructureException::class, $e); | ||
| } | ||
| $database->disableValidation(); | ||
| $doc = $database->createDocument($collection, new Document([ | ||
| '$id' => 'created-null', | ||
| '$permissions' => [Permission::read(Role::any()), Permission::create(Role::any()), Permission::update(Role::any())], | ||
| 'name' => null, | ||
| 'age' => null, | ||
| ])); | ||
| $this->assertEquals('created-null', $doc->getId()); | ||
| $database->enableValidation(); | ||
| // Seed a valid document for updates | ||
| $valid = $database->createDocument($collection, new Document([ | ||
| '$id' => 'valid', | ||
| '$permissions' => [Permission::read(Role::any()), Permission::update(Role::any())], | ||
| 'name' => 'ok', | ||
| 'age' => 10, | ||
| ])); | ||
| $this->assertEquals('valid', $valid->getId()); | ||
| // 2) updateDocument set required to null should fail when validation enabled, pass when disabled | ||
| try { | ||
| $database->updateDocument($collection, 'valid', new Document([ | ||
| 'age' => null, | ||
| ])); | ||
| $this->fail('Failed to throw exception'); | ||
| } catch (Throwable $e) { | ||
| $this->assertInstanceOf(StructureException::class, $e); | ||
| } | ||
| $database->disableValidation(); | ||
| $updated = $database->updateDocument($collection, 'valid', new Document([ | ||
| 'age' => null, | ||
| ])); | ||
| $this->assertNull($updated->getAttribute('age')); | ||
| $database->enableValidation(); | ||
| // Seed a few valid docs for bulk update | ||
| for ($i = 0; $i < 2; $i++) { | ||
| $database->createDocument($collection, new Document([ | ||
| '$id' => 'b' . $i, | ||
| '$permissions' => [Permission::read(Role::any()), Permission::update(Role::any())], | ||
| 'name' => 'ok', | ||
| 'age' => 1, | ||
| ])); | ||
| } | ||
| // 3) updateDocuments setting required to null should fail when validation enabled, pass when disabled | ||
| if ($database->getAdapter()->getSupportForBatchOperations()) { | ||
| try { | ||
| $database->updateDocuments($collection, new Document([ | ||
| 'name' => null, | ||
| ])); | ||
| $this->fail('Failed to throw exception'); | ||
| } catch (Throwable $e) { | ||
| $this->assertInstanceOf(StructureException::class, $e); | ||
| } | ||
| $database->disableValidation(); | ||
| $count = $database->updateDocuments($collection, new Document([ | ||
| 'name' => null, | ||
| ])); | ||
| $this->assertGreaterThanOrEqual(3, $count); // at least the seeded docs are updated | ||
| $database->enableValidation(); | ||
| } | ||
| // 4) upsertDocumentsWithIncrease with null required should fail when validation enabled, pass when disabled | ||
| if ($database->getAdapter()->getSupportForUpserts()) { | ||
| try { | ||
| $database->upsertDocumentsWithIncrease( | ||
| collection: $collection, | ||
| attribute: 'value', | ||
| documents: [new Document([ | ||
| '$id' => 'u1', | ||
| 'name' => null, // required null | ||
| 'value' => 1, | ||
| ])] | ||
| ); | ||
| $this->fail('Failed to throw exception'); | ||
| } catch (Throwable $e) { | ||
| $this->assertInstanceOf(StructureException::class, $e); | ||
| } | ||
| $database->disableValidation(); | ||
| $ucount = $database->upsertDocumentsWithIncrease( | ||
| collection: $collection, | ||
| attribute: 'value', | ||
| documents: [new Document([ | ||
| '$id' => 'u1', | ||
| 'name' => null, | ||
| 'value' => 1, | ||
| ])] | ||
| ); | ||
| $this->assertEquals(1, $ucount); | ||
| $database->enableValidation(); | ||
| } | ||
| // Cleanup | ||
| $database->deleteCollection($collection); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.