No Description

AutoCompleterTest.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Psy\Test\TabCompletion;
  3. use Psy\Command\ListCommand;
  4. use Psy\Command\ShowCommand;
  5. use Psy\Configuration;
  6. use Psy\Context;
  7. use Psy\ContextAware;
  8. use Psy\TabCompletion\Matcher;
  9. class AutoCompleterTest extends \PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @dataProvider classesInput
  13. */
  14. public function testClassesCompletion($line, $expect)
  15. {
  16. $context = new Context();
  17. $commands = array(
  18. new ShowCommand(),
  19. new ListCommand(),
  20. );
  21. $matchers = array(
  22. new Matcher\VariablesMatcher(),
  23. new Matcher\ClassNamesMatcher(),
  24. new Matcher\ConstantsMatcher(),
  25. new Matcher\FunctionsMatcher(),
  26. new Matcher\ObjectMethodsMatcher(),
  27. new Matcher\ObjectAttributesMatcher(),
  28. new Matcher\KeywordsMatcher(),
  29. new Matcher\ClassAttributesMatcher(),
  30. new Matcher\ClassMethodsMatcher(),
  31. new Matcher\CommandsMatcher($commands),
  32. );
  33. $config = new Configuration();
  34. $tabCompletion = $config->getAutoCompleter();
  35. foreach ($matchers as $matcher) {
  36. if ($matcher instanceof ContextAware) {
  37. $matcher->setContext($context);
  38. }
  39. $tabCompletion->addMatcher($matcher);
  40. }
  41. $context->setAll(array('foo' => 12, 'bar' => new \DOMDocument()));
  42. $code = $tabCompletion->processCallback('', 0, array(
  43. 'line_buffer' => $line,
  44. 'point' => 0,
  45. 'end' => strlen($line),
  46. ));
  47. $this->assertContains($expect, $code);
  48. }
  49. public function classesInput()
  50. {
  51. return array(
  52. array('T_OPE', 'T_OPEN_TAG'),
  53. array('st', 'stdClass'),
  54. array('stdCla', 'stdClass'),
  55. array('new s', 'stdClass'),
  56. array('\s', 'stdClass'),
  57. array('array_', 'array_search'),
  58. array('$bar->', 'load'),
  59. array('$b', 'bar' ),
  60. array('6 + $b', 'bar' ),
  61. array('$f', 'foo' ),
  62. array('l', 'ls'),
  63. array('sho', 'show'),
  64. array('12 + clone $', 'foo' ),
  65. array(
  66. 'Psy\Test\TabCompletion\StaticSample::CO',
  67. 'Psy\Test\TabCompletion\StaticSample::CONSTANT_VALUE',
  68. ),
  69. array(
  70. 'Psy\Test\TabCompletion\StaticSample::',
  71. 'Psy\Test\TabCompletion\StaticSample::$staticVariable',
  72. ),
  73. array(
  74. 'Psy\Test\TabCompletion\StaticSample::',
  75. 'Psy\Test\TabCompletion\StaticSample::staticFunction',
  76. ),
  77. );
  78. }
  79. }