Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConsoleTest.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Friendica\Test\src\Core\Console;
  3. use Friendica\App;
  4. use Friendica\BaseObject;
  5. use Friendica\Database\DBA;
  6. use Friendica\Test\Util\Intercept;
  7. use Friendica\Test\Util\VFSTrait;
  8. use org\bovigo\vfs\vfsStream;
  9. use org\bovigo\vfs\vfsStreamDirectory;
  10. use PHPUnit\Framework\TestCase;
  11. abstract class ConsoleTest extends TestCase
  12. {
  13. use VFSTrait;
  14. /**
  15. * @var MultiUseConsole Extension of the basic Friendica Console for testing purpose
  16. */
  17. private $console;
  18. /**
  19. * @var App The Friendica App
  20. */
  21. protected $app;
  22. protected $stdout;
  23. protected function setUp()
  24. {
  25. parent::setUp();
  26. Intercept::setUp();
  27. if (!getenv('MYSQL_DATABASE')) {
  28. $this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
  29. }
  30. $this->setUpVfsDir();
  31. // fake console.php for setting an executable
  32. vfsStream::newFile('console.php')
  33. ->at($this->root->getChild('bin'))
  34. ->setContent('<? php');
  35. // Reusable App object
  36. $this->app = new App($this->root->url());
  37. BaseObject::setApp($this->app);
  38. $this->console = new MultiUseConsole();
  39. }
  40. public function execute($args) {
  41. DBA::disconnect();
  42. $this->app->reload();
  43. array_unshift($args, $this->getExecutablePath());
  44. Intercept::reset();
  45. $this->console->reset();
  46. $this->console->parseTestArgv($args);
  47. $this->console->execute();
  48. $returnStr = Intercept::$cache;
  49. Intercept::reset();
  50. return $returnStr;
  51. }
  52. /**
  53. * @return string returns the path to the console executable during tests
  54. */
  55. protected function getExecutablePath() {
  56. return $this->root->getChild('bin' . DIRECTORY_SEPARATOR . 'console.php')->url();
  57. }
  58. }