X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FTestingAccessWrapperTest.php;h=23eb023ab96169b74508fc7f316dd1bbdafbddb7;hb=11cdbc02482f7b9de42184f02f1484dc1ff48cbd;hp=fc54afae338176802b00370c7db6151f6359800b;hpb=4f21e6be661f7305abc223bb31600970a3fb5326;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/TestingAccessWrapperTest.php b/tests/phpunit/includes/TestingAccessWrapperTest.php index fc54afae33..23eb023ab9 100644 --- a/tests/phpunit/includes/TestingAccessWrapperTest.php +++ b/tests/phpunit/includes/TestingAccessWrapperTest.php @@ -3,6 +3,7 @@ class TestingAccessWrapperTest extends MediaWikiTestCase { protected $raw; protected $wrapped; + protected $wrappedStatic; function setUp() { parent::setUp(); @@ -10,12 +11,38 @@ class TestingAccessWrapperTest extends MediaWikiTestCase { require_once __DIR__ . '/../data/helpers/WellProtectedClass.php'; $this->raw = new WellProtectedClass(); $this->wrapped = TestingAccessWrapper::newFromObject( $this->raw ); + $this->wrappedStatic = TestingAccessWrapper::newFromClass( 'WellProtectedClass' ); + } + + /** + * @expectedException InvalidArgumentException + */ + function testConstructorException() { + TestingAccessWrapper::newFromObject( 'WellProtectedClass' ); + } + + /** + * @expectedException InvalidArgumentException + */ + function testStaticConstructorException() { + TestingAccessWrapper::newFromClass( new WellProtectedClass() ); } function testGetProperty() { $this->assertSame( 1, $this->wrapped->property ); $this->assertSame( 42, $this->wrapped->privateProperty ); $this->assertSame( 9000, $this->wrapped->privateParentProperty ); + $this->assertSame( 'sp', $this->wrapped->staticProperty ); + $this->assertSame( 'spp', $this->wrapped->staticPrivateProperty ); + $this->assertSame( 'sp', $this->wrappedStatic->staticProperty ); + $this->assertSame( 'spp', $this->wrappedStatic->staticPrivateProperty ); + } + + /** + * @expectedException DomainException + */ + function testGetException() { + $this->wrappedStatic->property; } function testSetProperty() { @@ -30,6 +57,33 @@ class TestingAccessWrapperTest extends MediaWikiTestCase { $this->wrapped->privateParentProperty = 12; $this->assertSame( 12, $this->wrapped->privateParentProperty ); $this->assertSame( 12, $this->raw->getPrivateParentProperty() ); + + $this->wrapped->staticProperty = 'x'; + $this->assertSame( 'x', $this->wrapped->staticProperty ); + $this->assertSame( 'x', $this->wrappedStatic->staticProperty ); + + $this->wrapped->staticPrivateProperty = 'y'; + $this->assertSame( 'y', $this->wrapped->staticPrivateProperty ); + $this->assertSame( 'y', $this->wrappedStatic->staticPrivateProperty ); + + $this->wrappedStatic->staticProperty = 'X'; + $this->assertSame( 'X', $this->wrapped->staticProperty ); + $this->assertSame( 'X', $this->wrappedStatic->staticProperty ); + + $this->wrappedStatic->staticPrivateProperty = 'Y'; + $this->assertSame( 'Y', $this->wrapped->staticPrivateProperty ); + $this->assertSame( 'Y', $this->wrappedStatic->staticPrivateProperty ); + + // don't rely on PHPUnit to restore static properties + $this->wrapped->staticProperty = 'sp'; + $this->wrapped->staticPrivateProperty = 'spp'; + } + + /** + * @expectedException DomainException + */ + function testSetException() { + $this->wrappedStatic->property = 1; } function testCallMethod() { @@ -44,9 +98,22 @@ class TestingAccessWrapperTest extends MediaWikiTestCase { $this->wrapped->incrementPrivateParentPropertyValue(); $this->assertSame( 9001, $this->wrapped->privateParentProperty ); $this->assertSame( 9001, $this->raw->getPrivateParentProperty() ); + + $this->assertSame( 'sm', $this->wrapped->staticMethod() ); + $this->assertSame( 'spm', $this->wrapped->staticPrivateMethod() ); + $this->assertSame( 'sm', $this->wrappedStatic->staticMethod() ); + $this->assertSame( 'spm', $this->wrappedStatic->staticPrivateMethod() ); } function testCallMethodTwoArgs() { $this->assertSame( 'two', $this->wrapped->whatSecondArg( 'one', 'two' ) ); } + + /** + * @expectedException DomainException + */ + function testCallMethodException() { + $this->wrappedStatic->incrementPropertyValue(); + } + }