Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / TestingAccessWrapperTest.php
blob23eb023ab96169b74508fc7f316dd1bbdafbddb7
1 <?php
3 class TestingAccessWrapperTest extends MediaWikiTestCase {
4 protected $raw;
5 protected $wrapped;
6 protected $wrappedStatic;
8 function setUp() {
9 parent::setUp();
11 require_once __DIR__ . '/../data/helpers/WellProtectedClass.php';
12 $this->raw = new WellProtectedClass();
13 $this->wrapped = TestingAccessWrapper::newFromObject( $this->raw );
14 $this->wrappedStatic = TestingAccessWrapper::newFromClass( 'WellProtectedClass' );
17 /**
18 * @expectedException InvalidArgumentException
20 function testConstructorException() {
21 TestingAccessWrapper::newFromObject( 'WellProtectedClass' );
24 /**
25 * @expectedException InvalidArgumentException
27 function testStaticConstructorException() {
28 TestingAccessWrapper::newFromClass( new WellProtectedClass() );
31 function testGetProperty() {
32 $this->assertSame( 1, $this->wrapped->property );
33 $this->assertSame( 42, $this->wrapped->privateProperty );
34 $this->assertSame( 9000, $this->wrapped->privateParentProperty );
35 $this->assertSame( 'sp', $this->wrapped->staticProperty );
36 $this->assertSame( 'spp', $this->wrapped->staticPrivateProperty );
37 $this->assertSame( 'sp', $this->wrappedStatic->staticProperty );
38 $this->assertSame( 'spp', $this->wrappedStatic->staticPrivateProperty );
41 /**
42 * @expectedException DomainException
44 function testGetException() {
45 $this->wrappedStatic->property;
48 function testSetProperty() {
49 $this->wrapped->property = 10;
50 $this->assertSame( 10, $this->wrapped->property );
51 $this->assertSame( 10, $this->raw->getProperty() );
53 $this->wrapped->privateProperty = 11;
54 $this->assertSame( 11, $this->wrapped->privateProperty );
55 $this->assertSame( 11, $this->raw->getPrivateProperty() );
57 $this->wrapped->privateParentProperty = 12;
58 $this->assertSame( 12, $this->wrapped->privateParentProperty );
59 $this->assertSame( 12, $this->raw->getPrivateParentProperty() );
61 $this->wrapped->staticProperty = 'x';
62 $this->assertSame( 'x', $this->wrapped->staticProperty );
63 $this->assertSame( 'x', $this->wrappedStatic->staticProperty );
65 $this->wrapped->staticPrivateProperty = 'y';
66 $this->assertSame( 'y', $this->wrapped->staticPrivateProperty );
67 $this->assertSame( 'y', $this->wrappedStatic->staticPrivateProperty );
69 $this->wrappedStatic->staticProperty = 'X';
70 $this->assertSame( 'X', $this->wrapped->staticProperty );
71 $this->assertSame( 'X', $this->wrappedStatic->staticProperty );
73 $this->wrappedStatic->staticPrivateProperty = 'Y';
74 $this->assertSame( 'Y', $this->wrapped->staticPrivateProperty );
75 $this->assertSame( 'Y', $this->wrappedStatic->staticPrivateProperty );
77 // don't rely on PHPUnit to restore static properties
78 $this->wrapped->staticProperty = 'sp';
79 $this->wrapped->staticPrivateProperty = 'spp';
82 /**
83 * @expectedException DomainException
85 function testSetException() {
86 $this->wrappedStatic->property = 1;
89 function testCallMethod() {
90 $this->wrapped->incrementPropertyValue();
91 $this->assertSame( 2, $this->wrapped->property );
92 $this->assertSame( 2, $this->raw->getProperty() );
94 $this->wrapped->incrementPrivatePropertyValue();
95 $this->assertSame( 43, $this->wrapped->privateProperty );
96 $this->assertSame( 43, $this->raw->getPrivateProperty() );
98 $this->wrapped->incrementPrivateParentPropertyValue();
99 $this->assertSame( 9001, $this->wrapped->privateParentProperty );
100 $this->assertSame( 9001, $this->raw->getPrivateParentProperty() );
102 $this->assertSame( 'sm', $this->wrapped->staticMethod() );
103 $this->assertSame( 'spm', $this->wrapped->staticPrivateMethod() );
104 $this->assertSame( 'sm', $this->wrappedStatic->staticMethod() );
105 $this->assertSame( 'spm', $this->wrappedStatic->staticPrivateMethod() );
108 function testCallMethodTwoArgs() {
109 $this->assertSame( 'two', $this->wrapped->whatSecondArg( 'one', 'two' ) );
113 * @expectedException DomainException
115 function testCallMethodException() {
116 $this->wrappedStatic->incrementPropertyValue();