Skip to content

Commit

Permalink
Drop support for using plain objects as attributes due to the heavy c…
Browse files Browse the repository at this point in the history
…ost and low benefit
  • Loading branch information
Ravan Scafi committed Feb 1, 2019
1 parent 7ac32b1 commit b8febac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
7 changes: 1 addition & 6 deletions src/Model/HasAttributesTrait.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Mongolid\Model;

use Exception;
use Illuminate\Support\Str;
use Mongolid\Container\Container;
use stdClass;
Expand Down Expand Up @@ -189,11 +188,7 @@ public function setDocumentAttribute(string $key, $value)
*/
public function syncOriginalDocumentAttributes()
{
try {
$this->originalAttributes = unserialize(serialize($this->getDocumentAttributes()));
} catch (Exception $e) {
$this->originalAttributes = $this->getDocumentAttributes();
}
$this->originalAttributes = $this->getDocumentAttributes();
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/Integration/PersistedDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public function testSaveUpdatingData()
$user->preferences = [];
$user->friends = ['Mary'];
$user->address = '123 Blue Street';
$user->skills->HTML = ['percentage' => '89%', 'version' => 'HTML5'];
$user->skills->PHP['version'] = '7.1';
$user->skills['HTML'] = ['percentage' => '89%', 'version' => 'HTML5'];
$user->skills['PHP']['version'] = '7.1';

$expected = [
'_id' => (string) $user->_id,
Expand Down Expand Up @@ -104,8 +104,8 @@ public function testUpdateData()
$user->preferences = [];
$user->friends = ['Mary'];
$user->address = '123 Blue Street';
$user->skills->HTML = ['percentage' => '89%', 'version' => 'HTML5'];
$user->skills->PHP['version'] = '7.1';
$user->skills['HTML'] = ['percentage' => '89%', 'version' => 'HTML5'];
$user->skills['PHP']['version'] = '7.1';

$expected = [
'_id' => (string) $user->_id,
Expand Down Expand Up @@ -146,7 +146,7 @@ private function getUser(bool $save = false): ReferencedUser
];
$user->friends = [];
$user->address = null;
$user->skills = (object) [
$user->skills = [
'PHP' => ['percentage' => '100%', 'version' => '7.0'],
'JavaScript' => ['percentage' => '80%', 'version' => 'ES6'],
'CSS' => ['percentage' => '45%', 'version' => 'CSS3'],
Expand Down

0 comments on commit b8febac

Please sign in to comment.