From c1f509af572a52d946d15f4ace0dfc7ba1454401 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 31 Jul 2014 12:56:29 +0100 Subject: [PATCH 1/3] Updated the facade docs again --- src/Facade/FactoryMuffin.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Facade/FactoryMuffin.php b/src/Facade/FactoryMuffin.php index b889b9c..46c69e5 100644 --- a/src/Facade/FactoryMuffin.php +++ b/src/Facade/FactoryMuffin.php @@ -16,11 +16,12 @@ * @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 From 2fdcf72af595fe050c993ec88c8945f16290db89 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 31 Jul 2014 12:56:40 +0100 Subject: [PATCH 2/3] Added a missing param description --- src/FactoryMuffin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FactoryMuffin.php b/src/FactoryMuffin.php index 0819acf..f30f179 100644 --- a/src/FactoryMuffin.php +++ b/src/FactoryMuffin.php @@ -188,7 +188,7 @@ public function saved() /** * Is the object saved? * - * @param object $object + * @param object $object The model instance. * * @return bool */ From b26a1d96dd8fb319aea82a1cb4a43cd9c314decc Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 31 Jul 2014 14:02:16 +0100 Subject: [PATCH 3/3] Make the save function private --- src/Facade/FactoryMuffin.php | 1 - src/FactoryMuffin.php | 9 ++------- tests/SaveAndDeleteTest.php | 9 +++------ 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Facade/FactoryMuffin.php b/src/Facade/FactoryMuffin.php index 46c69e5..7ab610f 100644 --- a/src/Facade/FactoryMuffin.php +++ b/src/Facade/FactoryMuffin.php @@ -14,7 +14,6 @@ * @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. diff --git a/src/FactoryMuffin.php b/src/FactoryMuffin.php index f30f179..2f8982f 100644 --- a/src/FactoryMuffin.php +++ b/src/FactoryMuffin.php @@ -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); } @@ -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. diff --git a/tests/SaveAndDeleteTest.php b/tests/SaveAndDeleteTest.php index 75d8fae..35017f5 100644 --- a/tests/SaveAndDeleteTest.php +++ b/tests/SaveAndDeleteTest.php @@ -14,6 +14,7 @@ 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()); @@ -21,15 +22,11 @@ public function testShouldCreateAndDelete() 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(); } /**