/
Mock.php
74 lines (65 loc) · 1.68 KB
/
Mock.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Lithium: the most rad php framework
*
* @copyright Copyright 2010, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
namespace lithium\console\command\create;
use lithium\util\Inflector;
/**
* Generate a Mock that extends the name of the given class in the `--library` namespace.
*
* `li3 create mock model Post`
* `li3 create --library=li3_plugin mock model Post`
*
*/
class Mock extends \lithium\console\command\Create {
/**
* Get the namespace for the mock.
*
* @param string $request
* @param string $options
* @return string
*/
protected function _namespace($request, $options = array()) {
$request->params['command'] = $request->action;
return parent::_namespace($request, array('prepend' => 'tests.mocks.'));
}
/**
* Get the parent for the mock.
*
* @param string $request
* @return string
*/
protected function _parent($request) {
$namespace = parent::_namespace($request);
$class = $request->action;
return "\\{$namespace}\\{$class}";
}
/**
* Get the class name for the mock.
*
* @param string $request
* @return string
*/
protected function _class($request) {
$type = $request->action;
$name = $request->args();
if ($command = $this->_instance($type)) {
$request->params['action'] = $name;
$name = $command->invokeMethod('_class', array($request));
}
return Inflector::classify("Mock{$name}");
}
/**
* Get the methods for the mock to override
*
* @param string $request
* @return string
*/
protected function _methods($request) {
return null;
}
}
?>