UseStatementPassTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2017 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\UseStatementPass;
  12. class UseStatementPassTest extends CodeCleanerTestCase
  13. {
  14. public function setUp()
  15. {
  16. $this->setPass(new UseStatementPass());
  17. }
  18. /**
  19. * @dataProvider useStatements
  20. */
  21. public function testProcess($from, $to)
  22. {
  23. $this->assertProcessesAs($from, $to);
  24. }
  25. public function useStatements()
  26. {
  27. return array(
  28. array(
  29. "use StdClass as NotSoStd;\n\$std = new NotSoStd();",
  30. '$std = new \\StdClass();',
  31. ),
  32. array(
  33. "namespace Foo;\n\nuse StdClass as S;\n\$std = new S();",
  34. "namespace Foo;\n\n\$std = new \\StdClass();",
  35. ),
  36. array(
  37. "namespace Foo;\n\nuse \\StdClass as S;\n\$std = new S();",
  38. "namespace Foo;\n\n\$std = new \\StdClass();",
  39. ),
  40. array(
  41. "use Foo\\Bar as fb;\n\$baz = new fb\\Baz();",
  42. '$baz = new \\Foo\\Bar\\Baz();',
  43. ),
  44. );
  45. }
  46. }