~tsep-dev/tsep/0.9-beta

« back to all changes in this revision

Viewing changes to branches/symfony/cake/tests/cases/console/libs/bake.test.php

  • Committer: geoffreyfishing
  • Date: 2011-01-11 23:46:12 UTC
  • Revision ID: svn-v4:ae0de26e-ed09-4cbe-9a20-e40b4c60ac6c::125
Created a symfony branch for future migration to symfony

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * BakeShell Test Case
 
4
 *
 
5
 *
 
6
 * PHP versions 4 and 5
 
7
 *
 
8
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 
9
 * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
 
10
 *
 
11
 * Licensed under The MIT License
 
12
 * Redistributions of files must retain the above copyright notice.
 
13
 *
 
14
 * @copyright     Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
 
15
 * @link          http://cakephp.org CakePHP(tm) Project
 
16
 * @package       cake
 
17
 * @subpackage    cake.tests.cases.console.libs.tasks
 
18
 * @since         CakePHP(tm) v 1.3
 
19
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 
20
 */
 
21
App::import('Shell', 'Shell', false);
 
22
 
 
23
if (!defined('DISABLE_AUTO_DISPATCH')) {
 
24
        define('DISABLE_AUTO_DISPATCH', true);
 
25
}
 
26
 
 
27
if (!class_exists('ShellDispatcher')) {
 
28
        ob_start();
 
29
        $argv = false;
 
30
        require CAKE . 'console' .  DS . 'cake.php';
 
31
        ob_end_clean();
 
32
}
 
33
 
 
34
require_once CAKE . 'console' .  DS . 'libs' . DS . 'bake.php';
 
35
require_once CAKE . 'console' .  DS . 'libs' . DS . 'tasks' . DS . 'model.php';
 
36
require_once CAKE . 'console' .  DS . 'libs' . DS . 'tasks' . DS . 'controller.php';
 
37
require_once CAKE . 'console' .  DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
 
38
 
 
39
Mock::generatePartial(
 
40
        'ShellDispatcher', 'BakeShellMockShellDispatcher',
 
41
        array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
 
42
);
 
43
Mock::generatePartial(
 
44
        'BakeShell', 'MockBakeShell',
 
45
        array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
 
46
);
 
47
 
 
48
Mock::generate('DbConfigTask', 'BakeShellMockDbConfigTask');
 
49
Mock::generate('ModelTask', 'BakeShellMockModelTask');
 
50
Mock::generate('ControllerTask', 'BakeShellMockControllerTask');
 
51
 
 
52
if (!class_exists('UsersController')) {
 
53
        class UsersController extends Controller {
 
54
                var $name = 'Users';
 
55
        }
 
56
}
 
57
 
 
58
class BakeShellTestCase extends CakeTestCase {
 
59
 
 
60
/**
 
61
 * fixtures
 
62
 *
 
63
 * @var array
 
64
 * @access public
 
65
 */
 
66
        var $fixtures = array('core.user');
 
67
 
 
68
/**
 
69
 * start test
 
70
 *
 
71
 * @return void
 
72
 * @access public
 
73
 */
 
74
        function startTest() {
 
75
                $this->Dispatch =& new BakeShellMockShellDispatcher();
 
76
                $this->Shell =& new MockBakeShell();
 
77
                $this->Shell->Dispatch =& $this->Dispatch;
 
78
                $this->Shell->Dispatch->shellPaths = App::path('shells');
 
79
        }
 
80
 
 
81
/**
 
82
 * endTest method
 
83
 *
 
84
 * @return void
 
85
 * @access public
 
86
 */
 
87
        function endTest() {
 
88
                unset($this->Dispatch, $this->Shell);
 
89
        }
 
90
 
 
91
/**
 
92
 * test bake all
 
93
 *
 
94
 * @return void
 
95
 * @access public
 
96
 */
 
97
        function testAllWithModelName() {
 
98
                App::import('Model', 'User');
 
99
                $userExists = class_exists('User');
 
100
                if ($this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`. %s')) {
 
101
                        return;
 
102
                }
 
103
                $this->Shell->Model =& new BakeShellMockModelTask();
 
104
                $this->Shell->Controller =& new BakeShellMockControllerTask();
 
105
                $this->Shell->View =& new BakeShellMockModelTask();
 
106
                $this->Shell->DbConfig =& new BakeShellMockDbConfigTask();
 
107
 
 
108
                $this->Shell->DbConfig->expectOnce('getConfig');
 
109
                $this->Shell->DbConfig->setReturnValue('getConfig', 'test_suite');
 
110
 
 
111
                $this->Shell->Model->setReturnValue('bake', true);
 
112
                $this->Shell->Model->expectNever('getName');
 
113
                $this->Shell->Model->expectOnce('bake');
 
114
 
 
115
                $this->Shell->Controller->expectOnce('bake');
 
116
                $this->Shell->Controller->setReturnValue('bake', true);
 
117
 
 
118
                $this->Shell->View->expectOnce('execute');
 
119
 
 
120
                $this->Shell->expectAt(0, 'out', array('Bake All'));
 
121
                $this->Shell->expectAt(1, 'out', array('User Model was baked.'));
 
122
                $this->Shell->expectAt(2, 'out', array('User Controller was baked.'));
 
123
                $this->Shell->expectAt(3, 'out', array('User Views were baked.'));
 
124
                $this->Shell->expectAt(4, 'out', array('Bake All complete'));
 
125
 
 
126
                $this->Shell->params = array();
 
127
                $this->Shell->args = array('User');
 
128
                $this->Shell->all();
 
129
        }
 
130
}