Mock.php 1.6 KB

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