Browse Source

Fix `cake bake fixture` failing.

Bake failed as the connection property was not properly copied over in
sub-tasks. This fixes that issue by setting the property from params on
initialize().

Refs #3638
mark_story 11 years ago
parent
commit
7640ffff27

+ 13 - 0
src/Console/Command/Task/BakeTask.php

@@ -60,6 +60,19 @@ class BakeTask extends Shell {
 	}
 
 /**
+ * Initialize hook.
+ *
+ * Populates the connection property, which is useful for tasks of tasks.
+ *
+ * @return void
+ */
+	public function initialize() {
+		if (empty($this->connection) && !empty($this->params['connection'])) {
+			$this->connection = $this->params['connection'];
+		}
+	}
+
+/**
  * Gets the path for output. Checks the plugin property
  * and returns the correct path.
  *

+ 13 - 0
tests/TestCase/Console/Command/Task/FixtureTaskTest.php

@@ -67,6 +67,19 @@ class FixtureTaskTest extends TestCase {
 	}
 
 /**
+ * Test that initialize() copies the connection property over.
+ *
+ * @return void
+ */
+	public function testInitializeCopyConnection() {
+		$this->assertEquals('', $this->Task->connection);
+		$this->Task->params = ['connection' => 'test'];
+
+		$this->Task->initialize();
+		$this->assertEquals('test', $this->Task->connection);
+	}
+
+/**
  * test that initialize sets the path
  *
  * @return void