4 * This file is part of Psy Shell.
6 * (c) 2012-2018 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
16 class SudoTest extends \PHPUnit\Framework\TestCase
18 public function setUp()
20 if (version_compare(PHP_VERSION, '7.1.0', '<')) {
21 $this->markTestSkipped('YOLO');
25 public function testFetchProperty()
27 $obj = new ClassWithSecrets();
28 $this->assertSame('private and prop', Sudo::fetchProperty($obj, 'privateProp'));
31 public function testAssignProperty()
33 $obj = new ClassWithSecrets();
34 $this->assertSame('private and prop', Sudo::fetchProperty($obj, 'privateProp'));
35 $this->assertSame('not so private now', Sudo::assignProperty($obj, 'privateProp', 'not so private now'));
36 $this->assertSame('not so private now', Sudo::fetchProperty($obj, 'privateProp'));
39 public function testCallMethod()
41 $obj = new ClassWithSecrets();
42 $this->assertSame('private and method', Sudo::callMethod($obj, 'privateMethod'));
43 $this->assertSame('private and method with 1', Sudo::callMethod($obj, 'privateMethod', 1));
45 'private and method with ["foo",2]',
46 Sudo::callMethod($obj, 'privateMethod', ['foo', 2]
50 public function testFetchStaticProperty()
52 $obj = new ClassWithSecrets();
53 $this->assertSame('private and static and prop', Sudo::fetchStaticProperty($obj, 'privateStaticProp'));
56 public function testAssignStaticProperty()
58 $obj = new ClassWithSecrets();
59 $this->assertSame('private and static and prop', Sudo::fetchStaticProperty($obj, 'privateStaticProp'));
60 $this->assertSame('not so private now', Sudo::assignStaticProperty($obj, 'privateStaticProp', 'not so private now'));
61 $this->assertSame('not so private now', Sudo::fetchStaticProperty($obj, 'privateStaticProp'));
64 public function testCallStatic()
66 $obj = new ClassWithSecrets();
67 $this->assertSame('private and static and method', Sudo::callStatic($obj, 'privateStaticMethod'));
68 $this->assertSame('private and static and method with 1', Sudo::callStatic($obj, 'privateStaticMethod', 1));
70 'private and static and method with ["foo",2]',
71 Sudo::callStatic($obj, 'privateStaticMethod', ['foo', 2]
75 public function testFetchClassConst()
77 $obj = new ClassWithSecrets();
78 $this->assertSame('private and const', Sudo::fetchClassConst($obj, 'PRIVATE_CONST'));