Adding App::uses() call to model baking.

Models should always include their parent classes to be safe.
Bake should reflect the best practice.
Refs #1971
This commit is contained in:
mark_story 2011-09-09 20:32:01 -04:00
parent 1743eaa776
commit 7c08c966b0
3 changed files with 9 additions and 3 deletions

View file

@ -743,7 +743,10 @@ class ModelTask extends BakeTask {
$data = array_merge($defaults, $data);
$this->Template->set($data);
$this->Template->set('plugin', $this->plugin);
$this->Template->set(array(
'plugin' => $this->plugin,
'pluginPath' => empty($this->plugin) ? '' : $this->plugin . '.'
));
$out = $this->Template->generate('classes', 'model');
$path = $this->getPath();

View file

@ -19,7 +19,9 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
echo "<?php\n"; ?>
echo "<?php\n";
echo "App::uses('{$plugin}AppModel', '{$pluginPath}Model');\n";
?>
/**
* <?php echo $name ?> Model
*

View file

@ -754,7 +754,8 @@ STRINGEND;
$this->Task->expects($this->once())->method('createFile')
->with($path, new PHPUnit_Framework_Constraint_PCREMatch('/BakeArticle extends ControllerTestAppModel/'));
$this->Task->bake('BakeArticle', array(), array());
$result = $this->Task->bake('BakeArticle', array(), array());
$this->assertContains("App::uses('ControllerTestAppModel', 'ControllerTest.Model');", $result);
$this->assertEqual(count(ClassRegistry::keys()), 0);
$this->assertEqual(count(ClassRegistry::mapKeys()), 0);