Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Apr 27, 2014
1 parent a0afbbe commit 6019d22
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
42 changes: 32 additions & 10 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
require_once('vendor/autoload.php');
require_once('tests/stubs/ModelStub.php');
require_once 'tests/stubs/ModelStub.php';

use Jenssegers\Model\Model;

Expand All @@ -26,16 +25,30 @@ public function testNewInstanceWithAttributes()
{
$model = new ModelStub;
$instance = $model->newInstance(array('name' => 'john'));

$this->assertInstanceOf('ModelStub', $instance);
$this->assertEquals('john', $instance->name);
}

public function testHidden()
{
$model = new ModelStub;
$model->secret = 'secret';
$model->password = 'secret';

$attributes = $model->attributesToArray();
$this->assertFalse(isset($attributes['password']));
$this->assertEquals(array('password'), $model->getHidden());
}

public function testVisible()
{
$model = new ModelStub;
$model->setVisible(array('name'));
$model->name = 'John Doe';
$model->city = 'Paris';

$attributes = $model->attributesToArray();
$this->assertFalse(isset($attributes['secret']));
$this->assertEquals(array('name' => 'John Doe'), $attributes);
}

public function testToArray()
Expand Down Expand Up @@ -67,7 +80,7 @@ public function testToJson()
}

public function testMutator()
{
{
$model = new ModelStub;
$model->list_items = array('name' => 'john');
$this->assertEquals(array('name' => 'john'), $model->list_items);
Expand All @@ -89,17 +102,16 @@ public function testToArrayUsesMutators()
$model->list_items = array(1, 2, 3);
$array = $model->toArray();

$this->assertEquals(array(1, 2, 3), $array['list_items']);
$this->assertEquals(array(1, 2, 3), $array['list_items']);
}

public function testReplicate()
{
$model = new ModelStub;
$model->name = 'john';
$model->foo = 'bar';
$model->name = 'John Doe';
$model->city = 'Paris';

$clone = $model->replicate();

$this->assertEquals($model, $clone);
$this->assertEquals($model->name, $clone->name);
}
Expand All @@ -117,4 +129,14 @@ public function testAppends()
$this->assertEquals('test', $array['test']);
}

}
public function testArrayAccess()
{
$model = new ModelStub;
$model->name = 'John Doen';
$model['city'] = 'Paris';

$this->assertEquals($model->name, $model['name']);
$this->assertEquals($model->city, $model['city']);
}

}
4 changes: 2 additions & 2 deletions tests/stubs/ModelStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class ModelStub extends Model {

protected $hidden = array('secret');
protected $hidden = array('password');

public function getListItemsAttribute($value)
{
Expand Down Expand Up @@ -37,4 +37,4 @@ public function getTestAttribute($value)
return 'test';
}

}
}

0 comments on commit 6019d22

Please sign in to comment.