Skip to content

Commit

Permalink
Merge pull request #172 from GrahamCampbell/facade
Browse files Browse the repository at this point in the history
A Few Fixes
  • Loading branch information
scottrobertson committed Jul 31, 2014
2 parents 84d2469 + b26a1d9 commit 13decb1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/Facade/FactoryMuffin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* @method static void setDeleteMethod(string $method) Set the method we use when deleting objects.
* @method static object[] seed(string $model, int $times = 1, array $attr = array()) Returns multiple versions of an object.
* @method static object create(string $model, array $attr = array()) Creates and saves in db an instance of the model.
* @method static mixed save(object $object) Save our object to the db, and keep track of it.
* @method static object[] saved() Return an array of saved objects.
* @method static bool isSaved(object $object) Is the object saved?
* @method static void deleteSaved() Call the delete method on any saved objects.
* @method static object instance(string $model, array $attr = array()) Return an instance of the model.
* @method static array attributesFor(string $model, array $attr = array(), bool $save = false) Returns the mock attributes for the model.
* @method static array attributesFor(object $object, array $attr = array()) Returns the mock attributes for the model.
* @method static void define(string $model, array $definition = array()) Define a new model factory.
* @method static string|object generateAttr(string $kind, string $model = null, bool $save = false) Generate the attributes.
* @method static string|object generateAttr(string $kind, object $object = null) Generate the attributes.
* @method static void loadFactories(string|string[] $paths) Load the specified factories.
*
* @package League\FactoryMuffin\Facades
Expand Down
11 changes: 3 additions & 8 deletions src/FactoryMuffin.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,8 @@ private function make($model, array $attr, $save)
*
* @return mixed
*/
public function save($object)
private function save($object)
{
if (!$this->isSaved($object)) {
$this->saved[] = $object;
}

if (!method_exists($object, $method = $this->saveMethod)) {
throw new SaveMethodNotFoundException($object, $method);
}
Expand All @@ -188,7 +184,7 @@ public function saved()
/**
* Is the object saved?
*
* @param object $object
* @param object $object The model instance.
*
* @return bool
*/
Expand Down Expand Up @@ -231,8 +227,7 @@ public function deleteSaved()
/**
* Return an instance of the model.
*
* This does not save it in the database. Use the create method to create
* and save to the db, or pass the object from this method into the save method.
* This does not save it in the database. Use create for that.
*
* @param string $model Model class name.
* @param array $attr Model attributes.
Expand Down
9 changes: 3 additions & 6 deletions tests/SaveAndDeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@ class SaveAndDeleteTest extends AbstractTestCase
public function testShouldCreateAndDelete()
{
$obj = FactoryMuffin::create('ModelThatWillSaveStub');
$this->assertTrue(FactoryMuffin::isSaved($obj));
$this->assertTrue(is_numeric($obj->id));
$this->assertInternalType('array', FactoryMuffin::saved());
$this->assertCount(1, FactoryMuffin::saved());

FactoryMuffin::deleteSaved();
}

public function testShouldByAbleToSaveExisting()
public function testShouldNotSave()
{
$obj = FactoryMuffin::instance('ModelThatWillSaveStub');
$this->assertCount(0, FactoryMuffin::saved());
$this->assertFalse(FactoryMuffin::isSaved($obj));

FactoryMuffin::save($obj);
$this->assertTrue(FactoryMuffin::isSaved($obj));

FactoryMuffin::deleteSaved();
}

/**
Expand Down

0 comments on commit 13decb1

Please sign in to comment.