Browse Source

Split ModelAwareTrait::modelType into getter/setter

Michael Hoffmann 9 years ago
parent
commit
bb3a4652a5

+ 26 - 1
src/Datasource/ModelAwareTrait.php

@@ -90,7 +90,7 @@ trait ModelAwareTrait
             $modelClass = $this->modelClass;
         }
         if ($modelType === null) {
-            $modelType = $this->modelType();
+            $modelType = $this->getModelType();
 
             if ($modelType === null) {
                 throw new UnexpectedValueException('No model type has been defined');
@@ -130,8 +130,33 @@ trait ModelAwareTrait
     }
 
     /**
+     * Get the model type to be used by this class
+     *
+     * @return string
+     */
+    public function getModelType()
+    {
+        return $this->_modelType;
+    }
+
+    /**
+     * Set the model type to be used by this class
+     *
+     * @param string $modelType The model type
+     *
+     * @return $this
+     */
+    public function setModelType($modelType)
+    {
+        $this->_modelType = $modelType;
+
+        return $this;
+    }
+
+    /**
      * Set or get the model type to be used by this class
      *
+     * @deprecated 3.5.0 Use getModelType()/setModelType() instead.
      * @param string|null $modelType The model type or null to retrieve the current
      *
      * @return string|$this

+ 20 - 0
tests/TestCase/Datasource/ModelAwareTraitTest.php

@@ -142,6 +142,26 @@ class ModelAwareTraitTest extends TestCase
     }
 
     /**
+     * test getModelType() and setModelType()
+     *
+     * @return void
+     */
+    public function testGetSetModelType()
+    {
+        $stub = new Stub();
+        $stub->setProps('Articles');
+
+        FactoryLocator::add('Test', function ($name) {
+            $mock = new \StdClass();
+            $mock->name = $name;
+
+            return $mock;
+        });
+        $stub->setModelType('Test');
+        $this->assertSame('Test', $stub->getModelType());
+    }
+
+    /**
      * test MissingModelException being thrown
      *
      * @return void