설명 없음

SudoTest.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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;
  11. use Psy\Sudo;
  12. class SudoTest extends \PHPUnit\Framework\TestCase
  13. {
  14. public function setUp()
  15. {
  16. if (\version_compare(PHP_VERSION, '7.1.0', '<')) {
  17. $this->markTestSkipped('YOLO');
  18. }
  19. }
  20. public function testFetchProperty()
  21. {
  22. $obj = new ClassWithSecrets();
  23. $this->assertSame('private and prop', Sudo::fetchProperty($obj, 'privateProp'));
  24. }
  25. public function testAssignProperty()
  26. {
  27. $obj = new ClassWithSecrets();
  28. $this->assertSame('private and prop', Sudo::fetchProperty($obj, 'privateProp'));
  29. $this->assertSame('not so private now', Sudo::assignProperty($obj, 'privateProp', 'not so private now'));
  30. $this->assertSame('not so private now', Sudo::fetchProperty($obj, 'privateProp'));
  31. }
  32. public function testCallMethod()
  33. {
  34. $obj = new ClassWithSecrets();
  35. $this->assertSame('private and method', Sudo::callMethod($obj, 'privateMethod'));
  36. $this->assertSame('private and method with 1', Sudo::callMethod($obj, 'privateMethod', 1));
  37. $this->assertSame(
  38. 'private and method with ["foo",2]',
  39. Sudo::callMethod($obj, 'privateMethod', ['foo', 2]
  40. ));
  41. }
  42. public function testFetchStaticProperty()
  43. {
  44. $obj = new ClassWithSecrets();
  45. $this->assertSame('private and static and prop', Sudo::fetchStaticProperty($obj, 'privateStaticProp'));
  46. }
  47. public function testAssignStaticProperty()
  48. {
  49. $obj = new ClassWithSecrets();
  50. $this->assertSame('private and static and prop', Sudo::fetchStaticProperty($obj, 'privateStaticProp'));
  51. $this->assertSame('not so private now', Sudo::assignStaticProperty($obj, 'privateStaticProp', 'not so private now'));
  52. $this->assertSame('not so private now', Sudo::fetchStaticProperty($obj, 'privateStaticProp'));
  53. }
  54. public function testCallStatic()
  55. {
  56. $obj = new ClassWithSecrets();
  57. $this->assertSame('private and static and method', Sudo::callStatic($obj, 'privateStaticMethod'));
  58. $this->assertSame('private and static and method with 1', Sudo::callStatic($obj, 'privateStaticMethod', 1));
  59. $this->assertSame(
  60. 'private and static and method with ["foo",2]',
  61. Sudo::callStatic($obj, 'privateStaticMethod', ['foo', 2]
  62. ));
  63. }
  64. public function testFetchClassConst()
  65. {
  66. $obj = new ClassWithSecrets();
  67. $this->assertSame('private and const', Sudo::fetchClassConst($obj, 'PRIVATE_CONST'));
  68. }
  69. }