Nenhuma descrição

CalledClassPassTest.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2018 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\CalledClassPass;
  12. class CalledClassPassTest extends CodeCleanerTestCase
  13. {
  14. public function setUp()
  15. {
  16. $this->setPass(new CalledClassPass());
  17. }
  18. /**
  19. * @dataProvider invalidStatements
  20. * @expectedException \Psy\Exception\ErrorException
  21. */
  22. public function testProcessStatementFails($code)
  23. {
  24. $this->parseAndTraverse($code);
  25. }
  26. public function invalidStatements()
  27. {
  28. return [
  29. ['get_class()'],
  30. ['get_class(null)'],
  31. ['get_called_class()'],
  32. ['get_called_class(null)'],
  33. ['function foo() { return get_class(); }'],
  34. ['function foo() { return get_class(null); }'],
  35. ['function foo() { return get_called_class(); }'],
  36. ['function foo() { return get_called_class(null); }'],
  37. ];
  38. }
  39. /**
  40. * @dataProvider validStatements
  41. */
  42. public function testProcessStatementPasses($code)
  43. {
  44. $this->parseAndTraverse($code);
  45. $this->assertTrue(true);
  46. }
  47. public function validStatements()
  48. {
  49. return [
  50. ['get_class($foo)'],
  51. ['get_class(bar())'],
  52. ['get_called_class($foo)'],
  53. ['get_called_class(bar())'],
  54. ['function foo($bar) { return get_class($bar); }'],
  55. ['function foo($bar) { return get_called_class($bar); }'],
  56. ['class Foo { function bar() { return get_class(); } }'],
  57. ['class Foo { function bar() { return get_class(null); } }'],
  58. ['class Foo { function bar() { return get_called_class(); } }'],
  59. ['class Foo { function bar() { return get_called_class(null); } }'],
  60. ['$foo = function () {}; $foo()'],
  61. ];
  62. }
  63. /**
  64. * @dataProvider validTraitStatements
  65. */
  66. public function testProcessTraitStatementPasses($code)
  67. {
  68. $this->parseAndTraverse($code);
  69. $this->assertTrue(true);
  70. }
  71. public function validTraitStatements()
  72. {
  73. return [
  74. ['trait Foo { function bar() { return get_class(); } }'],
  75. ['trait Foo { function bar() { return get_class(null); } }'],
  76. ['trait Foo { function bar() { return get_called_class(); } }'],
  77. ['trait Foo { function bar() { return get_called_class(null); } }'],
  78. ];
  79. }
  80. }