Browse Source

Merge pull request #8180 from fxleblanc/extract

Extract table from class logic to method in TestFixture.
Mark Story 10 years ago
parent
commit
9a1634abf5
1 changed files with 19 additions and 7 deletions
  1. 19 7
      src/TestSuite/Fixture/TestFixture.php

+ 19 - 7
src/TestSuite/Fixture/TestFixture.php

@@ -134,13 +134,7 @@ class TestFixture implements FixtureInterface
     public function init()
     {
         if ($this->table === null) {
-            list(, $class) = namespaceSplit(get_class($this));
-            preg_match('/^(.*)Fixture$/', $class, $matches);
-            $table = $class;
-            if (isset($matches[1])) {
-                $table = $matches[1];
-            }
-            $this->table = Inflector::tableize($table);
+            $this->table = $this->_tableFromClass();
         }
 
         if (empty($this->import) && !empty($this->fields)) {
@@ -157,6 +151,24 @@ class TestFixture implements FixtureInterface
     }
 
     /**
+     * Returns the table name using the fixture class
+     *
+     * @return string
+     */
+    protected function _tableFromClass()
+    {
+        list(, $class) = namespaceSplit(get_class($this));
+        preg_match('/^(.*)Fixture$/', $class, $matches);
+        $table = $class;
+
+        if (isset($matches[1])) {
+            $table = $matches[1];
+        }
+
+        return Inflector::tableize($table);
+    }
+
+    /**
      * Build the fixtures table schema from the fields property.
      *
      * @return void