Skip to content

Commit dff4626

Browse files
author
Karl Pierce
committed
Correct guarded unit tests to be more relevant
1 parent 43b0789 commit dff4626

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Diff for: tests/ModelTest.php

+18-2
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,24 @@ public function testTruncateModel()
726726

727727
public function testGuardedModel()
728728
{
729-
Guarded::create(['var' => 'val']);
729+
$model = new Guarded();
730730

731-
$this->assertEquals(1, Guarded::count());
731+
// foobar is properly guarded
732+
$model->fill(['foobar' => 'ignored', 'name' => 'John Doe']);
733+
$this->assertFalse(isset($model->foobar));
734+
$this->assertSame('John Doe', $model->name);
735+
736+
// foobar is guarded to any level
737+
$model->fill(['foobar->level2' => 'v2']);
738+
$this->assertNull($model->getAttribute('foobar->level2'));
739+
740+
// multi level statement also guarded
741+
$model->fill(['level1->level2' => 'v1']);
742+
$this->assertNull($model->getAttribute('level1->level2'));
743+
744+
// level1 is still writable
745+
$dataValues = ['array', 'of', 'values'];
746+
$model->fill(['level1' => $dataValues]);
747+
$this->assertEquals($dataValues, $model->getAttribute('level1'));
732748
}
733749
}

Diff for: tests/models/Guarded.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ class Guarded extends Eloquent
77
{
88
protected $connection = 'mongodb';
99
protected $collection = 'guarded';
10-
protected $guarded = ['foobar'];
10+
protected $guarded = ['foobar', 'level1->level2'];
1111
}

0 commit comments

Comments
 (0)