No Description

NamespacePassTest.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * This file is part of Psy Shell
  4. *
  5. * (c) 2012-2014 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Psy\Test\CodeCleaner;
  11. use Psy\CodeCleaner;
  12. use Psy\CodeCleaner\NamespacePass;
  13. class NamespacePassTest extends CodeCleanerTestCase
  14. {
  15. private $cleaner;
  16. public function setUp()
  17. {
  18. $this->cleaner = new CodeCleaner();
  19. $this->setPass(new NamespacePass($this->cleaner));
  20. }
  21. public function testProcess()
  22. {
  23. $this->process('array_merge()');
  24. $this->assertNull($this->cleaner->getNamespace());
  25. // A non-block namespace statement should set the current namespace.
  26. $this->process('namespace Alpha');
  27. $this->assertEquals(array('Alpha'), $this->cleaner->getNamespace());
  28. // A new non-block namespace statement should override the current namespace.
  29. $this->process('namespace Beta');
  30. $this->assertEquals(array('Beta'), $this->cleaner->getNamespace());
  31. $this->process('namespace Gamma { array_merge(); }');
  32. $this->assertNull($this->cleaner->getNamespace());
  33. }
  34. private function process($code)
  35. {
  36. $stmts = $this->parse($code);
  37. $this->traverse($stmts);
  38. }
  39. }