commandUnitTest.php

  1. 8.0.x tests/commandUnitTest.php
  2. 6.x tests/commandUnitTest.php
  3. 7.x tests/commandUnitTest.php
  4. 5.x tests/commandUnitTest.php
  5. master tests/commandUnitTest.php

Namespace

Unish

Classes

Namesort descending Description
commandUnitCase

File

tests/commandUnitTest.php
View source
  1. <?php
  2. namespace Unish;
  3. use Webmozart\PathUtil\Path;
  4. class commandUnitCase extends UnitUnishTestCase {
  5. /**
  6. * Assure that matching version-specific command files are loaded and others are ignored.
  7. */
  8. function testCommandVersionSpecific() {
  9. $path = Path::join(UNISH_SANDBOX, 'commandUnitCase');
  10. $major = $this->drush_major_version();
  11. $major_plus1 = $major + 1;
  12. // Write matched and unmatched files to the system search path.
  13. $files = array(
  14. Path::join($path, "$major.drush$major.inc"),
  15. Path::join($path, "drush$major/drush$major.drush.inc"),
  16. Path::join($path, "$major_plus1.drush$major_plus1.inc"),
  17. Path::join($path, "drush$major_plus1/drush$major_plus1.drush.inc"),
  18. );
  19. $this->mkdir(Path::join($path, 'drush'. $major));
  20. $this->mkdir(Path::join($path, 'drush'. $major_plus1));
  21. foreach ($files as $file) {
  22. $contents = <<<EOD
  23. <?php
  24. // Written by Unish. This file is safe to delete.
  25. \$GLOBALS['unish_foo'][] = '$file';
  26. EOD;
  27. $return = file_put_contents($file, $contents);
  28. }
  29. drush_set_context('DRUSH_INCLUDE', array($path));
  30. drush_preflight();
  31. $loaded = drush_commandfile_list();
  32. $this->assertContains($files[0], $loaded); //Loaded a version-specific command file.
  33. $this->assertContains($files[1], $loaded); //Loaded a version-specific command directory.
  34. $this->assertNotContains($files[2], $loaded); //Did not load a mismatched version-specific command file.
  35. $this->assertNotContains($files[3], $loaded); //Did not load a a mismatched version-specific command directory.
  36. }
  37. /**
  38. * Assert that $command has interesting properties. Reference command by
  39. * it's alias (dl) to assure that those aliases are built as expected.
  40. */
  41. public function testGetCommands() {
  42. drush_preflight();
  43. $commands = drush_get_commands();
  44. $command = $commands['dl'];
  45. $this->assertEquals('dl', current($command['aliases']));
  46. $this->assertArrayHasKey('version_control', $command['engines']);
  47. $this->assertArrayHasKey('package_handler', $command['engines']);
  48. $this->assertArrayHasKey('release_info', $command['engines']);
  49. $this->assertEquals('pm-download', $command['command']);
  50. $this->assertEquals('pm', $command['commandfile']);
  51. $this->assertEquals('drush_command', $command['callback']);
  52. $this->assertArrayHasKey('examples', $command['sections']);
  53. $this->assertTrue($command['is_alias']);
  54. $command = $commands['pm-download'];
  55. $this->assertArrayNotHasKey('is_alias', $command);
  56. }
  57. }