MockTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\cases\console\command\create;
  9. use lithium\console\command\create\Mock;
  10. use lithium\console\Request;
  11. use lithium\core\Libraries;
  12. class MockTest extends \lithium\test\Unit {
  13. public $request;
  14. protected $_backup = array();
  15. protected $_testPath = null;
  16. public function skip() {
  17. $this->_testPath = Libraries::get(true, 'resources') . '/tmp/tests';
  18. $this->skipIf(!is_writable($this->_testPath), "Path `{$this->_testPath}` is not writable.");
  19. }
  20. public function setUp() {
  21. $this->classes = array('response' => 'lithium\tests\mocks\console\MockResponse');
  22. $this->_backup['cwd'] = getcwd();
  23. $this->_backup['_SERVER'] = $_SERVER;
  24. $_SERVER['argv'] = array();
  25. Libraries::add('create_test', array('path' => $this->_testPath . '/create_test'));
  26. $this->request = new Request(array('input' => fopen('php://temp', 'w+')));
  27. $this->request->params = array('library' => 'create_test');
  28. }
  29. public function tearDown() {
  30. $_SERVER = $this->_backup['_SERVER'];
  31. chdir($this->_backup['cwd']);
  32. $this->_cleanUp();
  33. }
  34. public function testMockModel() {
  35. $this->request->params += array(
  36. 'command' => 'create', 'action' => 'mock',
  37. 'args' => array('model', 'Posts')
  38. );
  39. $mock = new Mock(array(
  40. 'request' => $this->request, 'classes' => $this->classes
  41. ));
  42. $mock->path = $this->_testPath;
  43. $mock->run('mock');
  44. $expected = "MockPosts created in tests/mocks/models/MockPosts.php.\n";
  45. $result = $mock->response->output;
  46. $this->assertEqual($expected, $result);
  47. $expected = <<<'test'
  48. namespace create_test\tests\mocks\models;
  49. class MockPosts extends \create_test\models\Posts {
  50. }
  51. test;
  52. $replace = array("<?php", "?>");
  53. $result = str_replace($replace, '',
  54. file_get_contents($this->_testPath . '/create_test/tests/mocks/models/MockPosts.php')
  55. );
  56. $this->assertEqual($expected, $result);
  57. }
  58. }
  59. ?>