PageRenderTime 26ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/vendor/symfony/test/other/tasksTest.php

https://github.com/openpne/OpenPNE3
PHP | 132 lines | 92 code | 33 blank | 7 comment | 3 complexity | ed1165c663c775e9cf753db7d1aeeac4 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. <?php
  2. $_test_dir = realpath(__DIR__.'/..');
  3. require_once($_test_dir.'/../lib/vendor/lime/lime.php');
  4. require_once($_test_dir.'/../lib/util/sfToolkit.class.php');
  5. define('DS', DIRECTORY_SEPARATOR);
  6. class sf_test_project
  7. {
  8. public $php_cli = null;
  9. public $tmp_dir = null;
  10. public $t = null;
  11. public $current_dir = null;
  12. public function initialize($t)
  13. {
  14. $this->t = $t;
  15. $this->tmp_dir = sys_get_temp_dir().DS.'sf_test_project';
  16. if (is_dir($this->tmp_dir))
  17. {
  18. $this->clearTmpDir();
  19. rmdir($this->tmp_dir);
  20. }
  21. mkdir($this->tmp_dir, 0777);
  22. $this->current_dir = getcwd();
  23. chdir($this->tmp_dir);
  24. $this->php_cli = sfToolkit::getPhpCli();
  25. }
  26. public function shutdown()
  27. {
  28. $this->clearTmpDir();
  29. rmdir($this->tmp_dir);
  30. chdir($this->current_dir);
  31. }
  32. protected function clearTmpDir()
  33. {
  34. require_once(__DIR__.'/../../lib/util/sfToolkit.class.php');
  35. sfToolkit::clearDirectory($this->tmp_dir);
  36. }
  37. public function execute_command($cmd, $awaited_return=0)
  38. {
  39. chdir($this->tmp_dir);
  40. $symfony = file_exists('symfony') ? 'symfony' : __DIR__.'/../../data/bin/symfony';
  41. ob_start();
  42. passthru(sprintf('%s "%s" %s 2>&1', $this->php_cli, $symfony, $cmd), $return);
  43. $content = ob_get_clean();
  44. $this->t->cmp_ok($return, '==', $awaited_return, sprintf('"symfony %s" returns awaited value (%d)', $cmd, $awaited_return));
  45. return $content;
  46. }
  47. public function get_fixture_content($file)
  48. {
  49. return str_replace("\r\n", "\n", file_get_contents(__DIR__.'/fixtures/'.$file));
  50. }
  51. }
  52. $plan = 18;
  53. $t = new lime_test($plan);
  54. if (!extension_loaded('SQLite') && !extension_loaded('pdo_SQLite'))
  55. {
  56. $t->skip('You need SQLite to run these tests', $plan);
  57. return;
  58. }
  59. $c = new sf_test_project();
  60. $c->initialize($t);
  61. // generate:*
  62. $content = $c->execute_command('generate:project myproject --orm=Doctrine');
  63. $t->ok(file_exists($c->tmp_dir.DS.'symfony'), '"generate:project" installs the symfony CLI in root project directory');
  64. $content = $c->execute_command('generate:app frontend');
  65. $t->ok(is_dir($c->tmp_dir.DS.'apps'.DS.'frontend'), '"generate:app" creates a "frontend" directory under "apps" directory');
  66. $t->like(file_get_contents($c->tmp_dir.'/apps/frontend/config/settings.yml'), '/escaping_strategy: +true/', '"generate:app" switches escaping_strategy "on" by default');
  67. $t->like(file_get_contents($c->tmp_dir.'/apps/frontend/config/settings.yml'), '/csrf_secret: +\w+/', '"generate:app" generates a csrf_token by default');
  68. $content = $c->execute_command('generate:app backend --escaping-strategy=false --csrf-secret=false');
  69. $t->like(file_get_contents($c->tmp_dir.'/apps/backend/config/settings.yml'), '/escaping_strategy: +false/', '"generate:app" switches escaping_strategy "false"');
  70. $t->like(file_get_contents($c->tmp_dir.'/apps/backend/config/settings.yml'), '/csrf_secret: +false/', '"generate:app" switches csrf_token to "false"');
  71. // failing
  72. $content = $c->execute_command('generate:module wrongapp foo', 1);
  73. $content = $c->execute_command('generate:module frontend foo');
  74. $t->ok(is_dir($c->tmp_dir.DS.'apps'.DS.'frontend'.DS.'modules'.DS.'foo'), '"generate:module" creates a "foo" directory under "modules" directory');
  75. copy(__DIR__.'/fixtures/factories.yml', $c->tmp_dir.DS.'apps'.DS.'frontend'.DS.'config'.DS.'factories.yml');
  76. // test:*
  77. copy(__DIR__.'/fixtures/test/unit/testTest.php', $c->tmp_dir.DS.'test'.DS.'unit'.DS.'testTest.php');
  78. $content = $c->execute_command('test:unit test');
  79. $t->is($content, $c->get_fixture_content('/test/unit/result.txt'), '"test:unit" can launch a particular unit test');
  80. $content = $c->execute_command('test:unit');
  81. // this test is failing on 7.1 because tempnam() raise a notice because it uses sys_get_temp_dir()
  82. // so strict comparison doesn't work because the result contains the notice
  83. // $t->like($content, $c->get_fixture_content('test/unit/result-harness.txt'), '"test:unit" can launch all unit tests');
  84. $t->ok(false !== stripos($content, $c->get_fixture_content('test/unit/result-harness.txt')), '"test:unit" can launch all unit tests');
  85. $content = $c->execute_command('cache:clear');
  86. // Test task autoloading
  87. mkdir($c->tmp_dir.DS.'lib'.DS.'task');
  88. mkdir($pluginDir = $c->tmp_dir.DS.'plugins'.DS.'myFooPlugin'.DS.'lib'.DS.'task', 0777, true);
  89. copy(__DIR__.'/fixtures/task/myPluginTask.class.php', $pluginDir.DS.'myPluginTask.class.php');
  90. file_put_contents(
  91. $projectConfigurationFile = $c->tmp_dir.DS.'config'.DS.'ProjectConfiguration.class.php',
  92. str_replace(
  93. '$this->enablePlugins(\'sfDoctrinePlugin\')',
  94. '$this->enablePlugins(array(\'sfDoctrinePlugin\', \'myFooPlugin\'))',
  95. file_get_contents($projectConfigurationFile)
  96. )
  97. );
  98. $c->execute_command('p:run');
  99. $c->shutdown();