-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method to Document to set multiple attributes
This makes it easier and quicker to update several attributes on a document from a different document.
- Loading branch information
1 parent
4035d3f
commit d42ddd9
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -175,6 +175,30 @@ public function testSetAttribute(): void | |
$this->assertEquals(['one'], $this->document->getAttribute('list', [])); | ||
} | ||
|
||
public function testSetAttributes(): void | ||
{ | ||
$document = new Document(['$id' => ID::custom(''), '$collection' => 'users']); | ||
|
||
$otherDocument = new Document([ | ||
'$id' => ID::custom('new'), | ||
'$permissions' => [ | ||
Permission::read(Role::any()), | ||
Permission::update(Role::user('new')), | ||
Permission::delete(Role::user('new')), | ||
], | ||
'email' => '[email protected]', | ||
'prefs' => new \stdClass(), | ||
]); | ||
|
||
$document->setAttributes($otherDocument->getArrayCopy()); | ||
|
||
$this->assertEquals($otherDocument->getId(), $document->getId()); | ||
$this->assertEquals('users', $document->getCollection()); | ||
$this->assertEquals($otherDocument->getPermissions(), $document->getPermissions()); | ||
$this->assertEquals($otherDocument->getAttribute('email'), $document->getAttribute('email')); | ||
$this->assertEquals($otherDocument->getAttribute('prefs'), $document->getAttribute('prefs')); | ||
} | ||
|
||
public function testRemoveAttribute(): void | ||
{ | ||
$this->document->removeAttribute('list'); | ||
|