* @license MIT * * @covers \ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion * @group Coverage */ class CanProxyAssertionTest extends PHPUnit_Framework_TestCase { public function testDeniesFinalClasses() { $this->setExpectedException('ProxyManager\Exception\InvalidProxiedClassException'); CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass('ProxyManagerTestAsset\\FinalClass')); } public function testDeniesClassesWithAbstractProtectedMethods() { $this->setExpectedException('ProxyManager\Exception\InvalidProxiedClassException'); CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass( 'ProxyManagerTestAsset\\ClassWithAbstractProtectedMethod' )); } public function testAllowsInterfaceByDefault() { CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass( 'ProxyManagerTestAsset\\BaseInterface' )); $this->assertTrue(true); // not nice, but assertions are just fail-checks, no real code executed } public function testDeniesInterfaceIfSpecified() { $this->setExpectedException('ProxyManager\Exception\InvalidProxiedClassException'); CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass('ProxyManagerTestAsset\\BaseInterface'), false); } /** * @param string $className * * @dataProvider validClasses */ public function testAllowedClass($className) { CanProxyAssertion::assertClassCanBeProxied(new ReflectionClass($className)); $this->assertTrue(true); // not nice, but assertions are just fail-checks, no real code executed } public function testDisallowsConstructor() { $this->setExpectedException('BadMethodCallException'); new CanProxyAssertion(); } /** * @return string[][] */ public function validClasses() { return array( array('ProxyManagerTestAsset\AccessInterceptorValueHolderMock'), array('ProxyManagerTestAsset\BaseClass'), array('ProxyManagerTestAsset\BaseInterface'), array('ProxyManagerTestAsset\CallableTypeHintClass'), array('ProxyManagerTestAsset\ClassWithByRefMagicMethods'), array('ProxyManagerTestAsset\ClassWithFinalMagicMethods'), array('ProxyManagerTestAsset\ClassWithFinalMethods'), array('ProxyManagerTestAsset\ClassWithMethodWithDefaultParameters'), array('ProxyManagerTestAsset\ClassWithMixedProperties'), array('ProxyManagerTestAsset\ClassWithPrivateProperties'), array('ProxyManagerTestAsset\ClassWithProtectedProperties'), array('ProxyManagerTestAsset\ClassWithPublicProperties'), array('ProxyManagerTestAsset\ClassWithPublicArrayProperty'), array('ProxyManagerTestAsset\ClassWithSelfHint'), array('ProxyManagerTestAsset\EmptyClass'), array('ProxyManagerTestAsset\HydratedObject'), array('ProxyManagerTestAsset\LazyLoadingMock'), array('ProxyManagerTestAsset\NullObjectMock'), ); } }