No Description

MirrorTest.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Util;
  11. use Psy\Util\Mirror;
  12. use Psy\Reflection\ReflectionConstant;
  13. class MirrorTest extends \PHPUnit_Framework_TestCase
  14. {
  15. const FOO = 1;
  16. private $bar = 2;
  17. private static $baz = 3;
  18. public function aPublicMethod()
  19. {
  20. // nada
  21. }
  22. public function testMirror()
  23. {
  24. $refl = Mirror::get('sort');
  25. $this->assertTrue($refl instanceof \ReflectionFunction);
  26. $refl = Mirror::get('Psy\Test\Util\MirrorTest');
  27. $this->assertTrue($refl instanceof \ReflectionClass);
  28. $refl = Mirror::get($this);
  29. $this->assertTrue($refl instanceof \ReflectionObject);
  30. $refl = Mirror::get($this, 'FOO');
  31. $this->assertTrue($refl instanceof ReflectionConstant);
  32. $refl = Mirror::get($this, 'bar');
  33. $this->assertTrue($refl instanceof \ReflectionProperty);
  34. $refl = Mirror::get($this, 'baz');
  35. $this->assertTrue($refl instanceof \ReflectionProperty);
  36. $refl = Mirror::get($this, 'aPublicMethod');
  37. $this->assertTrue($refl instanceof \ReflectionMethod);
  38. $refl = Mirror::get($this, 'baz', Mirror::STATIC_PROPERTY);
  39. $this->assertTrue($refl instanceof \ReflectionProperty);
  40. }
  41. /**
  42. * @expectedException \RuntimeException
  43. */
  44. public function testMirrorThrowsExceptions()
  45. {
  46. Mirror::get($this, 'notAMethod');
  47. }
  48. /**
  49. * @expectedException \InvalidArgumentException
  50. * @dataProvider invalidArguments
  51. */
  52. public function testMirrorThrowsInvalidArgumentExceptions($value)
  53. {
  54. Mirror::get($value);
  55. }
  56. public function invalidArguments()
  57. {
  58. return array(
  59. array('not_a_function_or_class'),
  60. array(array()),
  61. array(1),
  62. );
  63. }
  64. }