Browse Source

Merge pull request #5179 from AD7six/3.0-bake-plugin-bootstrap.php

Don't hardcode paths when baking a plugin
José Lorenzo Rodríguez 11 years ago
parent
commit
f8a9c0dd36
1 changed files with 37 additions and 3 deletions
  1. 37 3
      src/Template/Bake/tests/bootstrap.ctp

+ 37 - 3
src/Template/Bake/tests/bootstrap.ctp

@@ -1,7 +1,41 @@
+<%
+/**
+ * Tests bootstrap file
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link          http://cakephp.org CakePHP(tm) Project
+ * @since         3.0.0
+ * @license       http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+%>
 <?php
 /**
  * Test suite bootstrap for <%= $plugin %>.
+ *
+ * This function is used to find the location of CakePHP whether CakePHP
+ * has been installed as a dependency of the plugin, or the plugin is itself
+ * installed as a dependency of an application.
  */
-// Customize this to be a relative path for embedded plugins.
-// For standalone plugins, this should point at a CakePHP installation.
-require '<%= $root %>/config/bootstrap.php';
+$findRoot = function($root) {
+	do {
+		$lastRoot = $root;
+		$root = dirname($root);
+		if (is_dir($root . '/vendor/cakephp/cakephp')) {
+			return $root;
+		}
+	} while($root !== $lastRoot);
+
+	throw new Exception("Cannot find the root of the application, unable to run tests");
+};
+$root = $findRoot(__FILE__);
+unset($findRoot);
+
+chdir($root);
+require $root . '/config/bootstrap.php';