Skip to content

Commit 79b6230

Browse files
committed
Expand test for push/pull
1 parent 7e8a9cc commit 79b6230

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/Jenssegers/Mongodb/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ protected function pullAttributeValues($column, array $values)
449449
}
450450
}
451451

452-
$this->attributes[$column] = $current;
452+
$this->attributes[$column] = array_values($current);
453453

454454
$this->syncOriginalAttribute($column);
455455
}

tests/ModelTest.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,28 @@ public function testIdAttribute()
406406

407407
public function testPushPull()
408408
{
409-
$user = User::create(array('name' => 'John Doe', 'tags' => array()));
409+
$user = User::create(array('name' => 'John Doe'));
410+
411+
$user->push('tags', 'tag1');
412+
$user->push('tags', array('tag1', 'tag2'));
413+
$user->push('tags', 'tag2', true);
410414

411-
$result = User::where('_id', $user->_id)->push('tags', 'tag1');
415+
$this->assertEquals(array('tag1', 'tag1', 'tag2'), $user->tags);
412416
$user = User::where('_id', $user->_id)->first();
417+
$this->assertEquals(array('tag1', 'tag1', 'tag2'), $user->tags);
413418

414-
$this->assertTrue(is_int($result));
415-
$this->assertTrue(is_array($user->tags));
416-
$this->assertEquals(1, count($user->tags));
419+
$user->pull('tags', 'tag1');
420+
421+
$this->assertEquals(array('tag2'), $user->tags);
422+
$user = User::where('_id', $user->_id)->first();
423+
$this->assertEquals(array('tag2'), $user->tags);
424+
425+
$user->push('tags', 'tag3');
426+
$user->pull('tags', array('tag2', 'tag3'));
427+
428+
$this->assertEquals(array(), $user->tags);
429+
$user = User::where('_id', $user->_id)->first();
430+
$this->assertEquals(array(), $user->tags);
417431
}
418432

419433
public function testRaw()

0 commit comments

Comments
 (0)