Ajout du FR
Ajout du FR + correction du "functions.php"
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Base test for proxy generators
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
abstract class AbstractProxyGeneratorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTestedImplementations
|
||||
*
|
||||
* Verifies that generated code is valid and implements expected interfaces
|
||||
*/
|
||||
public function testGeneratesValidCode($className)
|
||||
{
|
||||
$generator = $this->getProxyGenerator();
|
||||
$generatedClassName = UniqueIdentifierGenerator::getIdentifier('AbstractProxyGeneratorTest');
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$originalClass = new ReflectionClass($className);
|
||||
$generatorStrategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate($originalClass, $generatedClass);
|
||||
$generatorStrategy->generate($generatedClass);
|
||||
|
||||
$generatedReflection = new ReflectionClass($generatedClassName);
|
||||
|
||||
if ($originalClass->isInterface()) {
|
||||
$this->assertTrue($generatedReflection->implementsInterface($className));
|
||||
} else {
|
||||
$this->assertSame($originalClass->getName(), $generatedReflection->getParentClass()->getName());
|
||||
}
|
||||
|
||||
$this->assertSame($generatedClassName, $generatedReflection->getName());
|
||||
|
||||
foreach ($this->getExpectedImplementedInterfaces() as $interface) {
|
||||
$this->assertTrue($generatedReflection->implementsInterface($interface));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a new generator instance
|
||||
*
|
||||
* @return \ProxyManager\ProxyGenerator\ProxyGeneratorInterface
|
||||
*/
|
||||
abstract protected function getProxyGenerator();
|
||||
|
||||
/**
|
||||
* Retrieve interfaces that should be implemented by the generated code
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
abstract protected function getExpectedImplementedInterfaces();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTestedImplementations()
|
||||
{
|
||||
return array(
|
||||
array('ProxyManagerTestAsset\\BaseClass'),
|
||||
array('ProxyManagerTestAsset\\ClassWithMagicMethods'),
|
||||
array('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'),
|
||||
array('ProxyManagerTestAsset\\ClassWithMixedProperties'),
|
||||
array('ProxyManagerTestAsset\\BaseInterface'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptor\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicWakeupTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass(
|
||||
'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties'
|
||||
);
|
||||
|
||||
$magicWakeup = new MagicWakeup($reflection);
|
||||
|
||||
$this->assertSame('__wakeup', $magicWakeup->getName());
|
||||
$this->assertCount(0, $magicWakeup->getParameters());
|
||||
$this->assertSame("unset(\$this->bar, \$this->baz);", $magicWakeup->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup::__construct
|
||||
*/
|
||||
public function testBodyStructureWithoutPublicProperties()
|
||||
{
|
||||
$magicWakeup = new MagicWakeup(new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'));
|
||||
|
||||
$this->assertSame('__wakeup', $magicWakeup->getName());
|
||||
$this->assertCount(0, $magicWakeup->getParameters());
|
||||
$this->assertEmpty($magicWakeup->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptor\MethodGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodPrefixInterceptor;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodPrefixInterceptor}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class SetMethodPrefixInterceptorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodPrefixInterceptor::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$suffix = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$suffix->expects($this->once())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$setter = new SetMethodPrefixInterceptor($suffix);
|
||||
|
||||
$this->assertSame('setMethodPrefixInterceptor', $setter->getName());
|
||||
$this->assertCount(2, $setter->getParameters());
|
||||
$this->assertSame('$this->foo[$methodName] = $prefixInterceptor;', $setter->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptor\MethodGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class SetMethodSuffixInterceptorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$suffix = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$suffix->expects($this->once())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$setter = new SetMethodSuffixInterceptor($suffix);
|
||||
|
||||
$this->assertSame('setMethodSuffixInterceptor', $setter->getName());
|
||||
$this->assertCount(2, $setter->getParameters());
|
||||
$this->assertSame('$this->foo[$methodName] = $suffixInterceptor;', $setter->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptor\PropertyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors;
|
||||
use ProxyManagerTest\ProxyGenerator\PropertyGenerator\AbstractUniquePropertyNameTest;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors
|
||||
* @group Coverage
|
||||
*/
|
||||
class MethodPrefixInterceptorsTest extends AbstractUniquePropertyNameTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function createProperty()
|
||||
{
|
||||
return new MethodPrefixInterceptors();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptor\PropertyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodSuffixInterceptors;
|
||||
use ProxyManagerTest\ProxyGenerator\PropertyGenerator\AbstractUniquePropertyNameTest;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodSuffixInterceptors}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodSuffixInterceptors
|
||||
* @group Coverage
|
||||
*/
|
||||
class MethodSuffixInterceptorsTest extends AbstractUniquePropertyNameTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function createProperty()
|
||||
{
|
||||
return new MethodSuffixInterceptors();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class ConstructorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $prefixInterceptors;
|
||||
private $suffixInterceptors;
|
||||
public function setUp()
|
||||
{
|
||||
$this->prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$this->suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$this->prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$this->suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testSignature()
|
||||
{
|
||||
$constructor = new Constructor(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\ClassWithProtectedProperties'),
|
||||
$this->prefixInterceptors,
|
||||
$this->suffixInterceptors
|
||||
);
|
||||
$this->assertSame('__construct', $constructor->getName());
|
||||
|
||||
$parameters = $constructor->getParameters();
|
||||
|
||||
$this->assertCount(3, $parameters);
|
||||
|
||||
$this->assertSame(
|
||||
'ProxyManagerTestAsset\\ClassWithProtectedProperties',
|
||||
$parameters['localizedObject']->getType()
|
||||
);
|
||||
$this->assertSame('array', $parameters['prefixInterceptors']->getType());
|
||||
$this->assertSame('array', $parameters['suffixInterceptors']->getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$constructor = new Constructor(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\ClassWithPublicProperties'),
|
||||
$this->prefixInterceptors,
|
||||
$this->suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'$this->property0 = & $localizedObject->property0;
|
||||
|
||||
$this->property1 = & $localizedObject->property1;
|
||||
|
||||
$this->property2 = & $localizedObject->property2;
|
||||
|
||||
$this->property3 = & $localizedObject->property3;
|
||||
|
||||
$this->property4 = & $localizedObject->property4;
|
||||
|
||||
$this->property5 = & $localizedObject->property5;
|
||||
|
||||
$this->property6 = & $localizedObject->property6;
|
||||
|
||||
$this->property7 = & $localizedObject->property7;
|
||||
|
||||
$this->property8 = & $localizedObject->property8;
|
||||
|
||||
$this->property9 = & $localizedObject->property9;
|
||||
|
||||
$this->pre = $prefixInterceptors;
|
||||
$this->post = $suffixInterceptors;',
|
||||
$constructor->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testBodyStructureWithProtectedProperties()
|
||||
{
|
||||
$constructor = new Constructor(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\ClassWithProtectedProperties'),
|
||||
$this->prefixInterceptors,
|
||||
$this->suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'$this->property0 = & $localizedObject->property0;
|
||||
|
||||
$this->property1 = & $localizedObject->property1;
|
||||
|
||||
$this->property2 = & $localizedObject->property2;
|
||||
|
||||
$this->property3 = & $localizedObject->property3;
|
||||
|
||||
$this->property4 = & $localizedObject->property4;
|
||||
|
||||
$this->property5 = & $localizedObject->property5;
|
||||
|
||||
$this->property6 = & $localizedObject->property6;
|
||||
|
||||
$this->property7 = & $localizedObject->property7;
|
||||
|
||||
$this->property8 = & $localizedObject->property8;
|
||||
|
||||
$this->property9 = & $localizedObject->property9;
|
||||
|
||||
$this->pre = $prefixInterceptors;
|
||||
$this->post = $suffixInterceptors;',
|
||||
$constructor->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testBodyStructureWithPrivateProperties()
|
||||
{
|
||||
if (! method_exists('Closure', 'bind')) {
|
||||
$this->setExpectedException('ProxyManager\Exception\UnsupportedProxiedClassException');
|
||||
}
|
||||
|
||||
$constructor = new Constructor(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\ClassWithPrivateProperties'),
|
||||
$this->prefixInterceptors,
|
||||
$this->suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'\Closure::bind(function () use ($localizedObject) {
|
||||
$this->property0 = & $localizedObject->property0;
|
||||
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke();
|
||||
|
||||
\Closure::bind(function () use ($localizedObject) {
|
||||
$this->property1 = & $localizedObject->property1;
|
||||
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke();
|
||||
|
||||
\Closure::bind(function () use ($localizedObject) {
|
||||
$this->property2 = & $localizedObject->property2;
|
||||
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke();
|
||||
|
||||
\Closure::bind(function () use ($localizedObject) {
|
||||
$this->property3 = & $localizedObject->property3;
|
||||
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke();
|
||||
|
||||
\Closure::bind(function () use ($localizedObject) {
|
||||
$this->property4 = & $localizedObject->property4;
|
||||
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke();
|
||||
|
||||
\Closure::bind(function () use ($localizedObject) {
|
||||
$this->property5 = & $localizedObject->property5;
|
||||
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke();
|
||||
|
||||
\Closure::bind(function () use ($localizedObject) {
|
||||
$this->property6 = & $localizedObject->property6;
|
||||
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke();
|
||||
|
||||
\Closure::bind(function () use ($localizedObject) {
|
||||
$this->property7 = & $localizedObject->property7;
|
||||
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke();
|
||||
|
||||
\Closure::bind(function () use ($localizedObject) {
|
||||
$this->property8 = & $localizedObject->property8;
|
||||
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke();
|
||||
|
||||
\Closure::bind(function () use ($localizedObject) {
|
||||
$this->property9 = & $localizedObject->property9;
|
||||
}, $this, \'ProxyManagerTestAsset\\\\ClassWithPrivateProperties\')->__invoke();
|
||||
|
||||
$this->pre = $prefixInterceptors;
|
||||
$this->post = $suffixInterceptors;',
|
||||
$constructor->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod
|
||||
* @group Coverage
|
||||
*/
|
||||
class InterceptedMethodTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$method = InterceptedMethod::generateMethod(
|
||||
new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod'),
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('ProxyManager\\Generator\\MethodGenerator', $method);
|
||||
|
||||
$this->assertSame('publicByReferenceParameterMethod', $method->getName());
|
||||
$this->assertCount(2, $method->getParameters());
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
strpos(
|
||||
$method->getBody(),
|
||||
'$returnValue = parent::publicByReferenceParameterMethod($param, $byRefParam);'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicClone;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicClone}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicCloneTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicClone::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicClone = new MagicClone($reflection, $prefixInterceptors, $suffixInterceptors);
|
||||
|
||||
$this->assertSame('__clone', $magicClone->getName());
|
||||
$this->assertCount(0, $magicClone->getParameters());
|
||||
$this->assertStringMatchesFormat("%a\n\n\$returnValue = null;\n\n%a", $magicClone->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicClone::__construct
|
||||
*/
|
||||
public function testBodyStructureWithInheritedMethod()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicClone = new MagicClone($reflection, $prefixInterceptors, $suffixInterceptors);
|
||||
|
||||
$this->assertSame('__clone', $magicClone->getName());
|
||||
$this->assertCount(0, $magicClone->getParameters());
|
||||
$this->assertStringMatchesFormat("%a\n\n\$returnValue = parent::__clone();\n\n%a", $magicClone->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicGet;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicGet}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicGetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicGet::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicGet = new MagicGet(
|
||||
$reflection,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame('__get', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%a$returnValue = & $accessor();%a', $magicGet->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicGet::__construct
|
||||
*/
|
||||
public function testBodyStructureWithInheritedMethod()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicGet = new MagicGet(
|
||||
$reflection,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame('__get', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%a$returnValue = & parent::__get($name);%a', $magicGet->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicIsset;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicIsset}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicIssetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicIsset::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicGet = new MagicIsset(
|
||||
$reflection,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame('__isset', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%a$returnValue = $accessor();%a', $magicGet->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicIsset::__construct
|
||||
*/
|
||||
public function testBodyStructureWithInheritedMethod()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicGet = new MagicIsset(
|
||||
$reflection,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame('__isset', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%a$returnValue = & parent::__isset($name);%a', $magicGet->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSet;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSet}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicSetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSet::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicGet = new MagicSet(
|
||||
$reflection,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame('__set', $magicGet->getName());
|
||||
$this->assertCount(2, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%a$returnValue = & $accessor();%a', $magicGet->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSet::__construct
|
||||
*/
|
||||
public function testBodyStructureWithInheritedMethod()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicGet = new MagicSet(
|
||||
$reflection,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame('__set', $magicGet->getName());
|
||||
$this->assertCount(2, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%a$returnValue = & parent::__set($name, $value);%a', $magicGet->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicSleepTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicGet = new MagicSleep(
|
||||
$reflection,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame('__sleep', $magicGet->getName());
|
||||
$this->assertEmpty($magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%a$returnValue = array_keys((array) $this);%a', $magicGet->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep::__construct
|
||||
*/
|
||||
public function testBodyStructureWithInheritedMethod()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicGet = new MagicSleep(
|
||||
$reflection,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame('__sleep', $magicGet->getName());
|
||||
$this->assertEmpty($magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%a$returnValue = & parent::__sleep();%a', $magicGet->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicUnset;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicUnset}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicUnsetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicUnset::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicGet = new MagicUnset(
|
||||
$reflection,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame('__unset', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%a$returnValue = $accessor();%a', $magicGet->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicUnset::__construct
|
||||
*/
|
||||
public function testBodyStructureWithInheritedMethod()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicGet = new MagicUnset(
|
||||
$reflection,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame('__unset', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%a$returnValue = & parent::__unset($name);%a', $magicGet->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class InterceptorGeneratorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator
|
||||
*/
|
||||
public function testInterceptorGenerator()
|
||||
{
|
||||
$method = $this->getMock('ProxyManager\\Generator\\MethodGenerator');
|
||||
$bar = $this->getMock('ProxyManager\\Generator\\ParameterGenerator');
|
||||
$baz = $this->getMock('ProxyManager\\Generator\\ParameterGenerator');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$bar->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$baz->expects($this->any())->method('getName')->will($this->returnValue('baz'));
|
||||
$method->expects($this->any())->method('getName')->will($this->returnValue('fooMethod'));
|
||||
$method->expects($this->any())->method('getParameters')->will($this->returnValue(array($bar, $baz)));
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$body = InterceptorGenerator::createInterceptedMethodBody(
|
||||
'$returnValue = "foo";',
|
||||
$method,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'if (isset($this->pre[\'fooMethod\'])) {' . "\n"
|
||||
. ' $returnEarly = false;' . "\n"
|
||||
. ' $prefixReturnValue = $this->pre[\'fooMethod\']->__invoke($this, $this, \'fooMethod\', '
|
||||
. 'array(\'bar\' => $bar, \'baz\' => $baz), $returnEarly);' . "\n\n"
|
||||
. ' if ($returnEarly) {' . "\n"
|
||||
. ' return $prefixReturnValue;' . "\n"
|
||||
. ' }' . "\n"
|
||||
. '}' . "\n\n"
|
||||
. '$returnValue = "foo";' . "\n\n"
|
||||
. 'if (isset($this->post[\'fooMethod\'])) {' . "\n"
|
||||
. ' $returnEarly = false;' . "\n"
|
||||
. ' $suffixReturnValue = $this->post[\'fooMethod\']->__invoke($this, $this, \'fooMethod\', '
|
||||
. 'array(\'bar\' => $bar, \'baz\' => $baz), $returnValue, $returnEarly);' . "\n\n"
|
||||
. ' if ($returnEarly) {' . "\n"
|
||||
. ' return $suffixReturnValue;' . "\n"
|
||||
. ' }' . "\n"
|
||||
. '}' . "\n\n"
|
||||
. 'return $returnValue;',
|
||||
$body
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator
|
||||
* @group Coverage
|
||||
*/
|
||||
class AccessInterceptorScopeLocalizerTest extends AbstractProxyGeneratorTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTestedImplementations
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function testGeneratesValidCode($className)
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($className);
|
||||
|
||||
if ($reflectionClass->isInterface()) {
|
||||
// @todo interfaces *may* be proxied by deferring property localization to the constructor (no hardcoding)
|
||||
$this->setExpectedException('ProxyManager\Exception\InvalidProxiedClassException');
|
||||
|
||||
return parent::testGeneratesValidCode($className);
|
||||
}
|
||||
|
||||
if ((! method_exists('Closure', 'bind'))
|
||||
&& $reflectionClass->getProperties(ReflectionProperty::IS_PRIVATE)
|
||||
) {
|
||||
$this->setExpectedException('ProxyManager\Exception\UnsupportedProxiedClassException');
|
||||
}
|
||||
|
||||
return parent::testGeneratesValidCode($className);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getProxyGenerator()
|
||||
{
|
||||
return new AccessInterceptorScopeLocalizerGenerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedImplementedInterfaces()
|
||||
{
|
||||
return array('ProxyManager\\Proxy\\AccessInterceptorInterface');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoading\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class ConstructorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$reflection = new ReflectionClass(
|
||||
'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties'
|
||||
);
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$constructor = new Constructor($reflection, $initializer);
|
||||
|
||||
$this->assertSame('__construct', $constructor->getName());
|
||||
$this->assertCount(1, $constructor->getParameters());
|
||||
$this->assertSame("unset(\$this->bar, \$this->baz);\n\n\$this->foo = \$initializer;", $constructor->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testBodyStructureWithoutPublicProperties()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$constructor = new Constructor(new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'), $initializer);
|
||||
|
||||
$this->assertSame('__construct', $constructor->getName());
|
||||
$this->assertCount(1, $constructor->getParameters());
|
||||
$this->assertSame("\$this->foo = \$initializer;", $constructor->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class ConstructorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$reflection = new ReflectionClass(
|
||||
'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties'
|
||||
);
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$constructor = new Constructor($reflection, $valueHolder, $prefixInterceptors, $suffixInterceptors);
|
||||
|
||||
$this->assertSame('__construct', $constructor->getName());
|
||||
$this->assertCount(3, $constructor->getParameters());
|
||||
$this->assertSame(
|
||||
"unset(\$this->bar, \$this->baz);\n\n\$this->foo = \$wrappedObject;\n\$this->pre = \$prefixInterceptors;"
|
||||
. "\n\$this->post = \$suffixInterceptors;",
|
||||
$constructor->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testBodyStructureWithoutPublicProperties()
|
||||
{
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$constructor = new Constructor($reflection, $valueHolder, $prefixInterceptors, $suffixInterceptors);
|
||||
|
||||
$this->assertSame('__construct', $constructor->getName());
|
||||
$this->assertCount(3, $constructor->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo = \$wrappedObject;\n\$this->pre = \$prefixInterceptors;"
|
||||
. "\n\$this->post = \$suffixInterceptors;",
|
||||
$constructor->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\InterceptedMethod;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\InterceptedMethod}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\InterceptedMethod::generateMethod
|
||||
* @group Coverage
|
||||
*/
|
||||
class InterceptedMethodTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$method = InterceptedMethod::generateMethod(
|
||||
new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod'),
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('ProxyManager\\Generator\\MethodGenerator', $method);
|
||||
|
||||
$this->assertSame('publicByReferenceParameterMethod', $method->getName());
|
||||
$this->assertCount(2, $method->getParameters());
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
strpos(
|
||||
$method->getBody(),
|
||||
'$returnValue = $this->foo->publicByReferenceParameterMethod($param, $byRefParam);'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicCloneTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$magicClone = new MagicClone($reflection, $valueHolder, $prefixInterceptors, $suffixInterceptors);
|
||||
|
||||
$this->assertSame('__clone', $magicClone->getName());
|
||||
$this->assertCount(0, $magicClone->getParameters());
|
||||
$this->assertSame(
|
||||
'$this->bar = clone $this->bar;' . "\n\n"
|
||||
. 'foreach ($this->pre as $key => $value) {' . "\n"
|
||||
. ' $this->pre[$key] = clone $value;' . "\n"
|
||||
. '}' . "\n\n"
|
||||
. 'foreach ($this->post as $key => $value) {' . "\n"
|
||||
. ' $this->post[$key] = clone $value;' . "\n"
|
||||
. '}',
|
||||
$magicClone->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicGet;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicGet}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicGetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicGet::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
$publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
|
||||
$magicGet = new MagicGet(
|
||||
$reflection,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors,
|
||||
$publicProperties
|
||||
);
|
||||
|
||||
$this->assertSame('__get', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat('%A$returnValue = & $this->bar->$name;%A', $magicGet->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicIsset;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicIsset}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicIssetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicIsset::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
$publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
|
||||
$magicIsset = new MagicIsset(
|
||||
$reflection,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors,
|
||||
$publicProperties
|
||||
);
|
||||
|
||||
$this->assertSame('__isset', $magicIsset->getName());
|
||||
$this->assertCount(1, $magicIsset->getParameters());
|
||||
$this->assertGreaterThan(0, strpos($magicIsset->getBody(), '$returnValue = isset($this->bar->$name);'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicSet;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicSet}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicSetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicSet::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
$publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
|
||||
$magicSet = new MagicSet(
|
||||
$reflection,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors,
|
||||
$publicProperties
|
||||
);
|
||||
|
||||
$this->assertSame('__set', $magicSet->getName());
|
||||
$this->assertCount(2, $magicSet->getParameters());
|
||||
$this->assertGreaterThan(0, strpos($magicSet->getBody(), '$returnValue = ($this->bar->$name = $value);'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicUnset;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicUnset}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicUnsetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicUnset::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
$publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
|
||||
$magicUnset = new MagicUnset(
|
||||
$reflection,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors,
|
||||
$publicProperties
|
||||
);
|
||||
|
||||
$this->assertSame('__unset', $magicUnset->getName());
|
||||
$this->assertCount(1, $magicUnset->getParameters());
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
strpos($magicUnset->getBody(), 'unset($this->bar->$name);')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util\InterceptorGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class InterceptorGeneratorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util\InterceptorGenerator
|
||||
*/
|
||||
public function testInterceptorGenerator()
|
||||
{
|
||||
$method = $this->getMock('ProxyManager\\Generator\\MethodGenerator');
|
||||
$bar = $this->getMock('ProxyManager\\Generator\\ParameterGenerator');
|
||||
$baz = $this->getMock('ProxyManager\\Generator\\ParameterGenerator');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$bar->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$baz->expects($this->any())->method('getName')->will($this->returnValue('baz'));
|
||||
$method->expects($this->any())->method('getName')->will($this->returnValue('fooMethod'));
|
||||
$method->expects($this->any())->method('getParameters')->will($this->returnValue(array($bar, $baz)));
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
|
||||
$suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
|
||||
|
||||
$body = InterceptorGenerator::createInterceptedMethodBody(
|
||||
'$returnValue = "foo";',
|
||||
$method,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'if (isset($this->pre[\'fooMethod\'])) {' . "\n"
|
||||
. ' $returnEarly = false;' . "\n"
|
||||
. ' $prefixReturnValue = $this->pre[\'fooMethod\']->__invoke($this, $this->foo, \'fooMethod\', '
|
||||
. 'array(\'bar\' => $bar, \'baz\' => $baz), $returnEarly);' . "\n\n"
|
||||
. ' if ($returnEarly) {' . "\n"
|
||||
. ' return $prefixReturnValue;' . "\n"
|
||||
. ' }' . "\n"
|
||||
. '}' . "\n\n"
|
||||
. '$returnValue = "foo";' . "\n\n"
|
||||
. 'if (isset($this->post[\'fooMethod\'])) {' . "\n"
|
||||
. ' $returnEarly = false;' . "\n"
|
||||
. ' $suffixReturnValue = $this->post[\'fooMethod\']->__invoke($this, $this->foo, \'fooMethod\', '
|
||||
. 'array(\'bar\' => $bar, \'baz\' => $baz), $returnValue, $returnEarly);' . "\n\n"
|
||||
. ' if ($returnEarly) {' . "\n"
|
||||
. ' return $suffixReturnValue;' . "\n"
|
||||
. ' }' . "\n"
|
||||
. '}' . "\n\n"
|
||||
. 'return $returnValue;',
|
||||
$body
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator
|
||||
* @group Coverage
|
||||
*/
|
||||
class AccessInterceptorValueHolderTest extends AbstractProxyGeneratorTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getProxyGenerator()
|
||||
{
|
||||
return new AccessInterceptorValueHolderGenerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedImplementedInterfaces()
|
||||
{
|
||||
return array(
|
||||
'ProxyManager\\Proxy\\AccessInterceptorInterface',
|
||||
'ProxyManager\\Proxy\\ValueHolderInterface',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\Assertion;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @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'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\CallInitializer;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\CallInitializer}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class CallInitializerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\CallInitializer::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$propertiesDefaults = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$initializationTracker = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('init'));
|
||||
$propertiesDefaults->expects($this->any())->method('getName')->will($this->returnValue('props'));
|
||||
$initializationTracker->expects($this->any())->method('getName')->will($this->returnValue('track'));
|
||||
|
||||
$callInitializer = new CallInitializer($initializer, $propertiesDefaults, $initializationTracker);
|
||||
|
||||
$this->assertStringMatchesFormat(
|
||||
'%Aif ($this->track || ! $this->init) {%areturn;%a}%a'
|
||||
. '$this->track = true;%a'
|
||||
. 'foreach (self::$props as $key => $default) {%a'
|
||||
. '$this->$key = $default;%a'
|
||||
. '$this->init->__invoke(%a);%a'
|
||||
. '$this->track = false;',
|
||||
$callInitializer->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\GetProxyInitializer;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\GetProxyInitializer}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class GetProxyInitializerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\GetProxyInitializer::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$getter = new GetProxyInitializer($initializer);
|
||||
|
||||
$this->assertSame('getProxyInitializer', $getter->getName());
|
||||
$this->assertCount(0, $getter->getParameters());
|
||||
$this->assertSame('return $this->foo;', $getter->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\InitializeProxy;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\InitializeProxy}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class InitializeProxyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\InitializeProxy::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$initCall = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$initCall->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$initializeProxy = new InitializeProxy($initializer, $initCall);
|
||||
|
||||
$this->assertSame('initializeProxy', $initializeProxy->getName());
|
||||
$this->assertCount(0, $initializeProxy->getParameters());
|
||||
$this->assertSame(
|
||||
'return $this->foo && $this->bar(\'initializeProxy\', array());',
|
||||
$initializeProxy->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\IsProxyInitialized;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\IsProxyInitialized}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class IsProxyInitializedTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\IsProxyInitialized::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$isProxyInitialized = new IsProxyInitialized($initializer);
|
||||
|
||||
$this->assertSame('isProxyInitialized', $isProxyInitialized->getName());
|
||||
$this->assertCount(0, $isProxyInitialized->getParameters());
|
||||
$this->assertSame('return ! $this->foo;', $isProxyInitialized->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\LazyLoadingMethodInterceptor;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\LazyLoadingMethodInterceptor}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class LazyLoadingMethodInterceptorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\LazyLoadingMethodInterceptor
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$initCall = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$initCall->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$reflection = new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod');
|
||||
$method = LazyLoadingMethodInterceptor::generateMethod($reflection, $initializer, $initCall);
|
||||
|
||||
$this->assertSame('publicByReferenceParameterMethod', $method->getName());
|
||||
$this->assertCount(2, $method->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->bar('publicByReferenceParameterMethod', "
|
||||
. "array('param' => \$param, 'byRefParam' => \$byRefParam));\n\n"
|
||||
. "return parent::publicByReferenceParameterMethod(\$param, \$byRefParam);",
|
||||
$method->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\LazyLoadingMethodInterceptor
|
||||
*/
|
||||
public function testBodyStructureWithoutParameters()
|
||||
{
|
||||
$reflectionMethod = new MethodReflection(__CLASS__, 'testBodyStructureWithoutParameters');
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$initCall = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$initCall->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$method = LazyLoadingMethodInterceptor::generateMethod($reflectionMethod, $initializer, $initCall);
|
||||
|
||||
$this->assertSame('testBodyStructureWithoutParameters', $method->getName());
|
||||
$this->assertCount(0, $method->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->bar('testBodyStructureWithoutParameters', array());\n\n"
|
||||
. "return parent::testBodyStructureWithoutParameters();",
|
||||
$method->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicClone;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicClone}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicCloneTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicClone::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$initCall = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$initCall->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$magicClone = new MagicClone($reflection, $initializer, $initCall);
|
||||
|
||||
$this->assertSame('__clone', $magicClone->getName());
|
||||
$this->assertCount(0, $magicClone->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->bar('__clone', array());",
|
||||
$magicClone->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicGetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $initializer;
|
||||
|
||||
/**
|
||||
* @var \Zend\Code\Generator\MethodGenerator|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $initMethod;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $publicProperties;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$this->initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
$this->publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz'));
|
||||
$this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
$this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$magicGet = new MagicGet($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__get', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->baz('__get', array('name' => \$name));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return \$this->\$name;\n}\n\n"
|
||||
. "%a",
|
||||
$magicGet->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet::__construct
|
||||
*/
|
||||
public function testBodyStructureWithPublicProperties()
|
||||
{
|
||||
$reflection = new ReflectionClass(
|
||||
'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties'
|
||||
);
|
||||
|
||||
$magicGet = new MagicGet($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__get', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->baz('__get', array('name' => \$name));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return \$this->\$name;\n}\n\n"
|
||||
. "%a",
|
||||
$magicGet->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet::__construct
|
||||
*/
|
||||
public function testBodyStructureWithOverriddenMagicGet()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$magicGet = new MagicGet($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__get', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->baz('__get', array('name' => \$name));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return \$this->\$name;\n}\n\n"
|
||||
. "return parent::__get(\$name);",
|
||||
$magicGet->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicIssetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $initializer;
|
||||
|
||||
/**
|
||||
* @var \Zend\Code\Generator\MethodGenerator|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $initMethod;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $publicProperties;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$this->initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
$this->publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz'));
|
||||
$this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
$this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$magicIsset = new MagicIsset($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__isset', $magicIsset->getName());
|
||||
$this->assertCount(1, $magicIsset->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->baz('__isset', array('name' => \$name));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return isset(\$this->\$name);\n}\n\n"
|
||||
. "%areturn %s;",
|
||||
$magicIsset->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset::__construct
|
||||
*/
|
||||
public function testBodyStructureWithPublicProperties()
|
||||
{
|
||||
$reflection = new ReflectionClass(
|
||||
'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties'
|
||||
);
|
||||
$magicIsset = new MagicIsset($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__isset', $magicIsset->getName());
|
||||
$this->assertCount(1, $magicIsset->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->baz('__isset', array('name' => \$name));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return isset(\$this->\$name);\n}\n\n"
|
||||
. "%areturn %s;",
|
||||
$magicIsset->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset::__construct
|
||||
*/
|
||||
public function testBodyStructureWithOverriddenMagicGet()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$magicIsset = new MagicIsset($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__isset', $magicIsset->getName());
|
||||
$this->assertCount(1, $magicIsset->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->baz('__isset', array('name' => \$name));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return isset(\$this->\$name);\n}\n\n"
|
||||
. "return parent::__isset(\$name);",
|
||||
$magicIsset->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicSetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $initializer;
|
||||
|
||||
/**
|
||||
* @var \Zend\Code\Generator\MethodGenerator|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $initMethod;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $publicProperties;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$this->initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
$this->publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz'));
|
||||
$this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
$this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$magicSet = new MagicSet($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__set', $magicSet->getName());
|
||||
$this->assertCount(2, $magicSet->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->baz('__set', array('name' => \$name, 'value' => \$value));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return (\$this->\$name = \$value);\n}\n\n"
|
||||
. "%areturn %s;",
|
||||
$magicSet->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet::__construct
|
||||
*/
|
||||
public function testBodyStructureWithPublicProperties()
|
||||
{
|
||||
$reflection = new ReflectionClass(
|
||||
'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties'
|
||||
);
|
||||
|
||||
$magicSet = new MagicSet($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__set', $magicSet->getName());
|
||||
$this->assertCount(2, $magicSet->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->baz('__set', array('name' => \$name, 'value' => \$value));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return (\$this->\$name = \$value);\n}\n\n"
|
||||
. "%areturn %s;",
|
||||
$magicSet->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet::__construct
|
||||
*/
|
||||
public function testBodyStructureWithOverriddenMagicGet()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$magicSet = new MagicSet($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__set', $magicSet->getName());
|
||||
$this->assertCount(2, $magicSet->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->baz('__set', array('name' => \$name, 'value' => \$value));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return (\$this->\$name = \$value);\n}\n\n"
|
||||
. "return parent::__set(\$name, \$value);",
|
||||
$magicSet->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSleep;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSleep}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicSleepTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSleep::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$initMethod->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$magicSleep = new MagicSleep($reflection, $initializer, $initMethod);
|
||||
|
||||
$this->assertSame('__sleep', $magicSleep->getName());
|
||||
$this->assertCount(0, $magicSleep->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->bar('__sleep', array());"
|
||||
. "\n\nreturn array_keys((array) \$this);",
|
||||
$magicSleep->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicUnsetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $initializer;
|
||||
|
||||
/**
|
||||
* @var \Zend\Code\Generator\MethodGenerator|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $initMethod;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $publicProperties;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$this->initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
$this->publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz'));
|
||||
$this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
$this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$magicIsset = new MagicUnset($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__unset', $magicIsset->getName());
|
||||
$this->assertCount(1, $magicIsset->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->baz('__unset', array('name' => \$name));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n unset(\$this->\$name);\n\n return;\n}"
|
||||
. "%areturn %s;",
|
||||
$magicIsset->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset::__construct
|
||||
*/
|
||||
public function testBodyStructureWithPublicProperties()
|
||||
{
|
||||
$reflection = new ReflectionClass(
|
||||
'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties'
|
||||
);
|
||||
|
||||
$magicIsset = new MagicUnset($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__unset', $magicIsset->getName());
|
||||
$this->assertCount(1, $magicIsset->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->baz('__unset', array('name' => \$name));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n unset(\$this->\$name);\n\n return;\n}"
|
||||
. "%areturn %s;",
|
||||
$magicIsset->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset::__construct
|
||||
*/
|
||||
public function testBodyStructureWithOverriddenMagicGet()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$magicIsset = new MagicUnset($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
|
||||
|
||||
$this->assertSame('__unset', $magicIsset->getName());
|
||||
$this->assertCount(1, $magicIsset->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->baz('__unset', array('name' => \$name));\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n unset(\$this->\$name);\n\n return;\n}\n\n"
|
||||
. "return parent::__unset(\$name);",
|
||||
$magicIsset->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\SetProxyInitializer;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\SetProxyInitializer}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class SetProxyInitializerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\SetProxyInitializer::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$setter = new SetProxyInitializer($initializer);
|
||||
$parameters = $setter->getParameters();
|
||||
|
||||
$this->assertSame('setProxyInitializer', $setter->getName());
|
||||
$this->assertCount(1, $parameters);
|
||||
|
||||
/* @var $initializer \ProxyManager\Generator\ParameterGenerator */
|
||||
$initializer = array_shift($parameters);
|
||||
|
||||
$this->assertInstanceOf('ProxyManager\\Generator\\ParameterGenerator', $initializer);
|
||||
$this->assertSame('initializer', $initializer->getName());
|
||||
$this->assertSame('$this->foo = $initializer;', $setter->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\PropertyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializationTracker;
|
||||
use ProxyManagerTest\ProxyGenerator\PropertyGenerator\AbstractUniquePropertyNameTest;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializationTracker}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializationTracker
|
||||
* @group Coverage
|
||||
*/
|
||||
class InitializationTrackerTest extends AbstractUniquePropertyNameTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function createProperty()
|
||||
{
|
||||
return new InitializationTracker();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\PropertyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializerProperty;
|
||||
use ProxyManagerTest\ProxyGenerator\PropertyGenerator\AbstractUniquePropertyNameTest;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializerProperty}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializerProperty
|
||||
* @group Coverage
|
||||
*/
|
||||
class InitializerPropertyTest extends AbstractUniquePropertyNameTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function createProperty()
|
||||
{
|
||||
return new InitializerProperty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator
|
||||
* @group Coverage
|
||||
*/
|
||||
class LazyLoadingGhostGeneratorTest extends AbstractProxyGeneratorTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getProxyGenerator()
|
||||
{
|
||||
return new LazyLoadingGhostGenerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedImplementedInterfaces()
|
||||
{
|
||||
return array('ProxyManager\\Proxy\\GhostObjectInterface');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\GetProxyInitializer;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\GetProxyInitializer}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class GetProxyInitializerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\GetProxyInitializer::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$getter = new GetProxyInitializer($initializer);
|
||||
|
||||
$this->assertSame('getProxyInitializer', $getter->getName());
|
||||
$this->assertCount(0, $getter->getParameters());
|
||||
$this->assertSame('return $this->foo;', $getter->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class InitializeProxyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$initializeProxy = new InitializeProxy($initializer, $valueHolder);
|
||||
|
||||
$this->assertSame('initializeProxy', $initializeProxy->getName());
|
||||
$this->assertCount(0, $initializeProxy->getParameters());
|
||||
$this->assertSame(
|
||||
'return $this->foo && $this->foo->__invoke($this->bar, $this, \'initializeProxy\', array(), $this->foo);',
|
||||
$initializeProxy->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\IsProxyInitialized;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\IsProxyInitialized}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class IsProxyInitializedTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\IsProxyInitialized::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$isProxyInitialized = new IsProxyInitialized($valueHolder);
|
||||
|
||||
$this->assertSame('isProxyInitialized', $isProxyInitialized->getName());
|
||||
$this->assertCount(0, $isProxyInitialized->getParameters());
|
||||
$this->assertSame('return null !== $this->bar;', $isProxyInitialized->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class LazyLoadingMethodInterceptorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$reflection = new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod');
|
||||
$method = LazyLoadingMethodInterceptor::generateMethod($reflection, $initializer, $valueHolder);
|
||||
|
||||
$this->assertSame('publicByReferenceParameterMethod', $method->getName());
|
||||
$this->assertCount(2, $method->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, 'publicByReferenceParameterMethod', "
|
||||
. "array('param' => \$param, 'byRefParam' => \$byRefParam), \$this->foo);\n\n"
|
||||
. "return \$this->bar->publicByReferenceParameterMethod(\$param, \$byRefParam);",
|
||||
$method->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor
|
||||
*/
|
||||
public function testBodyStructureWithoutParameters()
|
||||
{
|
||||
$reflectionMethod = new MethodReflection(__CLASS__, 'testBodyStructureWithoutParameters');
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$method = LazyLoadingMethodInterceptor::generateMethod($reflectionMethod, $initializer, $valueHolder);
|
||||
|
||||
$this->assertSame('testBodyStructureWithoutParameters', $method->getName());
|
||||
$this->assertCount(0, $method->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, "
|
||||
. "'testBodyStructureWithoutParameters', array(), \$this->foo);\n\n"
|
||||
. "return \$this->bar->testBodyStructureWithoutParameters();",
|
||||
$method->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicClone;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicClone}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicCloneTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicClone::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$magicClone = new MagicClone($reflection, $initializer, $valueHolder);
|
||||
|
||||
$this->assertSame('__clone', $magicClone->getName());
|
||||
$this->assertCount(0, $magicClone->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, "
|
||||
. "'__clone', array(), \$this->foo);\n\n\$this->bar = clone \$this->bar;",
|
||||
$magicClone->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicGet;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicGet}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicGetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicGet::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
$publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$magicGet = new MagicGet($reflection, $initializer, $valueHolder, $publicProperties);
|
||||
|
||||
$this->assertSame('__get', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, '__get', array('name' => \$name)"
|
||||
. ", \$this->foo);\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return \$this->bar->\$name;\n}"
|
||||
. "%areturn %s;",
|
||||
$magicGet->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicIsset;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicIsset}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicIssetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicIsset::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
$publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$magicIsset = new MagicIsset($reflection, $initializer, $valueHolder, $publicProperties);
|
||||
|
||||
$this->assertSame('__isset', $magicIsset->getName());
|
||||
$this->assertCount(1, $magicIsset->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, '__isset', array('name' => \$name)"
|
||||
. ", \$this->foo);\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return isset(\$this->bar->\$name);\n}"
|
||||
. "%areturn %s;",
|
||||
$magicIsset->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSet;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSet}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicSetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSet::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
$publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$magicSet = new MagicSet($reflection, $initializer, $valueHolder, $publicProperties);
|
||||
|
||||
$this->assertSame('__set', $magicSet->getName());
|
||||
$this->assertCount(2, $magicSet->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, "
|
||||
. "'__set', array('name' => \$name, 'value' => \$value), \$this->foo);\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n return (\$this->bar->\$name = \$value);\n}"
|
||||
. "%areturn %s;",
|
||||
$magicSet->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSleep;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSleep}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicSleepTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSleep::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$magicSleep = new MagicSleep($reflection, $initializer, $valueHolder);
|
||||
|
||||
$this->assertSame('__sleep', $magicSleep->getName());
|
||||
$this->assertCount(0, $magicSleep->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, '__sleep', array(), \$this->foo);"
|
||||
. "\n\nreturn array('bar');",
|
||||
$magicSleep->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicUnset;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicUnset}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicUnsetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicUnset::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$publicProperties = $this
|
||||
->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
$publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
|
||||
$publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$magicIsset = new MagicUnset($reflection, $initializer, $valueHolder, $publicProperties);
|
||||
|
||||
$this->assertSame('__unset', $magicIsset->getName());
|
||||
$this->assertCount(1, $magicIsset->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
"\$this->foo && \$this->foo->__invoke(\$this->bar, \$this, '__unset', array('name' => \$name)"
|
||||
. ", \$this->foo);\n\n"
|
||||
. "if (isset(self::\$bar[\$name])) {\n unset(\$this->bar->\$name);\n\n return;\n}"
|
||||
. "%areturn %s;",
|
||||
$magicIsset->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\SetProxyInitializer;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\SetProxyInitializer}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class SetProxyInitializerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\SetProxyInitializer::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$setter = new SetProxyInitializer($initializer);
|
||||
$parameters = $setter->getParameters();
|
||||
|
||||
$this->assertSame('setProxyInitializer', $setter->getName());
|
||||
$this->assertCount(1, $parameters);
|
||||
|
||||
/* @var $initializer \ProxyManager\Generator\ParameterGenerator */
|
||||
$initializer = array_shift($parameters);
|
||||
|
||||
$this->assertInstanceOf('ProxyManager\\Generator\\ParameterGenerator', $initializer);
|
||||
$this->assertSame('initializer', $initializer->getName());
|
||||
$this->assertSame('$this->foo = $initializer;', $setter->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\InitializerProperty;
|
||||
use ProxyManagerTest\ProxyGenerator\PropertyGenerator\AbstractUniquePropertyNameTest;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\InitializerProperty}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\InitializerProperty
|
||||
* @group Coverage
|
||||
*/
|
||||
class InitializerPropertyTest extends AbstractUniquePropertyNameTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function createProperty()
|
||||
{
|
||||
return new InitializerProperty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty;
|
||||
use ProxyManagerTest\ProxyGenerator\PropertyGenerator\AbstractUniquePropertyNameTest;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty
|
||||
* @group Coverage
|
||||
*/
|
||||
class ValueHolderPropertyTest extends AbstractUniquePropertyNameTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function createProperty()
|
||||
{
|
||||
return new ValueHolderProperty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator
|
||||
* @group Coverage
|
||||
*/
|
||||
class LazyLoadingValueHolderGeneratorTest extends AbstractProxyGeneratorTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getProxyGenerator()
|
||||
{
|
||||
return new LazyLoadingValueHolderGenerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedImplementedInterfaces()
|
||||
{
|
||||
return array('ProxyManager\\Proxy\\VirtualProxyInterface');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\NullObject\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\Constructor;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\Constructor}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class ConstructorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMixedProperties');
|
||||
$constructor = new Constructor($reflection);
|
||||
|
||||
$this->assertSame('__construct', $constructor->getName());
|
||||
$this->assertCount(0, $constructor->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->publicProperty0 = null;\n\$this->publicProperty1 = null;\n\$this->publicProperty2 = null;",
|
||||
$constructor->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testBodyStructureWithoutPublicProperties()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithPrivateProperties');
|
||||
$constructor = new Constructor($reflection);
|
||||
|
||||
$this->assertSame('__construct', $constructor->getName());
|
||||
$this->assertCount(0, $constructor->getParameters());
|
||||
$body = $constructor->getBody();
|
||||
$this->assertTrue(empty($body));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\NullObject\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class NullObjectMethodInterceptorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod');
|
||||
$method = NullObjectMethodInterceptor::generateMethod($reflection);
|
||||
|
||||
$this->assertSame('publicByReferenceParameterMethod', $method->getName());
|
||||
$this->assertCount(2, $method->getParameters());
|
||||
$this->assertSame("", $method->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor
|
||||
*/
|
||||
public function testBodyStructureWithoutParameters()
|
||||
{
|
||||
$reflectionMethod = new MethodReflection(__CLASS__, 'testBodyStructureWithoutParameters');
|
||||
|
||||
$method = NullObjectMethodInterceptor::generateMethod($reflectionMethod);
|
||||
|
||||
$this->assertSame('testBodyStructureWithoutParameters', $method->getName());
|
||||
$this->assertCount(0, $method->getParameters());
|
||||
$this->assertSame("", $method->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor
|
||||
*/
|
||||
public function testBodyStructureWithoutByRefReturn()
|
||||
{
|
||||
$reflectionMethod = new MethodReflection('ProxyManagerTestAsset\BaseClass', 'publicByReferenceMethod');
|
||||
|
||||
$method = NullObjectMethodInterceptor::generateMethod($reflectionMethod);
|
||||
|
||||
$this->assertSame('publicByReferenceMethod', $method->getName());
|
||||
$this->assertCount(0, $method->getParameters());
|
||||
$this->assertStringMatchesFormat("\$ref%s = null;\nreturn \$ref%s;", $method->getBody());
|
||||
}
|
||||
}
|
||||
113
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php
vendored
Normal file
113
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/NullObjectGeneratorTest.php
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ProxyManager\ProxyGenerator\NullObjectGenerator;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\NullObjectGenerator}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\NullObjectGenerator
|
||||
* @group Coverage
|
||||
*/
|
||||
class NullObjectGeneratorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTestedImplementations
|
||||
*
|
||||
* Verifies that generated code is valid and implements expected interfaces
|
||||
*/
|
||||
public function testGeneratesValidCode($className)
|
||||
{
|
||||
$generator = $this->getProxyGenerator();
|
||||
$generatedClassName = UniqueIdentifierGenerator::getIdentifier('AbstractProxyGeneratorTest');
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$originalClass = new ReflectionClass($className);
|
||||
$generatorStrategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate($originalClass, $generatedClass);
|
||||
$generatorStrategy->generate($generatedClass);
|
||||
|
||||
$generatedReflection = new ReflectionClass($generatedClassName);
|
||||
|
||||
if ($originalClass->isInterface()) {
|
||||
$this->assertTrue($generatedReflection->implementsInterface($className));
|
||||
}
|
||||
|
||||
$this->assertSame($generatedClassName, $generatedReflection->getName());
|
||||
|
||||
foreach ($this->getExpectedImplementedInterfaces() as $interface) {
|
||||
$this->assertTrue($generatedReflection->implementsInterface($interface));
|
||||
}
|
||||
|
||||
$proxyGenerated = new $generatedClassName();
|
||||
|
||||
foreach ($generatedReflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
|
||||
$this->assertNull($proxyGenerated->$property);
|
||||
}
|
||||
|
||||
/** @var \ReflectionMethod $method */
|
||||
foreach ($generatedReflection->getMethods(ReflectionProperty::IS_PUBLIC) as $method) {
|
||||
if ($method->getNumberOfParameters() == 0) {
|
||||
$this->assertNull(call_user_func(array($proxyGenerated, $method->getName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getProxyGenerator()
|
||||
{
|
||||
return new NullObjectGenerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedImplementedInterfaces()
|
||||
{
|
||||
return array(
|
||||
'ProxyManager\\Proxy\\NullObjectInterface',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTestedImplementations()
|
||||
{
|
||||
return array(
|
||||
array('ProxyManagerTestAsset\\BaseClass'),
|
||||
array('ProxyManagerTestAsset\\ClassWithMagicMethods'),
|
||||
array('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'),
|
||||
array('ProxyManagerTestAsset\\ClassWithMixedProperties'),
|
||||
array('ProxyManagerTestAsset\\BaseInterface'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\PropertyGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Base test for unique property names
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
abstract class AbstractUniquePropertyNameTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Verifies that a given property name is unique across two different instantiations of the property
|
||||
*/
|
||||
public function testUniqueProperty()
|
||||
{
|
||||
$property1 = $this->createProperty();
|
||||
$property2 = $this->createProperty();
|
||||
|
||||
$this->assertSame($property1->getName(), $property1->getName());
|
||||
$this->assertNotEquals($property1->getName(), $property2->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Zend\Code\Generator\PropertyGenerator
|
||||
*/
|
||||
abstract protected function createProperty();
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesDefaults;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesDefaults}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesDefaults
|
||||
* @group Coverage
|
||||
*/
|
||||
class PublicPropertiesDefaultsTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEmptyClass()
|
||||
{
|
||||
$publicProperties = new PublicPropertiesDefaults(new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'));
|
||||
|
||||
$this->assertInternalType('array', $publicProperties->getDefaultValue()->getValue());
|
||||
$this->assertEmpty($publicProperties->getDefaultValue()->getValue());
|
||||
$this->assertTrue($publicProperties->isStatic());
|
||||
$this->assertSame(PublicPropertiesDefaults::VISIBILITY_PRIVATE, $publicProperties->getVisibility());
|
||||
}
|
||||
|
||||
public function testClassWithPublicProperties()
|
||||
{
|
||||
$publicProperties = new PublicPropertiesDefaults(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\ClassWithPublicProperties')
|
||||
);
|
||||
|
||||
$this->assertInternalType('array', $publicProperties->getDefaultValue()->getValue());
|
||||
$this->assertCount(10, $publicProperties->getDefaultValue()->getValue());
|
||||
$this->assertTrue($publicProperties->isStatic());
|
||||
$this->assertSame(PublicPropertiesDefaults::VISIBILITY_PRIVATE, $publicProperties->getVisibility());
|
||||
}
|
||||
|
||||
public function testBaseClass()
|
||||
{
|
||||
$publicProperties = new PublicPropertiesDefaults(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\BaseClass')
|
||||
);
|
||||
|
||||
$this->assertInternalType('array', $publicProperties->getDefaultValue()->getValue());
|
||||
$this->assertSame(
|
||||
array('publicProperty' => 'publicPropertyDefault'),
|
||||
$publicProperties->getDefaultValue()->getValue()
|
||||
);
|
||||
$this->assertTrue($publicProperties->isStatic());
|
||||
$this->assertSame(PublicPropertiesDefaults::VISIBILITY_PRIVATE, $publicProperties->getVisibility());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap
|
||||
* @group Coverage
|
||||
*/
|
||||
class PublicPropertiesMapTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEmptyClass()
|
||||
{
|
||||
$publicProperties = new PublicPropertiesMap(new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'));
|
||||
|
||||
$this->assertInternalType('array', $publicProperties->getDefaultValue()->getValue());
|
||||
$this->assertEmpty($publicProperties->getDefaultValue()->getValue());
|
||||
$this->assertTrue($publicProperties->isStatic());
|
||||
$this->assertSame('private', $publicProperties->getVisibility());
|
||||
$this->assertTrue($publicProperties->isEmpty());
|
||||
}
|
||||
|
||||
public function testClassWithPublicProperties()
|
||||
{
|
||||
$publicProperties = new PublicPropertiesMap(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\ClassWithPublicProperties')
|
||||
);
|
||||
|
||||
$this->assertInternalType('array', $publicProperties->getDefaultValue()->getValue());
|
||||
$this->assertCount(10, $publicProperties->getDefaultValue()->getValue());
|
||||
$this->assertTrue($publicProperties->isStatic());
|
||||
$this->assertSame('private', $publicProperties->getVisibility());
|
||||
$this->assertFalse($publicProperties->isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\Constructor;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\Constructor}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class ConstructorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\Constructor::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$adapter->expects($this->any())->method('getName')->will($this->returnValue('adapter'));
|
||||
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMixedProperties');
|
||||
$constructor = new Constructor($reflection, $adapter);
|
||||
|
||||
$this->assertSame('__construct', $constructor->getName());
|
||||
$this->assertCount(1, $constructor->getParameters());
|
||||
$this->assertSame(
|
||||
"\$this->adapter = \$adapter;\nunset(\$this->publicProperty0);"
|
||||
. "\nunset(\$this->publicProperty1);\nunset(\$this->publicProperty2);",
|
||||
$constructor->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicGet;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicGet}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicGetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicGet::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$adapter->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$magicGet = new MagicGet($reflection, $adapter);
|
||||
|
||||
$this->assertSame('__get', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
'$return = $this->foo->call(\'ProxyManagerTestAsset\\\EmptyClass\', \'__get\', array($name));'
|
||||
. "\n\nreturn \$return;",
|
||||
$magicGet->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicIsset;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicIsset}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicIssetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicIsset::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$adapter->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$magicGet = new MagicIsset($reflection, $adapter);
|
||||
|
||||
$this->assertSame('__isset', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
'$return = $this->foo->call(\'ProxyManagerTestAsset\\\EmptyClass\', \'__isset\', array($name));'
|
||||
. "\n\nreturn \$return;",
|
||||
$magicGet->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicSet;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicSet}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicSetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicSet::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$adapter->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$magicGet = new MagicSet($reflection, $adapter);
|
||||
|
||||
$this->assertSame('__set', $magicGet->getName());
|
||||
$this->assertCount(2, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
'$return = $this->foo->call(\'ProxyManagerTestAsset\\\EmptyClass\', \'__set\', array($name, $value));'
|
||||
. "\n\nreturn \$return;",
|
||||
$magicGet->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicUnset;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicUnset}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicUnsetTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicUnset::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$adapter->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$magicGet = new MagicUnset($reflection, $adapter);
|
||||
|
||||
$this->assertSame('__unset', $magicGet->getName());
|
||||
$this->assertCount(1, $magicGet->getParameters());
|
||||
$this->assertStringMatchesFormat(
|
||||
'$return = $this->foo->call(\'ProxyManagerTestAsset\\\EmptyClass\', \'__unset\', array($name));'
|
||||
. "\n\nreturn \$return;",
|
||||
$magicGet->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class RemoteObjectMethodTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod
|
||||
*/
|
||||
public function testBodyStructureWithParameters()
|
||||
{
|
||||
$adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$adapter->expects($this->any())->method('getName')->will($this->returnValue('adapter'));
|
||||
|
||||
$reflectionMethod = new MethodReflection(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
'publicByReferenceParameterMethod'
|
||||
);
|
||||
|
||||
$method = RemoteObjectMethod::generateMethod(
|
||||
$reflectionMethod,
|
||||
$adapter,
|
||||
new ReflectionClass('Zend\\Code\\Generator\\PropertyGenerator')
|
||||
);
|
||||
|
||||
$this->assertSame('publicByReferenceParameterMethod', $method->getName());
|
||||
$this->assertCount(2, $method->getParameters());
|
||||
$this->assertSame(
|
||||
'$return = $this->adapter->call(\'Zend\\\Code\\\Generator\\\PropertyGenerator\', '
|
||||
. '\'publicByReferenceParameterMethod\', array($param, $byRefParam));'
|
||||
. "\n\nreturn \$return;",
|
||||
$method->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod
|
||||
*/
|
||||
public function testBodyStructureWithArrayParameter()
|
||||
{
|
||||
$adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$adapter->expects($this->any())->method('getName')->will($this->returnValue('adapter'));
|
||||
|
||||
$reflectionMethod = new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicArrayHintedMethod');
|
||||
|
||||
$method = RemoteObjectMethod::generateMethod(
|
||||
$reflectionMethod,
|
||||
$adapter,
|
||||
new ReflectionClass('Zend\\Code\\Generator\\PropertyGenerator')
|
||||
);
|
||||
|
||||
$this->assertSame('publicArrayHintedMethod', $method->getName());
|
||||
$this->assertCount(1, $method->getParameters());
|
||||
$this->assertSame(
|
||||
'$return = $this->adapter->call(\'Zend\\\Code\\\Generator\\\PropertyGenerator\', '
|
||||
. '\'publicArrayHintedMethod\', array($param));'
|
||||
. "\n\nreturn \$return;",
|
||||
$method->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod
|
||||
*/
|
||||
public function testBodyStructureWithoutParameters()
|
||||
{
|
||||
$adapter = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
$adapter->expects($this->any())->method('getName')->will($this->returnValue('adapter'));
|
||||
|
||||
$reflectionMethod = new MethodReflection(__CLASS__, 'testBodyStructureWithoutParameters');
|
||||
|
||||
$method = RemoteObjectMethod::generateMethod(
|
||||
$reflectionMethod,
|
||||
$adapter,
|
||||
new ReflectionClass('Zend\\Code\\Generator\\PropertyGenerator')
|
||||
);
|
||||
|
||||
$this->assertSame('testBodyStructureWithoutParameters', $method->getName());
|
||||
$this->assertCount(0, $method->getParameters());
|
||||
$this->assertSame(
|
||||
'$return = $this->adapter->call(\'Zend\\\Code\\\Generator\\\PropertyGenerator\', '
|
||||
. '\'testBodyStructureWithoutParameters\', array());'
|
||||
. "\n\nreturn \$return;",
|
||||
$method->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\RemoteObject\PropertyGenerator;
|
||||
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty;
|
||||
use ProxyManagerTest\ProxyGenerator\PropertyGenerator\AbstractUniquePropertyNameTest;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty
|
||||
* @group Coverage
|
||||
*/
|
||||
class AdapterPropertyTest extends AbstractUniquePropertyNameTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function createProperty()
|
||||
{
|
||||
return new AdapterProperty();
|
||||
}
|
||||
}
|
||||
103
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObjectGeneratorTest.php
vendored
Normal file
103
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/RemoteObjectGeneratorTest.php
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ProxyManager\ProxyGenerator\RemoteObjectGenerator;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObjectGenerator}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\RemoteObjectGenerator
|
||||
* @group Coverage
|
||||
*/
|
||||
class RemoteObjectGeneratorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTestedImplementations
|
||||
*
|
||||
* Verifies that generated code is valid and implements expected interfaces
|
||||
*/
|
||||
public function testGeneratesValidCode($className)
|
||||
{
|
||||
$generator = $this->getProxyGenerator();
|
||||
$generatedClassName = UniqueIdentifierGenerator::getIdentifier('AbstractProxyGeneratorTest');
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$originalClass = new ReflectionClass($className);
|
||||
$generatorStrategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate($originalClass, $generatedClass);
|
||||
$generatorStrategy->generate($generatedClass);
|
||||
|
||||
$generatedReflection = new ReflectionClass($generatedClassName);
|
||||
|
||||
if ($originalClass->isInterface()) {
|
||||
$this->assertTrue($generatedReflection->implementsInterface($className));
|
||||
} else {
|
||||
$this->assertEmpty(
|
||||
array_diff($originalClass->getInterfaceNames(), $generatedReflection->getInterfaceNames())
|
||||
);
|
||||
}
|
||||
|
||||
$this->assertSame($generatedClassName, $generatedReflection->getName());
|
||||
|
||||
foreach ($this->getExpectedImplementedInterfaces() as $interface) {
|
||||
$this->assertTrue($generatedReflection->implementsInterface($interface));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getProxyGenerator()
|
||||
{
|
||||
return new RemoteObjectGenerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getExpectedImplementedInterfaces()
|
||||
{
|
||||
return array(
|
||||
'ProxyManager\\Proxy\\RemoteObjectInterface',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTestedImplementations()
|
||||
{
|
||||
return array(
|
||||
array('ProxyManagerTestAsset\\BaseClass'),
|
||||
array('ProxyManagerTestAsset\\ClassWithMagicMethods'),
|
||||
array('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'),
|
||||
array('ProxyManagerTestAsset\\ClassWithMixedProperties'),
|
||||
array('ProxyManagerTestAsset\\BaseInterface'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\Util;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter
|
||||
* @group Coverage
|
||||
*/
|
||||
class ProxiedMethodsFilterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider expectedMethods
|
||||
*/
|
||||
public function testFiltering(ReflectionClass $reflectionClass, $excludes, array $expectedMethods)
|
||||
{
|
||||
if (is_array($excludes)) {
|
||||
$filtered = ProxiedMethodsFilter::getProxiedMethods($reflectionClass, $excludes);
|
||||
} else {
|
||||
$filtered = ProxiedMethodsFilter::getProxiedMethods($reflectionClass);
|
||||
}
|
||||
|
||||
foreach ($filtered as $method) {
|
||||
$this->assertInstanceOf('ReflectionMethod', $method);
|
||||
}
|
||||
|
||||
$keys = array_map(
|
||||
function (ReflectionMethod $method) {
|
||||
return $method->getName();
|
||||
},
|
||||
$filtered
|
||||
);
|
||||
|
||||
sort($keys);
|
||||
sort($expectedMethods);
|
||||
|
||||
$this->assertSame($keys, $expectedMethods);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[][]
|
||||
*/
|
||||
public function expectedMethods()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\BaseClass'),
|
||||
null,
|
||||
array(
|
||||
'publicArrayHintedMethod',
|
||||
'publicByReferenceMethod',
|
||||
'publicByReferenceParameterMethod',
|
||||
'publicMethod',
|
||||
'publicTypeHintedMethod',
|
||||
),
|
||||
),
|
||||
array(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'),
|
||||
null,
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\LazyLoadingMock'),
|
||||
null,
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\LazyLoadingMock'),
|
||||
array(),
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\HydratedObject'),
|
||||
array('doFoo'),
|
||||
array('__get'),
|
||||
),
|
||||
array(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\HydratedObject'),
|
||||
array('Dofoo'),
|
||||
array('__get'),
|
||||
),
|
||||
array(
|
||||
new ReflectionClass('ProxyManagerTestAsset\\HydratedObject'),
|
||||
array(),
|
||||
array('doFoo', '__get'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\Util;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\Util\PublicScopeSimulator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\ProxyGenerator\Util\PublicScopeSimulator
|
||||
* @group Coverage
|
||||
*/
|
||||
class PublicScopeSimulatorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSimpleGet()
|
||||
{
|
||||
$code = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_GET,
|
||||
'foo',
|
||||
null,
|
||||
null,
|
||||
'bar'
|
||||
);
|
||||
|
||||
$this->assertStringMatchesFormat('%a{%areturn $%s->$foo;%a}%a$bar = %s;', $code);
|
||||
}
|
||||
|
||||
public function testSimpleSet()
|
||||
{
|
||||
$code = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_SET,
|
||||
'foo',
|
||||
'baz',
|
||||
null,
|
||||
'bar'
|
||||
);
|
||||
|
||||
$this->assertStringMatchesFormat('%a{%areturn $%s->$foo = $baz;%a}%a$bar = %s;', $code);
|
||||
}
|
||||
|
||||
public function testSimpleIsset()
|
||||
{
|
||||
$code = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_ISSET,
|
||||
'foo',
|
||||
null,
|
||||
null,
|
||||
'bar'
|
||||
);
|
||||
|
||||
$this->assertStringMatchesFormat('%a{%areturn isset($%s->$foo);%a}%a$bar = %s;', $code);
|
||||
}
|
||||
|
||||
public function testSimpleUnset()
|
||||
{
|
||||
$code = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_UNSET,
|
||||
'foo',
|
||||
null,
|
||||
null,
|
||||
'bar'
|
||||
);
|
||||
|
||||
$this->assertStringMatchesFormat('%a{%aunset($%s->$foo);%a}%a$bar = %s;', $code);
|
||||
}
|
||||
|
||||
public function testSetRequiresValueParameterName()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_SET,
|
||||
'foo',
|
||||
null,
|
||||
null,
|
||||
'bar'
|
||||
);
|
||||
}
|
||||
|
||||
public function testDelegatesToValueHolderWhenAvailable()
|
||||
{
|
||||
$code = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_SET,
|
||||
'foo',
|
||||
'baz',
|
||||
new PropertyGenerator('valueHolder'),
|
||||
'bar'
|
||||
);
|
||||
|
||||
$this->assertStringMatchesFormat(
|
||||
'%A$targetObject = $this->valueHolder;%a{%areturn $%s->$foo = $baz;%a}%a$bar = %s;',
|
||||
$code
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetRequiresValidOperation()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
PublicScopeSimulator::getPublicAccessSimulationCode('invalid', 'foo');
|
||||
}
|
||||
|
||||
public function testWillReturnDirectlyWithNoReturnParam()
|
||||
{
|
||||
$code = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_GET,
|
||||
'foo'
|
||||
);
|
||||
|
||||
$this->assertStringMatchesFormat('%a{%areturn $%s->$foo;%a}%areturn %s;', $code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\ValueHolder\MethodGenerator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class GetWrappedValueHolderValueTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('foo'));
|
||||
|
||||
$getter = new GetWrappedValueHolderValue($valueHolder);
|
||||
|
||||
$this->assertSame('getWrappedValueHolderValue', $getter->getName());
|
||||
$this->assertCount(0, $getter->getParameters());
|
||||
$this->assertSame('return $this->foo;', $getter->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
namespace ProxyManagerTest\ProxyGenerator\ValueHolder\MethodGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\MagicSleep;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\MagicSleep}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicSleepTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\MagicSleep::__construct
|
||||
*/
|
||||
public function testBodyStructure()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
|
||||
$valueHolder = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
|
||||
|
||||
$valueHolder->expects($this->any())->method('getName')->will($this->returnValue('bar'));
|
||||
|
||||
$magicSleep = new MagicSleep($reflection, $valueHolder);
|
||||
|
||||
$this->assertSame('__sleep', $magicSleep->getName());
|
||||
$this->assertCount(0, $magicSleep->getParameters());
|
||||
$this->assertSame(
|
||||
"return array('bar');",
|
||||
$magicSleep->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user