comparison vendor/psy/psysh/test/SudoTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 /*
4 * This file is part of Psy Shell.
5 *
6 * (c) 2012-2018 Justin Hileman
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Psy\Test;
13
14 use Psy\Sudo;
15
16 class SudoTest extends \PHPUnit\Framework\TestCase
17 {
18 public function setUp()
19 {
20 if (version_compare(PHP_VERSION, '7.1.0', '<')) {
21 $this->markTestSkipped('YOLO');
22 }
23 }
24
25 public function testFetchProperty()
26 {
27 $obj = new ClassWithSecrets();
28 $this->assertSame('private and prop', Sudo::fetchProperty($obj, 'privateProp'));
29 }
30
31 public function testAssignProperty()
32 {
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'));
37 }
38
39 public function testCallMethod()
40 {
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));
44 $this->assertSame(
45 'private and method with ["foo",2]',
46 Sudo::callMethod($obj, 'privateMethod', ['foo', 2]
47 ));
48 }
49
50 public function testFetchStaticProperty()
51 {
52 $obj = new ClassWithSecrets();
53 $this->assertSame('private and static and prop', Sudo::fetchStaticProperty($obj, 'privateStaticProp'));
54 }
55
56 public function testAssignStaticProperty()
57 {
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'));
62 }
63
64 public function testCallStatic()
65 {
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));
69 $this->assertSame(
70 'private and static and method with ["foo",2]',
71 Sudo::callStatic($obj, 'privateStaticMethod', ['foo', 2]
72 ));
73 }
74
75 public function testFetchClassConst()
76 {
77 $obj = new ClassWithSecrets();
78 $this->assertSame('private and const', Sudo::fetchClassConst($obj, 'PRIVATE_CONST'));
79 }
80 }