Skip to content

Commit cfc0548

Browse files
committed
adding test for accessors.
1 parent 47b8867 commit cfc0548

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tests/Support/SupportCollectionTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,39 @@ public function testMakeMethod()
234234
$this->assertEquals(array('foo'), $collection->all());
235235
}
236236

237+
238+
public function testGetListValueWithAccessors()
239+
{
240+
$model = new TestAccessorEloquentTestStub(array('some' => 'foo'));
241+
$modelTwo = new TestAccessorEloquentTestStub(array('some' => 'bar'));
242+
$data = new Collection(array($model, $modelTwo));
243+
244+
$this->assertEquals(array('foo', 'bar'), $data->lists('some'));
245+
}
246+
237247
}
248+
249+
class TestAccessorEloquentTestStub
250+
{
251+
protected $attributes = array();
252+
253+
public function __construct($attributes)
254+
{
255+
$this->attributes = $attributes;
256+
}
257+
258+
public function __get($attribute)
259+
{
260+
$accessor = 'get' .lcfirst($attribute). 'Attribute';
261+
if (method_exists($this, $accessor)) {
262+
return $this->$accessor();
263+
}
264+
265+
return $this->$attribute;
266+
}
267+
268+
public function getSomeAttribute()
269+
{
270+
return $this->attributes['some'];
271+
}
272+
}

0 commit comments

Comments
 (0)