public function testToArray()
 {
     $model = new EloquentModelStub();
     $model->name = 'foo';
     $model->age = null;
     $model->password = '******';
     $model->setHidden(array('password'));
     $model->setRelation('names', new Illuminate\Database\Eloquent\Collection(array(new EloquentModelStub(array('bar' => 'baz')), new EloquentModelStub(array('bam' => 'boom')))));
     $model->setRelation('partner', new EloquentModelStub(array('name' => 'abby')));
     $array = $model->toArray();
     $this->assertTrue(is_array($array));
     $this->assertEquals('foo', $array['name']);
     $this->assertEquals('baz', $array['names'][0]['bar']);
     $this->assertEquals('boom', $array['names'][1]['bam']);
     $this->assertEquals('abby', $array['partner']['name']);
     $this->assertFalse(isset($array['password']));
 }
示例#2
0
 public function testMakeHidden()
 {
     $model = new EloquentModelStub(['name' => 'foo', 'age' => 'bar', 'address' => 'foobar', 'id' => 'baz']);
     $array = $model->toArray();
     $this->assertArrayHasKey('name', $array);
     $this->assertArrayHasKey('age', $array);
     $this->assertArrayHasKey('address', $array);
     $this->assertArrayHasKey('id', $array);
     $array = $model->makeHidden('address')->toArray();
     $this->assertArrayNotHasKey('address', $array);
     $this->assertArrayHasKey('name', $array);
     $this->assertArrayHasKey('age', $array);
     $this->assertArrayHasKey('id', $array);
     $array = $model->makeHidden(['name', 'age'])->toArray();
     $this->assertArrayNotHasKey('name', $array);
     $this->assertArrayNotHasKey('age', $array);
     $this->assertArrayNotHasKey('address', $array);
     $this->assertArrayHasKey('id', $array);
 }