PDF rausgenommen
This commit is contained in:
133
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Autoloader/AutoloaderTest.php
vendored
Normal file
133
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Autoloader/AutoloaderTest.php
vendored
Normal file
@ -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\Autoloader;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Autoloader\Autoloader;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Autoloader\Autoloader}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\Autoloader\Autoloader
|
||||
* @group Coverage
|
||||
*/
|
||||
class AutoloaderTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\Autoloader\Autoloader
|
||||
*/
|
||||
protected $autoloader;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $fileLocator;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Inflector\ClassNameInflectorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $classNameInflector;
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Autoloader\Autoloader::__construct
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->fileLocator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
|
||||
$this->classNameInflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface');
|
||||
$this->autoloader = new Autoloader($this->fileLocator, $this->classNameInflector);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Autoloader\Autoloader::__invoke
|
||||
*/
|
||||
public function testWillNotAutoloadUserClasses()
|
||||
{
|
||||
$className = 'Foo\\' . UniqueIdentifierGenerator::getIdentifier('Bar');
|
||||
$this
|
||||
->classNameInflector
|
||||
->expects($this->once())
|
||||
->method('isProxyClassName')
|
||||
->with($className)
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->assertFalse($this->autoloader->__invoke($className));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Autoloader\Autoloader::__invoke
|
||||
*/
|
||||
public function testWillNotAutoloadNonExistingClass()
|
||||
{
|
||||
$className = 'Foo\\' . UniqueIdentifierGenerator::getIdentifier('Bar');
|
||||
$this
|
||||
->classNameInflector
|
||||
->expects($this->once())
|
||||
->method('isProxyClassName')
|
||||
->with($className)
|
||||
->will($this->returnValue(true));
|
||||
$this
|
||||
->fileLocator
|
||||
->expects($this->once())
|
||||
->method('getProxyFileName')
|
||||
->will($this->returnValue(__DIR__ . '/non-existing'));
|
||||
|
||||
$this->assertFalse($this->autoloader->__invoke($className));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Autoloader\Autoloader::__invoke
|
||||
*/
|
||||
public function testWillNotAutoloadExistingClass()
|
||||
{
|
||||
$this->assertFalse($this->autoloader->__invoke(__CLASS__));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Autoloader\Autoloader::__invoke
|
||||
*/
|
||||
public function testWillAutoloadExistingFile()
|
||||
{
|
||||
$namespace = 'Foo';
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('Bar');
|
||||
$fqcn = $namespace . '\\' . $className;
|
||||
$fileName = sys_get_temp_dir() . '/foo_' . uniqid() . '.php';
|
||||
|
||||
file_put_contents($fileName, '<?php namespace ' . $namespace . '; class ' . $className . '{}');
|
||||
|
||||
$this
|
||||
->classNameInflector
|
||||
->expects($this->once())
|
||||
->method('isProxyClassName')
|
||||
->with($fqcn)
|
||||
->will($this->returnValue(true));
|
||||
$this
|
||||
->fileLocator
|
||||
->expects($this->once())
|
||||
->method('getProxyFileName')
|
||||
->will($this->returnValue($fileName));
|
||||
|
||||
$this->assertTrue($this->autoloader->__invoke($fqcn));
|
||||
$this->assertTrue(class_exists($fqcn, false));
|
||||
}
|
||||
}
|
183
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ConfigurationTest.php
vendored
Normal file
183
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ConfigurationTest.php
vendored
Normal file
@ -0,0 +1,183 @@
|
||||
<?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;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Configuration;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Configuration}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class ConfigurationTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\Configuration
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->configuration = new Configuration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Configuration::getProxiesNamespace
|
||||
* @covers \ProxyManager\Configuration::setProxiesNamespace
|
||||
*/
|
||||
public function testGetSetProxiesNamespace()
|
||||
{
|
||||
$this->assertSame(
|
||||
'ProxyManagerGeneratedProxy',
|
||||
$this->configuration->getProxiesNamespace(),
|
||||
'Default setting check for BC'
|
||||
);
|
||||
|
||||
$this->configuration->setProxiesNamespace('foo');
|
||||
$this->assertSame('foo', $this->configuration->getProxiesNamespace());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Configuration::getClassNameInflector
|
||||
* @covers \ProxyManager\Configuration::setClassNameInflector
|
||||
*/
|
||||
public function testSetGetClassNameInflector()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
'ProxyManager\\Inflector\\ClassNameInflectorInterface',
|
||||
$this->configuration->getClassNameInflector()
|
||||
);
|
||||
|
||||
/* @var $inflector \ProxyManager\Inflector\ClassNameInflectorInterface */
|
||||
$inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface');
|
||||
|
||||
$this->configuration->setClassNameInflector($inflector);
|
||||
$this->assertSame($inflector, $this->configuration->getClassNameInflector());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Configuration::getGeneratorStrategy
|
||||
* @covers \ProxyManager\Configuration::setGeneratorStrategy
|
||||
*/
|
||||
public function testSetGetGeneratorStrategy()
|
||||
{
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface',
|
||||
$this->configuration->getGeneratorStrategy()
|
||||
);
|
||||
|
||||
/* @var $strategy \ProxyManager\GeneratorStrategy\GeneratorStrategyInterface */
|
||||
$strategy = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
|
||||
|
||||
$this->configuration->setGeneratorStrategy($strategy);
|
||||
$this->assertSame($strategy, $this->configuration->getGeneratorStrategy());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Configuration::getProxiesTargetDir
|
||||
* @covers \ProxyManager\Configuration::setProxiesTargetDir
|
||||
*/
|
||||
public function testSetGetProxiesTargetDir()
|
||||
{
|
||||
$this->assertTrue(is_dir($this->configuration->getProxiesTargetDir()));
|
||||
|
||||
$this->configuration->setProxiesTargetDir(__DIR__);
|
||||
$this->assertSame(__DIR__, $this->configuration->getProxiesTargetDir());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Configuration::getProxyAutoloader
|
||||
* @covers \ProxyManager\Configuration::setProxyAutoloader
|
||||
*/
|
||||
public function testSetGetProxyAutoloader()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
'ProxyManager\\Autoloader\\AutoloaderInterface',
|
||||
$this->configuration->getProxyAutoloader()
|
||||
);
|
||||
|
||||
/* @var $autoloader \ProxyManager\Autoloader\AutoloaderInterface */
|
||||
$autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
|
||||
|
||||
$this->configuration->setProxyAutoloader($autoloader);
|
||||
$this->assertSame($autoloader, $this->configuration->getProxyAutoloader());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Configuration::getSignatureGenerator
|
||||
* @covers \ProxyManager\Configuration::setSignatureGenerator
|
||||
*/
|
||||
public function testSetGetSignatureGenerator()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
'ProxyManager\\Signature\\SignatureGeneratorInterface',
|
||||
$this->configuration->getSignatureGenerator()
|
||||
);
|
||||
|
||||
/* @var $signatureGenerator \ProxyManager\Signature\SignatureGeneratorInterface */
|
||||
$signatureGenerator = $this->getMock('ProxyManager\\Signature\\SignatureGeneratorInterface');
|
||||
|
||||
$this->configuration->setSignatureGenerator($signatureGenerator);
|
||||
$this->assertSame($signatureGenerator, $this->configuration->getSignatureGenerator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Configuration::getSignatureChecker
|
||||
* @covers \ProxyManager\Configuration::setSignatureChecker
|
||||
*/
|
||||
public function testSetGetSignatureChecker()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
'ProxyManager\\Signature\\SignatureCheckerInterface',
|
||||
$this->configuration->getSignatureChecker()
|
||||
);
|
||||
|
||||
/* @var $signatureChecker \ProxyManager\Signature\SignatureCheckerInterface */
|
||||
$signatureChecker = $this->getMock('ProxyManager\\Signature\\SignatureCheckerInterface');
|
||||
|
||||
$this->configuration->setSignatureChecker($signatureChecker);
|
||||
$this->assertSame($signatureChecker, $this->configuration->getSignatureChecker());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Configuration::getClassSignatureGenerator
|
||||
* @covers \ProxyManager\Configuration::setClassSignatureGenerator
|
||||
*/
|
||||
public function testSetGetClassSignatureGenerator()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
'ProxyManager\\Signature\\ClassSignatureGeneratorInterface',
|
||||
$this->configuration->getClassSignatureGenerator()
|
||||
);
|
||||
|
||||
/* @var $classSignatureGenerator \ProxyManager\Signature\ClassSignatureGeneratorInterface */
|
||||
$classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface');
|
||||
|
||||
$this->configuration->setClassSignatureGenerator($classSignatureGenerator);
|
||||
$this->assertSame($classSignatureGenerator, $this->configuration->getClassSignatureGenerator());
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?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\Exception;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Exception\DisabledMethodException;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Exception\DisabledMethodException}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\Exception\DisabledMethodException
|
||||
* @group Coverage
|
||||
*/
|
||||
class DisabledMethodExceptionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\Exception\DisabledMethodException::disabledMethod
|
||||
*/
|
||||
public function testProxyDirectoryNotFound()
|
||||
{
|
||||
$exception = DisabledMethodException::disabledMethod('foo::bar');
|
||||
|
||||
$this->assertSame('Method "foo::bar" is forcefully disabled', $exception->getMessage());
|
||||
}
|
||||
}
|
@ -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\Exception;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Exception\FileNotWritableException;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Exception\FileNotWritableException}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\Exception\FileNotWritableException
|
||||
* @group Coverage
|
||||
*/
|
||||
class FileNotWritableExceptionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFromInvalidMoveOperation()
|
||||
{
|
||||
$exception = FileNotWritableException::fromInvalidMoveOperation('/tmp/a', '/tmp/b');
|
||||
|
||||
$this->assertInstanceOf('ProxyManager\\Exception\\FileNotWritableException', $exception);
|
||||
$this->assertSame(
|
||||
'Could not move file "/tmp/a" to location "/tmp/b": either the source file is not readable,'
|
||||
. ' or the destination is not writable',
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromNotWritableLocationWithNonFilePath()
|
||||
{
|
||||
$exception = FileNotWritableException::fromNonWritableLocation(__DIR__);
|
||||
|
||||
$this->assertInstanceOf('ProxyManager\\Exception\\FileNotWritableException', $exception);
|
||||
$this->assertSame(
|
||||
'Could not write to path "' . __DIR__ . '": exists and is not a file',
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromNotWritableLocationWithNonWritablePath()
|
||||
{
|
||||
$path = sys_get_temp_dir() . '/' . uniqid('FileNotWritableExceptionTestNonWritable', true);
|
||||
|
||||
mkdir($path, 0555);
|
||||
|
||||
$exception = FileNotWritableException::fromNonWritableLocation($path . '/foo');
|
||||
|
||||
$this->assertInstanceOf('ProxyManager\\Exception\\FileNotWritableException', $exception);
|
||||
$this->assertSame(
|
||||
'Could not write to path "' . $path . '/foo": is not writable',
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
<?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\Exception;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Exception\InvalidProxiedClassException;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Exception\InvalidProxiedClassException}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\Exception\InvalidProxiedClassException
|
||||
* @group Coverage
|
||||
*/
|
||||
class InvalidProxiedClassExceptionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testInterfaceNotSupported()
|
||||
{
|
||||
$this->assertSame(
|
||||
'Provided interface "ProxyManagerTestAsset\BaseInterface" cannot be proxied',
|
||||
InvalidProxiedClassException::interfaceNotSupported(
|
||||
new ReflectionClass('ProxyManagerTestAsset\BaseInterface')
|
||||
)->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
public function testFinalClassNotSupported()
|
||||
{
|
||||
$this->assertSame(
|
||||
'Provided class "ProxyManagerTestAsset\FinalClass" is final and cannot be proxied',
|
||||
InvalidProxiedClassException::finalClassNotSupported(
|
||||
new ReflectionClass('ProxyManagerTestAsset\FinalClass')
|
||||
)->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
public function testAbstractProtectedMethodsNotSupported()
|
||||
{
|
||||
$this->assertSame(
|
||||
'Provided class "ProxyManagerTestAsset\ClassWithAbstractProtectedMethod" has following protected abstract'
|
||||
. ' methods, and therefore cannot be proxied:' . "\n"
|
||||
. 'ProxyManagerTestAsset\ClassWithAbstractProtectedMethod::protectedAbstractMethod',
|
||||
InvalidProxiedClassException::abstractProtectedMethodsNotSupported(
|
||||
new ReflectionClass('ProxyManagerTestAsset\ClassWithAbstractProtectedMethod')
|
||||
)->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?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\Exception;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Exception\InvalidProxyDirectoryException;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Exception\InvalidProxyDirectoryException}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\Exception\InvalidProxyDirectoryException
|
||||
* @group Coverage
|
||||
*/
|
||||
class InvalidProxyDirectoryExceptionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\Exception\InvalidProxyDirectoryException::proxyDirectoryNotFound
|
||||
*/
|
||||
public function testProxyDirectoryNotFound()
|
||||
{
|
||||
$exception = InvalidProxyDirectoryException::proxyDirectoryNotFound('foo/bar');
|
||||
|
||||
$this->assertSame('Provided directory "foo/bar" does not exist', $exception->getMessage());
|
||||
}
|
||||
}
|
@ -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\Exception;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Exception\UnsupportedProxiedClassException;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Exception\UnsupportedProxiedClassException}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\Exception\UnsupportedProxiedClassException
|
||||
* @group Coverage
|
||||
*/
|
||||
class UnsupportedProxiedClassExceptionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\Exception\UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty
|
||||
*/
|
||||
public function testUnsupportedLocalizedReflectionProperty()
|
||||
{
|
||||
$this->assertSame(
|
||||
'Provided reflection property "property0" of class "ProxyManagerTestAsset\ClassWithPrivateProperties" '
|
||||
. 'is private and cannot be localized in PHP 5.3',
|
||||
UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty(
|
||||
new ReflectionProperty('ProxyManagerTestAsset\ClassWithPrivateProperties', 'property0')
|
||||
)->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
158
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AbstractBaseFactoryTest.php
vendored
Normal file
158
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/AbstractBaseFactoryTest.php
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
<?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\Factory;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\AbstractBaseFactory}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\Factory\AbstractBaseFactory
|
||||
* @group Coverage
|
||||
*/
|
||||
class AbstractBaseFactoryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\Factory\AbstractBaseFactory
|
||||
*/
|
||||
private $factory;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\ProxyGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $generator;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Inflector\ClassNameInflectorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $classNameInflector;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\GeneratorStrategy\GeneratorStrategyInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $generatorStrategy;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Autoloader\AutoloaderInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $proxyAutoloader;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Signature\SignatureCheckerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $signatureChecker;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Signature\ClassSignatureGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $classSignatureGenerator;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$configuration = $this->getMock('ProxyManager\\Configuration');
|
||||
$this->generator = $this->getMock('ProxyManager\\ProxyGenerator\\ProxyGeneratorInterface');
|
||||
$this->classNameInflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface');
|
||||
$this->generatorStrategy = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
|
||||
$this->proxyAutoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
|
||||
$this->signatureChecker = $this->getMock('ProxyManager\\Signature\\SignatureCheckerInterface');
|
||||
$this->classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface');
|
||||
|
||||
$configuration
|
||||
->expects($this->any())
|
||||
->method('getClassNameInflector')
|
||||
->will($this->returnValue($this->classNameInflector));
|
||||
|
||||
$configuration
|
||||
->expects($this->any())
|
||||
->method('getGeneratorStrategy')
|
||||
->will($this->returnValue($this->generatorStrategy));
|
||||
|
||||
$configuration
|
||||
->expects($this->any())
|
||||
->method('getProxyAutoloader')
|
||||
->will($this->returnValue($this->proxyAutoloader));
|
||||
|
||||
$configuration
|
||||
->expects($this->any())
|
||||
->method('getSignatureChecker')
|
||||
->will($this->returnValue($this->signatureChecker));
|
||||
|
||||
$configuration
|
||||
->expects($this->any())
|
||||
->method('getClassSignatureGenerator')
|
||||
->will($this->returnValue($this->classSignatureGenerator));
|
||||
|
||||
$this
|
||||
->classNameInflector
|
||||
->expects($this->any())
|
||||
->method('getUserClassName')
|
||||
->will($this->returnValue('stdClass'));
|
||||
|
||||
$this->factory = $this->getMockForAbstractClass(
|
||||
'ProxyManager\\Factory\\AbstractBaseFactory',
|
||||
array($configuration)
|
||||
);
|
||||
|
||||
$this->factory->expects($this->any())->method('getGenerator')->will($this->returnValue($this->generator));
|
||||
}
|
||||
|
||||
public function testGeneratesClass()
|
||||
{
|
||||
$generateProxy = new ReflectionMethod($this->factory, 'generateProxy');
|
||||
|
||||
$generateProxy->setAccessible(true);
|
||||
$generatedClass = UniqueIdentifierGenerator::getIdentifier('fooBar');
|
||||
|
||||
$this
|
||||
->classNameInflector
|
||||
->expects($this->any())
|
||||
->method('getProxyClassName')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($generatedClass));
|
||||
|
||||
$this
|
||||
->generatorStrategy
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with($this->isInstanceOf('Zend\\Code\\Generator\\ClassGenerator'));
|
||||
$this
|
||||
->proxyAutoloader
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($generatedClass)
|
||||
->will($this->returnCallback(function ($className) {
|
||||
eval('class ' . $className . ' {}');
|
||||
}));
|
||||
|
||||
$this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
|
||||
$this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
|
||||
|
||||
$this->assertSame($generatedClass, $generateProxy->invoke($this->factory, 'stdClass'));
|
||||
$this->assertTrue(class_exists($generatedClass, false));
|
||||
$this->assertSame($generatedClass, $generateProxy->invoke($this->factory, 'stdClass'));
|
||||
}
|
||||
}
|
@ -0,0 +1,199 @@
|
||||
<?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\Factory;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory;
|
||||
use ProxyManager\Factory\AccessInterceptorValueHolderFactory;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class AccessInterceptorScopeLocalizerFactoryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $inflector;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $signatureChecker;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Signature\ClassSignatureGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $classSignatureGenerator;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = $this->getMock('ProxyManager\\Configuration');
|
||||
$this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface');
|
||||
$this->signatureChecker = $this->getMock('ProxyManager\\Signature\\SignatureCheckerInterface');
|
||||
$this->classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface');
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassNameInflector')
|
||||
->will($this->returnValue($this->inflector));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getSignatureChecker')
|
||||
->will($this->returnValue($this->signatureChecker));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassSignatureGenerator')
|
||||
->will($this->returnValue($this->classSignatureGenerator));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::__construct
|
||||
*/
|
||||
public function testWithOptionalFactory()
|
||||
{
|
||||
$factory = new AccessInterceptorValueHolderFactory();
|
||||
$this->assertAttributeNotEmpty('configuration', $factory);
|
||||
$this->assertAttributeInstanceOf('ProxyManager\Configuration', 'configuration', $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::__construct
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::createProxy
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::getGenerator
|
||||
*/
|
||||
public function testWillSkipAutoGeneration()
|
||||
{
|
||||
$instance = new stdClass();
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue('ProxyManagerTestAsset\\AccessInterceptorValueHolderMock'));
|
||||
|
||||
$factory = new AccessInterceptorScopeLocalizerFactory($this->config);
|
||||
/* @var $proxy \ProxyManagerTestAsset\AccessInterceptorValueHolderMock */
|
||||
$proxy = $factory->createProxy($instance, array('foo'), array('bar'));
|
||||
|
||||
$this->assertInstanceOf('ProxyManagerTestAsset\\AccessInterceptorValueHolderMock', $proxy);
|
||||
$this->assertSame($instance, $proxy->instance);
|
||||
$this->assertSame(array('foo'), $proxy->prefixInterceptors);
|
||||
$this->assertSame(array('bar'), $proxy->suffixInterceptors);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::__construct
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::createProxy
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory::getGenerator
|
||||
*
|
||||
* NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
|
||||
*/
|
||||
public function testWillTryAutoGeneration()
|
||||
{
|
||||
$instance = new stdClass();
|
||||
$proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
|
||||
$generator = $this->getMock('ProxyManager\GeneratorStrategy\\GeneratorStrategyInterface');
|
||||
$autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
|
||||
|
||||
$this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
|
||||
$this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
|
||||
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with(
|
||||
$this->callback(
|
||||
function (ClassGenerator $targetClass) use ($proxyClassName) {
|
||||
return $targetClass->getName() === $proxyClassName;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// simulate autoloading
|
||||
$autoloader
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($proxyClassName)
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () use ($proxyClassName) {
|
||||
eval(
|
||||
'class ' . $proxyClassName
|
||||
. ' extends \\ProxyManagerTestAsset\\AccessInterceptorValueHolderMock {}'
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($proxyClassName));
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getUserClassName')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
|
||||
|
||||
$this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
|
||||
$this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
|
||||
|
||||
$factory = new AccessInterceptorScopeLocalizerFactory($this->config);
|
||||
/* @var $proxy \ProxyManagerTestAsset\AccessInterceptorValueHolderMock */
|
||||
$proxy = $factory->createProxy($instance, array('foo'), array('bar'));
|
||||
|
||||
$this->assertInstanceOf($proxyClassName, $proxy);
|
||||
$this->assertSame($instance, $proxy->instance);
|
||||
$this->assertSame(array('foo'), $proxy->prefixInterceptors);
|
||||
$this->assertSame(array('bar'), $proxy->suffixInterceptors);
|
||||
}
|
||||
}
|
@ -0,0 +1,198 @@
|
||||
<?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\Factory;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\AccessInterceptorValueHolderFactory;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\AccessInterceptorValueHolderFactory}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class AccessInterceptorValueHolderFactoryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $inflector;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $signatureChecker;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Signature\ClassSignatureGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $classSignatureGenerator;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = $this->getMock('ProxyManager\\Configuration');
|
||||
$this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface');
|
||||
$this->signatureChecker = $this->getMock('ProxyManager\\Signature\\SignatureCheckerInterface');
|
||||
$this->classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface');
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassNameInflector')
|
||||
->will($this->returnValue($this->inflector));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getSignatureChecker')
|
||||
->will($this->returnValue($this->signatureChecker));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassSignatureGenerator')
|
||||
->will($this->returnValue($this->classSignatureGenerator));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::__construct
|
||||
*/
|
||||
public function testWithOptionalFactory()
|
||||
{
|
||||
$factory = new AccessInterceptorValueHolderFactory();
|
||||
$this->assertAttributeNotEmpty('configuration', $factory);
|
||||
$this->assertAttributeInstanceOf('ProxyManager\Configuration', 'configuration', $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::__construct
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::createProxy
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::getGenerator
|
||||
*/
|
||||
public function testWillSkipAutoGeneration()
|
||||
{
|
||||
$instance = new stdClass();
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue('ProxyManagerTestAsset\\AccessInterceptorValueHolderMock'));
|
||||
|
||||
$factory = new AccessInterceptorValueHolderFactory($this->config);
|
||||
/* @var $proxy \ProxyManagerTestAsset\AccessInterceptorValueHolderMock */
|
||||
$proxy = $factory->createProxy($instance, array('foo'), array('bar'));
|
||||
|
||||
$this->assertInstanceOf('ProxyManagerTestAsset\\AccessInterceptorValueHolderMock', $proxy);
|
||||
$this->assertSame($instance, $proxy->instance);
|
||||
$this->assertSame(array('foo'), $proxy->prefixInterceptors);
|
||||
$this->assertSame(array('bar'), $proxy->suffixInterceptors);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::__construct
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::createProxy
|
||||
* @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::getGenerator
|
||||
*
|
||||
* NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
|
||||
*/
|
||||
public function testWillTryAutoGeneration()
|
||||
{
|
||||
$instance = new stdClass();
|
||||
$proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
|
||||
$generator = $this->getMock('ProxyManager\GeneratorStrategy\\GeneratorStrategyInterface');
|
||||
$autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
|
||||
|
||||
$this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
|
||||
$this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
|
||||
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with(
|
||||
$this->callback(
|
||||
function (ClassGenerator $targetClass) use ($proxyClassName) {
|
||||
return $targetClass->getName() === $proxyClassName;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// simulate autoloading
|
||||
$autoloader
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($proxyClassName)
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () use ($proxyClassName) {
|
||||
eval(
|
||||
'class ' . $proxyClassName
|
||||
. ' extends \\ProxyManagerTestAsset\\AccessInterceptorValueHolderMock {}'
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($proxyClassName));
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getUserClassName')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
|
||||
|
||||
$this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
|
||||
$this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
|
||||
|
||||
$factory = new AccessInterceptorValueHolderFactory($this->config);
|
||||
/* @var $proxy \ProxyManagerTestAsset\AccessInterceptorValueHolderMock */
|
||||
$proxy = $factory->createProxy($instance, array('foo'), array('bar'));
|
||||
|
||||
$this->assertInstanceOf($proxyClassName, $proxy);
|
||||
$this->assertSame($instance, $proxy->instance);
|
||||
$this->assertSame(array('foo'), $proxy->prefixInterceptors);
|
||||
$this->assertSame(array('bar'), $proxy->suffixInterceptors);
|
||||
}
|
||||
}
|
@ -0,0 +1,193 @@
|
||||
<?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\Factory;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\LazyLoadingGhostFactory;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\LazyLoadingGhostFactory}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class LazyLoadingGhostFactoryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $inflector;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $signatureChecker;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Signature\ClassSignatureGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $classSignatureGenerator;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = $this->getMock('ProxyManager\\Configuration');
|
||||
$this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface');
|
||||
$this->signatureChecker = $this->getMock('ProxyManager\\Signature\\SignatureCheckerInterface');
|
||||
$this->classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface');
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassNameInflector')
|
||||
->will($this->returnValue($this->inflector));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getSignatureChecker')
|
||||
->will($this->returnValue($this->signatureChecker));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassSignatureGenerator')
|
||||
->will($this->returnValue($this->classSignatureGenerator));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct
|
||||
*/
|
||||
public function testWithOptionalFactory()
|
||||
{
|
||||
$factory = new LazyLoadingGhostFactory();
|
||||
$this->assertAttributeNotEmpty('configuration', $factory);
|
||||
$this->assertAttributeInstanceOf('ProxyManager\Configuration', 'configuration', $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct
|
||||
* @covers \ProxyManager\Factory\LazyLoadingGhostFactory::createProxy
|
||||
*/
|
||||
public function testWillSkipAutoGeneration()
|
||||
{
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('foo');
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with($className)
|
||||
->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
|
||||
|
||||
$factory = new LazyLoadingGhostFactory($this->config);
|
||||
$initializer = function () {
|
||||
};
|
||||
/* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */
|
||||
$proxy = $factory->createProxy($className, $initializer);
|
||||
|
||||
$this->assertInstanceOf('ProxyManagerTestAsset\\LazyLoadingMock', $proxy);
|
||||
$this->assertSame($initializer, $proxy->initializer);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct
|
||||
* @covers \ProxyManager\Factory\LazyLoadingGhostFactory::createProxy
|
||||
* @covers \ProxyManager\Factory\LazyLoadingGhostFactory::getGenerator
|
||||
*
|
||||
* NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
|
||||
*/
|
||||
public function testWillTryAutoGeneration()
|
||||
{
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('foo');
|
||||
$proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
|
||||
$generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
|
||||
$autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
|
||||
|
||||
$this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
|
||||
$this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
|
||||
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with(
|
||||
$this->callback(
|
||||
function (ClassGenerator $targetClass) use ($proxyClassName) {
|
||||
return $targetClass->getName() === $proxyClassName;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// simulate autoloading
|
||||
$autoloader
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($proxyClassName)
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () use ($proxyClassName) {
|
||||
eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\LazyLoadingMock {}');
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with($className)
|
||||
->will($this->returnValue($proxyClassName));
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getUserClassName')
|
||||
->with($className)
|
||||
->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
|
||||
|
||||
$this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
|
||||
$this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
|
||||
|
||||
$factory = new LazyLoadingGhostFactory($this->config);
|
||||
$initializer = function () {
|
||||
};
|
||||
/* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */
|
||||
$proxy = $factory->createProxy($className, $initializer);
|
||||
|
||||
$this->assertInstanceOf($proxyClassName, $proxy);
|
||||
$this->assertSame($initializer, $proxy->initializer);
|
||||
}
|
||||
}
|
@ -0,0 +1,193 @@
|
||||
<?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\Factory;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\LazyLoadingValueHolderFactory}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class LazyLoadingValueHolderFactoryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $inflector;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $signatureChecker;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Signature\ClassSignatureGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $classSignatureGenerator;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = $this->getMock('ProxyManager\\Configuration');
|
||||
$this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface');
|
||||
$this->signatureChecker = $this->getMock('ProxyManager\\Signature\\SignatureCheckerInterface');
|
||||
$this->classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface');
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassNameInflector')
|
||||
->will($this->returnValue($this->inflector));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getSignatureChecker')
|
||||
->will($this->returnValue($this->signatureChecker));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassSignatureGenerator')
|
||||
->will($this->returnValue($this->classSignatureGenerator));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::__construct
|
||||
*/
|
||||
public function testWithOptionalFactory()
|
||||
{
|
||||
$factory = new LazyLoadingValueHolderFactory();
|
||||
$this->assertAttributeNotEmpty('configuration', $factory);
|
||||
$this->assertAttributeInstanceOf('ProxyManager\Configuration', 'configuration', $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::__construct
|
||||
* @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::createProxy
|
||||
*/
|
||||
public function testWillSkipAutoGeneration()
|
||||
{
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('foo');
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with($className)
|
||||
->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
|
||||
|
||||
$factory = new LazyLoadingValueHolderFactory($this->config);
|
||||
$initializer = function () {
|
||||
};
|
||||
/* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */
|
||||
$proxy = $factory->createProxy($className, $initializer);
|
||||
|
||||
$this->assertInstanceOf('ProxyManagerTestAsset\\LazyLoadingMock', $proxy);
|
||||
$this->assertSame($initializer, $proxy->initializer);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::__construct
|
||||
* @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::createProxy
|
||||
* @covers \ProxyManager\Factory\LazyLoadingValueHolderFactory::getGenerator
|
||||
*
|
||||
* NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
|
||||
*/
|
||||
public function testWillTryAutoGeneration()
|
||||
{
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('foo');
|
||||
$proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
|
||||
$generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
|
||||
$autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
|
||||
|
||||
$this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
|
||||
$this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
|
||||
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with(
|
||||
$this->callback(
|
||||
function (ClassGenerator $targetClass) use ($proxyClassName) {
|
||||
return $targetClass->getName() === $proxyClassName;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// simulate autoloading
|
||||
$autoloader
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($proxyClassName)
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () use ($proxyClassName) {
|
||||
eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\LazyLoadingMock {}');
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with($className)
|
||||
->will($this->returnValue($proxyClassName));
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getUserClassName')
|
||||
->with($className)
|
||||
->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
|
||||
|
||||
$this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
|
||||
$this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
|
||||
|
||||
$factory = new LazyLoadingValueHolderFactory($this->config);
|
||||
$initializer = function () {
|
||||
};
|
||||
/* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */
|
||||
$proxy = $factory->createProxy($className, $initializer);
|
||||
|
||||
$this->assertInstanceOf($proxyClassName, $proxy);
|
||||
$this->assertSame($initializer, $proxy->initializer);
|
||||
}
|
||||
}
|
180
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/NullObjectFactoryTest.php
vendored
Normal file
180
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/NullObjectFactoryTest.php
vendored
Normal file
@ -0,0 +1,180 @@
|
||||
<?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\Factory;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\NullObjectFactory;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\NullObjectFactory}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class NullObjectFactoryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $inflector;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $signatureChecker;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Signature\ClassSignatureGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $classSignatureGenerator;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = $this->getMock('ProxyManager\\Configuration');
|
||||
$this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface');
|
||||
$this->signatureChecker = $this->getMock('ProxyManager\\Signature\\SignatureCheckerInterface');
|
||||
$this->classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface');
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassNameInflector')
|
||||
->will($this->returnValue($this->inflector));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getSignatureChecker')
|
||||
->will($this->returnValue($this->signatureChecker));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassSignatureGenerator')
|
||||
->will($this->returnValue($this->classSignatureGenerator));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\NullObjectFactory::__construct
|
||||
* @covers \ProxyManager\Factory\NullObjectFactory::createProxy
|
||||
* @covers \ProxyManager\Factory\NullObjectFactory::getGenerator
|
||||
*/
|
||||
public function testWillSkipAutoGeneration()
|
||||
{
|
||||
$instance = new stdClass();
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue('ProxyManagerTestAsset\\NullObjectMock'));
|
||||
|
||||
$factory = new NullObjectFactory($this->config);
|
||||
/* @var $proxy \ProxyManagerTestAsset\NullObjectMock */
|
||||
$proxy = $factory->createProxy($instance);
|
||||
|
||||
$this->assertInstanceOf('ProxyManagerTestAsset\\NullObjectMock', $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\NullObjectFactory::__construct
|
||||
* @covers \ProxyManager\Factory\NullObjectFactory::createProxy
|
||||
* @covers \ProxyManager\Factory\NullObjectFactory::getGenerator
|
||||
*
|
||||
* NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
|
||||
*/
|
||||
public function testWillTryAutoGeneration()
|
||||
{
|
||||
$instance = new stdClass();
|
||||
$proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
|
||||
$generator = $this->getMock('ProxyManager\GeneratorStrategy\\GeneratorStrategyInterface');
|
||||
$autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
|
||||
|
||||
$this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
|
||||
$this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
|
||||
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with(
|
||||
$this->callback(
|
||||
function (ClassGenerator $targetClass) use ($proxyClassName) {
|
||||
return $targetClass->getName() === $proxyClassName;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// simulate autoloading
|
||||
$autoloader
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($proxyClassName)
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () use ($proxyClassName) {
|
||||
eval(
|
||||
'class ' . $proxyClassName
|
||||
. ' extends \\ProxyManagerTestAsset\\NullObjectMock {}'
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue($proxyClassName));
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getUserClassName')
|
||||
->with('stdClass')
|
||||
->will($this->returnValue('ProxyManagerTestAsset\\NullObjectMock'));
|
||||
|
||||
$this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
|
||||
$this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
|
||||
|
||||
$factory = new NullObjectFactory($this->config);
|
||||
/* @var $proxy \ProxyManagerTestAsset\NullObjectMock */
|
||||
$proxy = $factory->createProxy($instance);
|
||||
|
||||
$this->assertInstanceOf($proxyClassName, $proxy);
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
<?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\Factory\RemoteObject\Adapter;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\RemoteObject\Adapter\Soap;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\RemoteObject\Adapter\Soap}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class BaseAdapterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\BaseAdapter::__construct
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\BaseAdapter::call
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\Soap::getServiceName
|
||||
*/
|
||||
public function testBaseAdapter()
|
||||
{
|
||||
$client = $this
|
||||
->getMockBuilder('Zend\Server\Client')
|
||||
->setMethods(array('call'))
|
||||
->getMock();
|
||||
|
||||
$adapter = $this->getMockForAbstractClass(
|
||||
'ProxyManager\\Factory\\RemoteObject\\Adapter\\BaseAdapter',
|
||||
array($client)
|
||||
);
|
||||
|
||||
$client
|
||||
->expects($this->once())
|
||||
->method('call')
|
||||
->with('foobarbaz', array('tab' => 'taz'))
|
||||
->will($this->returnValue('baz'));
|
||||
|
||||
$adapter
|
||||
->expects($this->once())
|
||||
->method('getServiceName')
|
||||
->with('foo', 'bar')
|
||||
->will($this->returnValue('foobarbaz'));
|
||||
|
||||
$this->assertSame('baz', $adapter->call('foo', 'bar', array('tab' => 'taz')));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\BaseAdapter::__construct
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\BaseAdapter::call
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\Soap::getServiceName
|
||||
*/
|
||||
public function testBaseAdapterWithServiceMap()
|
||||
{
|
||||
$client = $this
|
||||
->getMockBuilder('Zend\Server\Client')
|
||||
->setMethods(array('call'))
|
||||
->getMock();
|
||||
|
||||
$adapter = $this->getMockForAbstractClass(
|
||||
'ProxyManager\\Factory\\RemoteObject\\Adapter\\BaseAdapter',
|
||||
array($client, array('foobarbaz' => 'mapped'))
|
||||
);
|
||||
|
||||
$client
|
||||
->expects($this->once())
|
||||
->method('call')
|
||||
->with('mapped', array('tab' => 'taz'))
|
||||
->will($this->returnValue('baz'));
|
||||
|
||||
$adapter
|
||||
->expects($this->once())
|
||||
->method('getServiceName')
|
||||
->with('foo', 'bar')
|
||||
->will($this->returnValue('foobarbaz'));
|
||||
|
||||
$this->assertSame('baz', $adapter->call('foo', 'bar', array('tab' => 'taz')));
|
||||
}
|
||||
}
|
@ -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\Factory\RemoteObject\Adapter;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\RemoteObject\Adapter\JsonRpc;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\RemoteObject\Adapter\JsonRpc}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class JsonRpcTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\JsonRpc::__construct
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\JsonRpc::getServiceName
|
||||
*/
|
||||
public function testCanBuildAdapterWithJsonRpcClient()
|
||||
{
|
||||
$client = $this
|
||||
->getMockBuilder('Zend\Server\Client')
|
||||
->setMethods(array('call'))
|
||||
->getMock();
|
||||
|
||||
$adapter = new JsonRpc($client);
|
||||
|
||||
$client
|
||||
->expects($this->once())
|
||||
->method('call')
|
||||
->with('foo.bar', array('tab' => 'taz'))
|
||||
->will($this->returnValue('baz'));
|
||||
|
||||
$this->assertSame('baz', $adapter->call('foo', 'bar', array('tab' => 'taz')));
|
||||
}
|
||||
}
|
@ -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\Factory\RemoteObject\Adapter;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\RemoteObject\Adapter\Soap;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\RemoteObject\Adapter\Soap}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class SoapTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\Soap::__construct
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\Soap::getServiceName
|
||||
*/
|
||||
public function testCanBuildAdapterWithSoapRpcClient()
|
||||
{
|
||||
$client = $this
|
||||
->getMockBuilder('Zend\Server\Client')
|
||||
->setMethods(array('call'))
|
||||
->getMock();
|
||||
|
||||
$adapter = new Soap($client);
|
||||
|
||||
$client
|
||||
->expects($this->once())
|
||||
->method('call')
|
||||
->with('bar', array('tab' => 'taz'))
|
||||
->will($this->returnValue('baz'));
|
||||
|
||||
$this->assertSame('baz', $adapter->call('foo', 'bar', array('tab' => 'taz')));
|
||||
}
|
||||
}
|
@ -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\Factory\RemoteObject\Adapter;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\RemoteObject\Adapter\XmlRpc;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class XmlRpcTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc::__construct
|
||||
* @covers \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc::getServiceName
|
||||
*/
|
||||
public function testCanBuildAdapterWithXmlRpcClient()
|
||||
{
|
||||
$client = $this
|
||||
->getMockBuilder('Zend\Server\Client')
|
||||
->setMethods(array('call'))
|
||||
->getMock();
|
||||
|
||||
$adapter = new XmlRpc($client);
|
||||
|
||||
$client
|
||||
->expects($this->once())
|
||||
->method('call')
|
||||
->with('foo.bar', array('tab' => 'taz'))
|
||||
->will($this->returnValue('baz'));
|
||||
|
||||
$this->assertSame('baz', $adapter->call('foo', 'bar', array('tab' => 'taz')));
|
||||
}
|
||||
}
|
178
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php
vendored
Normal file
178
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
<?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\Factory;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\RemoteObjectFactory;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Factory\RemoteObjectFactory}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class RemoteObjectFactoryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $inflector;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $signatureChecker;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Signature\ClassSignatureGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $classSignatureGenerator;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = $this->getMock('ProxyManager\\Configuration');
|
||||
$this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface');
|
||||
$this->signatureChecker = $this->getMock('ProxyManager\\Signature\\SignatureCheckerInterface');
|
||||
$this->classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface');
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassNameInflector')
|
||||
->will($this->returnValue($this->inflector));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getSignatureChecker')
|
||||
->will($this->returnValue($this->signatureChecker));
|
||||
|
||||
$this
|
||||
->config
|
||||
->expects($this->any())
|
||||
->method('getClassSignatureGenerator')
|
||||
->will($this->returnValue($this->classSignatureGenerator));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\RemoteObjectFactory::__construct
|
||||
* @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy
|
||||
* @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator
|
||||
*/
|
||||
public function testWillSkipAutoGeneration()
|
||||
{
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with('ProxyManagerTestAsset\\BaseInterface')
|
||||
->will($this->returnValue('StdClass'));
|
||||
|
||||
$adapter = $this->getMock('ProxyManager\Factory\RemoteObject\AdapterInterface');
|
||||
$factory = new RemoteObjectFactory($adapter, $this->config);
|
||||
/* @var $proxy \stdClass */
|
||||
$proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter);
|
||||
|
||||
$this->assertInstanceOf('stdClass', $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @covers \ProxyManager\Factory\RemoteObjectFactory::__construct
|
||||
* @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy
|
||||
* @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator
|
||||
*
|
||||
* NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
|
||||
*/
|
||||
public function testWillTryAutoGeneration()
|
||||
{
|
||||
$proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
|
||||
$generator = $this->getMock('ProxyManager\GeneratorStrategy\\GeneratorStrategyInterface');
|
||||
$autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
|
||||
|
||||
$this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
|
||||
$this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
|
||||
|
||||
$generator
|
||||
->expects($this->once())
|
||||
->method('generate')
|
||||
->with(
|
||||
$this->callback(
|
||||
function (ClassGenerator $targetClass) use ($proxyClassName) {
|
||||
return $targetClass->getName() === $proxyClassName;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// simulate autoloading
|
||||
$autoloader
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($proxyClassName)
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () use ($proxyClassName) {
|
||||
eval(
|
||||
'class ' . $proxyClassName
|
||||
. ' extends stdClass {}'
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getProxyClassName')
|
||||
->with('ProxyManagerTestAsset\\BaseInterface')
|
||||
->will($this->returnValue($proxyClassName));
|
||||
|
||||
$this
|
||||
->inflector
|
||||
->expects($this->once())
|
||||
->method('getUserClassName')
|
||||
->with('ProxyManagerTestAsset\\BaseInterface')
|
||||
->will($this->returnValue('stdClass'));
|
||||
|
||||
$this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
|
||||
$this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
|
||||
|
||||
$adapter = $this->getMock('ProxyManager\Factory\RemoteObject\AdapterInterface');
|
||||
$factory = new RemoteObjectFactory($adapter, $this->config);
|
||||
/* @var $proxy \stdClass */
|
||||
$proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter);
|
||||
|
||||
$this->assertInstanceOf($proxyClassName, $proxy);
|
||||
}
|
||||
}
|
54
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/FileLocator/FileLocatorTest.php
vendored
Normal file
54
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/FileLocator/FileLocatorTest.php
vendored
Normal file
@ -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\FileLocator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\FileLocator\FileLocator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\FileLocator\FileLocator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class FileLocatorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\FileLocator\FileLocator::__construct
|
||||
* @covers \ProxyManager\FileLocator\FileLocator::getProxyFileName
|
||||
*/
|
||||
public function testGetProxyFileName()
|
||||
{
|
||||
$locator = new FileLocator(__DIR__);
|
||||
|
||||
$this->assertSame(__DIR__ . DIRECTORY_SEPARATOR . 'FooBarBaz.php', $locator->getProxyFileName('Foo\\Bar\\Baz'));
|
||||
$this->assertSame(__DIR__ . DIRECTORY_SEPARATOR . 'Foo_Bar_Baz.php', $locator->getProxyFileName('Foo_Bar_Baz'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\FileLocator\FileLocator::__construct
|
||||
*/
|
||||
public function testRejectsNonExistingDirectory()
|
||||
{
|
||||
$this->setExpectedException('ProxyManager\\Exception\\InvalidProxyDirectoryException');
|
||||
new FileLocator(__DIR__ . '/non-existing');
|
||||
}
|
||||
}
|
@ -0,0 +1,388 @@
|
||||
<?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\Functional;
|
||||
|
||||
use PHPUnit_Framework_SkippedTestError;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Exception\UnsupportedProxiedClassException;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ProxyManager\Proxy\AccessInterceptorInterface;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator;
|
||||
use ProxyManagerTestAsset\BaseClass;
|
||||
use ProxyManagerTestAsset\ClassWithPublicArrayProperty;
|
||||
use ProxyManagerTestAsset\ClassWithPublicProperties;
|
||||
use ProxyManagerTestAsset\ClassWithSelfHint;
|
||||
use ReflectionClass;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator} produced objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Functional
|
||||
* @coversNothing
|
||||
*/
|
||||
class AccessInterceptorScopeLocalizerFunctionalTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (! method_exists('Closure', 'bind')) {
|
||||
throw new PHPUnit_Framework_SkippedTestError(
|
||||
'PHP 5.3 doesn\'t support scope localization of private properties'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCalls($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */
|
||||
$proxy = new $proxyName($instance);
|
||||
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
|
||||
$listener = $this->getMock('stdClass', array('__invoke'));
|
||||
$listener
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($proxy, $proxy, $method, $params, false);
|
||||
|
||||
$proxy->setMethodPrefixInterceptor(
|
||||
$method,
|
||||
function ($proxy, $instance, $method, $params, & $returnEarly) use ($listener) {
|
||||
$listener->__invoke($proxy, $instance, $method, $params, $returnEarly);
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
|
||||
$random = uniqid();
|
||||
|
||||
$proxy->setMethodPrefixInterceptor(
|
||||
$method,
|
||||
function ($proxy, $instance, $method, $params, & $returnEarly) use ($random) {
|
||||
$returnEarly = true;
|
||||
|
||||
return $random;
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertSame($random, call_user_func_array(array($proxy, $method), $params));
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsWithSuffixListener($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */
|
||||
$proxy = new $proxyName($instance);
|
||||
$listener = $this->getMock('stdClass', array('__invoke'));
|
||||
$listener
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($proxy, $proxy, $method, $params, $expectedValue, false);
|
||||
|
||||
$proxy->setMethodSuffixInterceptor(
|
||||
$method,
|
||||
function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) use ($listener) {
|
||||
$listener->__invoke($proxy, $instance, $method, $params, $returnValue, $returnEarly);
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
|
||||
$random = uniqid();
|
||||
|
||||
$proxy->setMethodSuffixInterceptor(
|
||||
$method,
|
||||
function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) use ($random) {
|
||||
$returnEarly = true;
|
||||
|
||||
return $random;
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertSame($random, call_user_func_array(array($proxy, $method), $params));
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */
|
||||
$proxy = unserialize(serialize(new $proxyName($instance)));
|
||||
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */
|
||||
$proxy = new $proxyName($instance);
|
||||
$cloned = clone $proxy;
|
||||
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($cloned, $method), $params));
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */
|
||||
$this->assertSame($propertyValue, $proxy->$publicProperty);
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyWriteAccess($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */
|
||||
$newValue = uniqid();
|
||||
$proxy->$publicProperty = $newValue;
|
||||
|
||||
$this->assertSame($newValue, $proxy->$publicProperty);
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyExistence($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */
|
||||
$this->assertSame(isset($instance->$publicProperty), isset($proxy->$publicProperty));
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
|
||||
$instance->$publicProperty = null;
|
||||
$this->assertFalse(isset($proxy->$publicProperty));
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyUnset($instance, $proxy, $publicProperty)
|
||||
{
|
||||
$this->markTestSkipped('It is currently not possible to synchronize properties un-setting');
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface */
|
||||
unset($proxy->$publicProperty);
|
||||
|
||||
$this->assertFalse(isset($instance->$publicProperty));
|
||||
$this->assertFalse(isset($proxy->$publicProperty));
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that accessing a public property containing an array behaves like in a normal context
|
||||
*/
|
||||
public function testCanWriteToArrayKeysInPublicProperty()
|
||||
{
|
||||
$instance = new ClassWithPublicArrayProperty();
|
||||
$className = get_class($instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicArrayProperty */
|
||||
$proxy = new $proxyName($instance);
|
||||
|
||||
$proxy->arrayProperty['foo'] = 'bar';
|
||||
|
||||
$this->assertSame('bar', $proxy->arrayProperty['foo']);
|
||||
|
||||
$proxy->arrayProperty = array('tab' => 'taz');
|
||||
|
||||
$this->assertSame(array('tab' => 'taz'), $proxy->arrayProperty);
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that public properties retrieved via `__get` don't get modified in the object state
|
||||
*/
|
||||
public function testWillNotModifyRetrievedPublicProperties()
|
||||
{
|
||||
$instance = new ClassWithPublicProperties();
|
||||
$className = get_class($instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicProperties */
|
||||
$proxy = new $proxyName($instance);
|
||||
$variable = $proxy->property0;
|
||||
|
||||
$this->assertSame('property0', $variable);
|
||||
|
||||
$variable = 'foo';
|
||||
|
||||
$this->assertSame('property0', $proxy->property0);
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that public properties references retrieved via `__get` modify in the object state
|
||||
*/
|
||||
public function testWillModifyByRefRetrievedPublicProperties()
|
||||
{
|
||||
$instance = new ClassWithPublicProperties();
|
||||
$className = get_class($instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicProperties */
|
||||
$proxy = new $proxyName($instance);
|
||||
$variable = & $proxy->property0;
|
||||
|
||||
$this->assertSame('property0', $variable);
|
||||
|
||||
$variable = 'foo';
|
||||
|
||||
$this->assertSame('foo', $proxy->property0);
|
||||
$this->assertProxySynchronized($instance, $proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a proxy for the given class name, and retrieves its class name
|
||||
*
|
||||
* @param string $parentClassName
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws UnsupportedProxiedClassException
|
||||
*/
|
||||
private function generateProxy($parentClassName)
|
||||
{
|
||||
$generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
|
||||
$generator = new AccessInterceptorScopeLocalizerGenerator();
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$strategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate(new ReflectionClass($parentClassName), $generatedClass);
|
||||
$strategy->generate($generatedClass);
|
||||
|
||||
return $generatedClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a list of object | invoked method | parameters | expected result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProxyMethods()
|
||||
{
|
||||
$selfHintParam = new ClassWithSelfHint();
|
||||
|
||||
$data = array(
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicMethod',
|
||||
array(),
|
||||
'publicMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicTypeHintedMethod',
|
||||
array('param' => new \stdClass()),
|
||||
'publicTypeHintedMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicByReferenceMethod',
|
||||
array(),
|
||||
'publicByReferenceMethodDefault'
|
||||
),
|
||||
);
|
||||
|
||||
if (PHP_VERSION_ID >= 50401) {
|
||||
// PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573
|
||||
$data[] = array(
|
||||
'ProxyManagerTestAsset\\ClassWithSelfHint',
|
||||
new ClassWithSelfHint(),
|
||||
'selfHintMethod',
|
||||
array('parameter' => $selfHintParam),
|
||||
$selfHintParam
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates proxies and instances with a public property to feed to the property accessor methods
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyAccessProxies()
|
||||
{
|
||||
$instance1 = new BaseClass();
|
||||
$proxyName1 = $this->generateProxy(get_class($instance1));
|
||||
|
||||
return array(
|
||||
array(
|
||||
$instance1,
|
||||
new $proxyName1($instance1),
|
||||
'publicProperty',
|
||||
'publicPropertyDefault',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $instance
|
||||
* @param AccessInterceptorInterface $proxy
|
||||
*/
|
||||
private function assertProxySynchronized($instance, AccessInterceptorInterface $proxy)
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($instance);
|
||||
|
||||
foreach ($reflectionClass->getProperties() as $property) {
|
||||
$property->setAccessible(true);
|
||||
|
||||
$this->assertSame(
|
||||
$property->getValue($instance),
|
||||
$property->getValue($proxy),
|
||||
'Property "' . $property->getName() . '" is synchronized between instance and proxy'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,360 @@
|
||||
<?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\Functional;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator;
|
||||
use ProxyManagerTestAsset\BaseClass;
|
||||
use ProxyManagerTestAsset\ClassWithPublicArrayProperty;
|
||||
use ProxyManagerTestAsset\ClassWithPublicProperties;
|
||||
use ProxyManagerTestAsset\ClassWithSelfHint;
|
||||
use ReflectionClass;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator} produced objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Functional
|
||||
* @coversNothing
|
||||
*/
|
||||
class AccessInterceptorValueHolderFunctionalTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCalls($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */
|
||||
$proxy = new $proxyName($instance);
|
||||
|
||||
$this->assertSame($instance, $proxy->getWrappedValueHolderValue());
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
|
||||
$listener = $this->getMock('stdClass', array('__invoke'));
|
||||
$listener
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($proxy, $instance, $method, $params, false);
|
||||
|
||||
$proxy->setMethodPrefixInterceptor(
|
||||
$method,
|
||||
function ($proxy, $instance, $method, $params, & $returnEarly) use ($listener) {
|
||||
$listener->__invoke($proxy, $instance, $method, $params, $returnEarly);
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
|
||||
$random = uniqid();
|
||||
|
||||
$proxy->setMethodPrefixInterceptor(
|
||||
$method,
|
||||
function ($proxy, $instance, $method, $params, & $returnEarly) use ($random) {
|
||||
$returnEarly = true;
|
||||
|
||||
return $random;
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertSame($random, call_user_func_array(array($proxy, $method), $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsWithSuffixListener($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */
|
||||
$proxy = new $proxyName($instance);
|
||||
$listener = $this->getMock('stdClass', array('__invoke'));
|
||||
$listener
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($proxy, $instance, $method, $params, $expectedValue, false);
|
||||
|
||||
$proxy->setMethodSuffixInterceptor(
|
||||
$method,
|
||||
function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) use ($listener) {
|
||||
$listener->__invoke($proxy, $instance, $method, $params, $returnValue, $returnEarly);
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
|
||||
$random = uniqid();
|
||||
|
||||
$proxy->setMethodSuffixInterceptor(
|
||||
$method,
|
||||
function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) use ($random) {
|
||||
$returnEarly = true;
|
||||
|
||||
return $random;
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertSame($random, call_user_func_array(array($proxy, $method), $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */
|
||||
$proxy = unserialize(serialize(new $proxyName($instance)));
|
||||
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
$this->assertEquals($instance, $proxy->getWrappedValueHolderValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */
|
||||
$proxy = new $proxyName($instance);
|
||||
$cloned = clone $proxy;
|
||||
|
||||
$this->assertNotSame($proxy->getWrappedValueHolderValue(), $cloned->getWrappedValueHolderValue());
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($cloned, $method), $params));
|
||||
$this->assertEquals($instance, $cloned->getWrappedValueHolderValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */
|
||||
$this->assertSame($propertyValue, $proxy->$publicProperty);
|
||||
$this->assertEquals($instance, $proxy->getWrappedValueHolderValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyWriteAccess($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */
|
||||
$newValue = uniqid();
|
||||
$proxy->$publicProperty = $newValue;
|
||||
|
||||
$this->assertSame($newValue, $proxy->$publicProperty);
|
||||
$this->assertSame($newValue, $proxy->getWrappedValueHolderValue()->$publicProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyExistence($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */
|
||||
$this->assertSame(isset($instance->$publicProperty), isset($proxy->$publicProperty));
|
||||
$this->assertEquals($instance, $proxy->getWrappedValueHolderValue());
|
||||
|
||||
$proxy->getWrappedValueHolderValue()->$publicProperty = null;
|
||||
$this->assertFalse(isset($proxy->$publicProperty));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyUnset($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface */
|
||||
$instance = $proxy->getWrappedValueHolderValue() ? $proxy->getWrappedValueHolderValue() : $instance;
|
||||
unset($proxy->$publicProperty);
|
||||
|
||||
$this->assertFalse(isset($instance->$publicProperty));
|
||||
$this->assertFalse(isset($proxy->$publicProperty));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that accessing a public property containing an array behaves like in a normal context
|
||||
*/
|
||||
public function testCanWriteToArrayKeysInPublicProperty()
|
||||
{
|
||||
$instance = new ClassWithPublicArrayProperty();
|
||||
$className = get_class($instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicArrayProperty */
|
||||
$proxy = new $proxyName($instance);
|
||||
|
||||
$proxy->arrayProperty['foo'] = 'bar';
|
||||
|
||||
$this->assertSame('bar', $proxy->arrayProperty['foo']);
|
||||
|
||||
$proxy->arrayProperty = array('tab' => 'taz');
|
||||
|
||||
$this->assertSame(array('tab' => 'taz'), $proxy->arrayProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that public properties retrieved via `__get` don't get modified in the object state
|
||||
*/
|
||||
public function testWillNotModifyRetrievedPublicProperties()
|
||||
{
|
||||
$instance = new ClassWithPublicProperties();
|
||||
$className = get_class($instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicProperties */
|
||||
$proxy = new $proxyName($instance);
|
||||
$variable = $proxy->property0;
|
||||
|
||||
$this->assertSame('property0', $variable);
|
||||
|
||||
$variable = 'foo';
|
||||
|
||||
$this->assertSame('property0', $proxy->property0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that public properties references retrieved via `__get` modify in the object state
|
||||
*/
|
||||
public function testWillModifyByRefRetrievedPublicProperties()
|
||||
{
|
||||
$instance = new ClassWithPublicProperties();
|
||||
$className = get_class($instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicProperties */
|
||||
$proxy = new $proxyName($instance);
|
||||
$variable = & $proxy->property0;
|
||||
|
||||
$this->assertSame('property0', $variable);
|
||||
|
||||
$variable = 'foo';
|
||||
|
||||
$this->assertSame('foo', $proxy->property0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a proxy for the given class name, and retrieves its class name
|
||||
*
|
||||
* @param string $parentClassName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateProxy($parentClassName)
|
||||
{
|
||||
$generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
|
||||
$generator = new AccessInterceptorValueHolderGenerator();
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$strategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate(new ReflectionClass($parentClassName), $generatedClass);
|
||||
$strategy->generate($generatedClass);
|
||||
|
||||
return $generatedClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a list of object | invoked method | parameters | expected result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProxyMethods()
|
||||
{
|
||||
$selfHintParam = new ClassWithSelfHint();
|
||||
|
||||
$data = array(
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicMethod',
|
||||
array(),
|
||||
'publicMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicTypeHintedMethod',
|
||||
array('param' => new \stdClass()),
|
||||
'publicTypeHintedMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicByReferenceMethod',
|
||||
array(),
|
||||
'publicByReferenceMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseInterface',
|
||||
new BaseClass(),
|
||||
'publicMethod',
|
||||
array(),
|
||||
'publicMethodDefault'
|
||||
),
|
||||
);
|
||||
|
||||
if (PHP_VERSION_ID >= 50401) {
|
||||
// PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573
|
||||
$data[] = array(
|
||||
'ProxyManagerTestAsset\\ClassWithSelfHint',
|
||||
new ClassWithSelfHint(),
|
||||
'selfHintMethod',
|
||||
array('parameter' => $selfHintParam),
|
||||
$selfHintParam
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates proxies and instances with a public property to feed to the property accessor methods
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyAccessProxies()
|
||||
{
|
||||
$instance1 = new BaseClass();
|
||||
$proxyName1 = $this->generateProxy(get_class($instance1));
|
||||
$instance2 = new BaseClass();
|
||||
$proxyName2 = $this->generateProxy(get_class($instance2));
|
||||
|
||||
return array(
|
||||
array(
|
||||
$instance1,
|
||||
new $proxyName1($instance1),
|
||||
'publicProperty',
|
||||
'publicPropertyDefault',
|
||||
),
|
||||
array(
|
||||
$instance2,
|
||||
unserialize(serialize(new $proxyName2($instance2))),
|
||||
'publicProperty',
|
||||
'publicPropertyDefault',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,196 @@
|
||||
<?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\Functional;
|
||||
|
||||
/**
|
||||
* Base performance test logic for lazy loading proxies
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Performance
|
||||
* @coversNothing
|
||||
*/
|
||||
abstract class BaseLazyLoadingPerformanceTest extends BasePerformanceTest
|
||||
{
|
||||
/**
|
||||
* @param string $className
|
||||
* @param object[] $instances
|
||||
* @param \ProxyManager\Proxy\LazyLoadingInterface[] $proxies
|
||||
* @param string $methodName
|
||||
* @param array $parameters
|
||||
*/
|
||||
protected function profileMethodAccess($className, array $instances, array $proxies, $methodName, array $parameters)
|
||||
{
|
||||
$iterations = count($instances);
|
||||
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
call_user_func_array(array($instance, $methodName), $parameters);
|
||||
}
|
||||
|
||||
$baseProfile = $this->endCapturing(
|
||||
$iterations . ' calls to ' . $className . '#' . $methodName . ': %fms / %fKb'
|
||||
);
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($proxies as $proxy) {
|
||||
call_user_func_array(array($proxy, $methodName), $parameters);
|
||||
}
|
||||
|
||||
$proxyProfile = $this->endCapturing(
|
||||
$iterations . ' calls to proxied ' . $className . '#' . $methodName . ': %fms / %fKb'
|
||||
);
|
||||
$this->compareProfile($baseProfile, $proxyProfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param object[] $instances
|
||||
* @param \ProxyManager\Proxy\LazyLoadingInterface[] $proxies
|
||||
* @param string $property
|
||||
*/
|
||||
protected function profilePropertyWrites($className, array $instances, array $proxies, $property)
|
||||
{
|
||||
$iterations = count($instances);
|
||||
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
$instance->$property = 'foo';
|
||||
}
|
||||
|
||||
$baseProfile = $this->endCapturing(
|
||||
$iterations . ' writes of ' . $className . '::' . $property . ': %fms / %fKb'
|
||||
);
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($proxies as $proxy) {
|
||||
$proxy->$property = 'foo';
|
||||
}
|
||||
|
||||
$proxyProfile = $this->endCapturing(
|
||||
$iterations . ' writes of proxied ' . $className . '::' . $property . ': %fms / %fKb'
|
||||
);
|
||||
$this->compareProfile($baseProfile, $proxyProfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param object[] $instances
|
||||
* @param \ProxyManager\Proxy\LazyLoadingInterface[] $proxies
|
||||
* @param string $property
|
||||
*/
|
||||
protected function profilePropertyReads($className, array $instances, array $proxies, $property)
|
||||
{
|
||||
$iterations = count($instances);
|
||||
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
$instance->$property;
|
||||
}
|
||||
|
||||
$baseProfile = $this->endCapturing(
|
||||
$iterations . ' reads of ' . $className . '::' . $property . ': %fms / %fKb'
|
||||
);
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($proxies as $proxy) {
|
||||
$proxy->$property;
|
||||
}
|
||||
|
||||
$proxyProfile = $this->endCapturing(
|
||||
$iterations . ' reads of proxied ' . $className . '::' . $property . ': %fms / %fKb'
|
||||
);
|
||||
$this->compareProfile($baseProfile, $proxyProfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param object[] $instances
|
||||
* @param \ProxyManager\Proxy\LazyLoadingInterface[] $proxies
|
||||
* @param string $property
|
||||
*/
|
||||
protected function profilePropertyIsset($className, array $instances, array $proxies, $property)
|
||||
{
|
||||
$iterations = count($instances);
|
||||
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
isset($instance->$property);
|
||||
}
|
||||
|
||||
$baseProfile = $this->endCapturing(
|
||||
$iterations . ' isset of ' . $className . '::' . $property . ': %fms / %fKb'
|
||||
);
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($proxies as $proxy) {
|
||||
isset($proxy->$property);
|
||||
}
|
||||
|
||||
$proxyProfile = $this->endCapturing(
|
||||
$iterations . ' isset of proxied ' . $className . '::' . $property . ': %fms / %fKb'
|
||||
);
|
||||
$this->compareProfile($baseProfile, $proxyProfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param object[] $instances
|
||||
* @param \ProxyManager\Proxy\LazyLoadingInterface[] $proxies
|
||||
* @param string $property
|
||||
*/
|
||||
protected function profilePropertyUnset($className, array $instances, array $proxies, $property)
|
||||
{
|
||||
$iterations = count($instances);
|
||||
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
unset($instance->$property);
|
||||
}
|
||||
|
||||
$baseProfile = $this->endCapturing(
|
||||
$iterations . ' unset of ' . $className . '::' . $property . ': %fms / %fKb'
|
||||
);
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($proxies as $proxy) {
|
||||
unset($proxy->$property);
|
||||
}
|
||||
|
||||
$proxyProfile = $this->endCapturing(
|
||||
$iterations . ' unset of proxied ' . $className . '::' . $property . ': %fms / %fKb'
|
||||
);
|
||||
$this->compareProfile($baseProfile, $proxyProfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a proxy for the given class name, and retrieves its class name
|
||||
*
|
||||
* @param string $parentClassName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function generateProxy($parentClassName);
|
||||
}
|
101
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/BasePerformanceTest.php
vendored
Normal file
101
msd2/phpBB3/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/BasePerformanceTest.php
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
<?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\Functional;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Base performance test logic
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Performance
|
||||
* @coversNothing
|
||||
*/
|
||||
abstract class BasePerformanceTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var float time when last capture was started
|
||||
*/
|
||||
private $startTime = 0;
|
||||
|
||||
/**
|
||||
* @var int bytes when last capture was started
|
||||
*/
|
||||
private $startMemory = 0;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$header = "Performance test - " . get_called_class() . ":";
|
||||
|
||||
echo "\n\n" . str_repeat('=', strlen($header)) . "\n" . $header . "\n\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Start profiler snapshot
|
||||
*/
|
||||
protected function startCapturing()
|
||||
{
|
||||
$this->startMemory = memory_get_usage();
|
||||
$this->startTime = microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Echo current profiler output
|
||||
*
|
||||
* @param string $messageTemplate
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function endCapturing($messageTemplate)
|
||||
{
|
||||
$time = microtime(true) - $this->startTime;
|
||||
$memory = memory_get_usage() - $this->startMemory;
|
||||
|
||||
if (gc_enable()) {
|
||||
gc_collect_cycles();
|
||||
}
|
||||
|
||||
echo sprintf($messageTemplate, $time, $memory / 1024) . "\n";
|
||||
|
||||
return array(
|
||||
'time' => $time,
|
||||
'memory' => $memory
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display comparison between two profiles
|
||||
*
|
||||
* @param array $baseProfile
|
||||
* @param array $proxyProfile
|
||||
*/
|
||||
protected function compareProfile(array $baseProfile, array $proxyProfile)
|
||||
{
|
||||
$baseMemory = max(1, $baseProfile['memory']);
|
||||
$timeOverhead = (($proxyProfile['time'] / $baseProfile['time']) - 1) * 100;
|
||||
$memoryOverhead = (($proxyProfile['memory'] / $baseMemory) - 1) * 100;
|
||||
|
||||
echo sprintf('Comparison time / memory: %.2f%% / %.2f%%', $timeOverhead, $memoryOverhead) . "\n\n";
|
||||
}
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
<?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\Functional;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPUnit_Util_PHP;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Verifies that proxy-manager will not attempt to `eval()` code that will cause fatal errors
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Functional
|
||||
* @coversNothing
|
||||
*/
|
||||
class FatalPreventionFunctionalTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $template = <<<'PHP'
|
||||
<?php
|
||||
|
||||
require_once %s;
|
||||
|
||||
$className = %s;
|
||||
$generatedClass = new ProxyManager\Generator\ClassGenerator(uniqid('generated'));
|
||||
$generatorStrategy = new ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy();
|
||||
$classGenerator = new %s;
|
||||
$classSignatureGenerator = new ProxyManager\Signature\ClassSignatureGenerator(
|
||||
new ProxyManager\Signature\SignatureGenerator()
|
||||
);
|
||||
|
||||
try {
|
||||
$classGenerator->generate(new ReflectionClass($className), $generatedClass);
|
||||
$classSignatureGenerator->addSignature($generatedClass, array('eval tests'));
|
||||
$generatorStrategy->generate($generatedClass);
|
||||
} catch (ProxyManager\Exception\ExceptionInterface $e) {
|
||||
} catch (ReflectionException $e) {
|
||||
}
|
||||
|
||||
echo 'SUCCESS: ' . %s;
|
||||
PHP;
|
||||
|
||||
/**
|
||||
* Verifies that code generation and evaluation will not cause fatals with any given class
|
||||
*
|
||||
* @param string $generatorClass an instantiable class (no arguments) implementing
|
||||
* the {@see \ProxyManager\ProxyGenerator\ProxyGeneratorInterface}
|
||||
* @param string $className a valid (existing/autoloadable) class name
|
||||
*
|
||||
* @dataProvider getTestedClasses
|
||||
*/
|
||||
public function testCodeGeneration($generatorClass, $className)
|
||||
{
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('HHVM is just too slow for this kind of test right now.');
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID < 50401) {
|
||||
$this->markTestSkipped('Can\'t run this test suite on php < 5.4.1');
|
||||
}
|
||||
|
||||
$runner = PHPUnit_Util_PHP::factory();
|
||||
|
||||
$code = sprintf(
|
||||
$this->template,
|
||||
var_export(realpath(__DIR__ . '/../../../vendor/autoload.php'), true),
|
||||
var_export($className, true),
|
||||
$generatorClass,
|
||||
var_export($className, true)
|
||||
);
|
||||
|
||||
$result = $runner->runJob($code, array('-n'));
|
||||
|
||||
if (('SUCCESS: ' . $className) !== $result['stdout']) {
|
||||
$this->fail(sprintf(
|
||||
"Crashed with class '%s' and generator '%s'.\n\nStdout:\n%s\nStderr:\n%s\nGenerated code:\n%s'",
|
||||
$generatorClass,
|
||||
$className,
|
||||
$result['stdout'],
|
||||
$result['stderr'],
|
||||
$code
|
||||
));
|
||||
}
|
||||
|
||||
$this->assertSame('SUCCESS: ' . $className, $result['stdout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function getTestedClasses()
|
||||
{
|
||||
$that = $this;
|
||||
|
||||
return call_user_func_array(
|
||||
'array_merge',
|
||||
array_map(
|
||||
function ($generator) use ($that) {
|
||||
return array_map(
|
||||
function ($class) use ($generator) {
|
||||
return array($generator, $class);
|
||||
},
|
||||
$that->getProxyTestedClasses()
|
||||
);
|
||||
},
|
||||
array(
|
||||
'ProxyManager\\ProxyGenerator\\AccessInterceptorScopeLocalizerGenerator',
|
||||
'ProxyManager\\ProxyGenerator\\AccessInterceptorValueHolderGenerator',
|
||||
'ProxyManager\\ProxyGenerator\\LazyLoadingGhostGenerator',
|
||||
'ProxyManager\\ProxyGenerator\\LazyLoadingValueHolderGenerator',
|
||||
'ProxyManager\\ProxyGenerator\\NullObjectGenerator',
|
||||
'ProxyManager\\ProxyGenerator\\RemoteObjectGenerator',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (public only for PHP 5.3 compatibility)
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getProxyTestedClasses()
|
||||
{
|
||||
$skippedPaths = array(
|
||||
realpath(__DIR__ . '/../../src'),
|
||||
realpath(__DIR__ . '/../../vendor'),
|
||||
realpath(__DIR__ . '/../../tests/ProxyManagerTest'),
|
||||
);
|
||||
|
||||
return array_filter(
|
||||
get_declared_classes(),
|
||||
function ($className) use ($skippedPaths) {
|
||||
$reflectionClass = new ReflectionClass($className);
|
||||
$fileName = $reflectionClass->getFileName();
|
||||
|
||||
if (! $fileName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$realPath = realpath($fileName);
|
||||
|
||||
foreach ($skippedPaths as $skippedPath) {
|
||||
if (0 === strpos($realPath, $skippedPath)) {
|
||||
// skip classes defined within ProxyManager, vendor or the test suite
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,441 @@
|
||||
<?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\Functional;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPUnit_Framework_MockObject_MockObject as Mock;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ProxyManager\Proxy\GhostObjectInterface;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator;
|
||||
use ProxyManagerTestAsset\BaseClass;
|
||||
use ProxyManagerTestAsset\ClassWithPublicArrayProperty;
|
||||
use ProxyManagerTestAsset\ClassWithPublicProperties;
|
||||
use ProxyManagerTestAsset\ClassWithProtectedProperties;
|
||||
use ProxyManagerTestAsset\ClassWithPrivateProperties;
|
||||
use ProxyManagerTestAsset\ClassWithSelfHint;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator} produced objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Functional
|
||||
* @coversNothing
|
||||
*/
|
||||
class LazyLoadingGhostFunctionalTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCalls($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */
|
||||
$proxy = new $proxyName($this->createInitializer($className, $instance));
|
||||
|
||||
$this->assertFalse($proxy->isProxyInitialized());
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */
|
||||
$proxy = unserialize(serialize(new $proxyName($this->createInitializer($className, $instance))));
|
||||
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */
|
||||
$proxy = new $proxyName($this->createInitializer($className, $instance));
|
||||
$cloned = clone $proxy;
|
||||
|
||||
$this->assertTrue($cloned->isProxyInitialized());
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($cloned, $method), $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */
|
||||
$this->assertSame($propertyValue, $proxy->$publicProperty);
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyWriteAccess($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */
|
||||
$newValue = uniqid();
|
||||
$proxy->$publicProperty = $newValue;
|
||||
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
$this->assertSame($newValue, $proxy->$publicProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyExistence($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */
|
||||
$this->assertSame(isset($instance->$publicProperty), isset($proxy->$publicProperty));
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyAbsence($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */
|
||||
$proxy->$publicProperty = null;
|
||||
$this->assertFalse(isset($proxy->$publicProperty));
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyUnset($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */
|
||||
|
||||
unset($proxy->$publicProperty);
|
||||
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
$this->assertTrue(isset($instance->$publicProperty));
|
||||
$this->assertFalse(isset($proxy->$publicProperty));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that accessing a public property containing an array behaves like in a normal context
|
||||
*/
|
||||
public function testCanWriteToArrayKeysInPublicProperty()
|
||||
{
|
||||
$instance = new ClassWithPublicArrayProperty();
|
||||
$className = get_class($instance);
|
||||
$initializer = $this->createInitializer($className, $instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicArrayProperty */
|
||||
$proxy = new $proxyName($initializer);
|
||||
|
||||
$proxy->arrayProperty['foo'] = 'bar';
|
||||
|
||||
$this->assertSame('bar', $proxy->arrayProperty['foo']);
|
||||
|
||||
$proxy->arrayProperty = array('tab' => 'taz');
|
||||
|
||||
$this->assertSame(array('tab' => 'taz'), $proxy->arrayProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that public properties retrieved via `__get` don't get modified in the object itself
|
||||
*/
|
||||
public function testWillNotModifyRetrievedPublicProperties()
|
||||
{
|
||||
$instance = new ClassWithPublicProperties();
|
||||
$className = get_class($instance);
|
||||
$initializer = $this->createInitializer($className, $instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicProperties */
|
||||
$proxy = new $proxyName($initializer);
|
||||
$variable = $proxy->property0;
|
||||
|
||||
$this->assertSame('property0', $variable);
|
||||
|
||||
$variable = 'foo';
|
||||
|
||||
$this->assertSame('property0', $proxy->property0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that public properties references retrieved via `__get` modify in the object state
|
||||
*/
|
||||
public function testWillModifyByRefRetrievedPublicProperties()
|
||||
{
|
||||
$instance = new ClassWithPublicProperties();
|
||||
$className = get_class($instance);
|
||||
$initializer = $this->createInitializer($className, $instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicProperties */
|
||||
$proxy = new $proxyName($initializer);
|
||||
$variable = & $proxy->property0;
|
||||
|
||||
$this->assertSame('property0', $variable);
|
||||
|
||||
$variable = 'foo';
|
||||
|
||||
$this->assertSame('foo', $proxy->property0);
|
||||
}
|
||||
|
||||
public function testKeepsInitializerWhenNotOverwitten()
|
||||
{
|
||||
$instance = new BaseClass();
|
||||
$proxyName = $this->generateProxy(get_class($instance));
|
||||
$initializer = function () {
|
||||
};
|
||||
/* @var $proxy \ProxyManager\Proxy\GhostObjectInterface */
|
||||
$proxy = new $proxyName($initializer);
|
||||
|
||||
$proxy->initializeProxy();
|
||||
|
||||
$this->assertSame($initializer, $proxy->getProxyInitializer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that public properties are not being initialized multiple times
|
||||
*/
|
||||
public function testKeepsInitializedPublicProperties()
|
||||
{
|
||||
$instance = new BaseClass();
|
||||
$proxyName = $this->generateProxy(get_class($instance));
|
||||
$initializer = function (BaseClass $proxy, $method, $parameters, & $initializer) {
|
||||
$initializer = null;
|
||||
$proxy->publicProperty = 'newValue';
|
||||
};
|
||||
/* @var $proxy \ProxyManager\Proxy\GhostObjectInterface|BaseClass */
|
||||
$proxy = new $proxyName($initializer);
|
||||
|
||||
$proxy->initializeProxy();
|
||||
$this->assertSame('newValue', $proxy->publicProperty);
|
||||
|
||||
$proxy->publicProperty = 'otherValue';
|
||||
|
||||
$proxy->initializeProxy();
|
||||
|
||||
$this->assertSame('otherValue', $proxy->publicProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that properties' default values are preserved
|
||||
*/
|
||||
public function testPublicPropertyDefaultWillBePreserved()
|
||||
{
|
||||
$instance = new ClassWithPublicProperties();
|
||||
$proxyName = $this->generateProxy(get_class($instance));
|
||||
/* @var $proxy ClassWithPublicProperties */
|
||||
$proxy = new $proxyName(function () {
|
||||
});
|
||||
|
||||
$this->assertSame('property0', $proxy->property0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that protected properties' default values are preserved
|
||||
*/
|
||||
public function testProtectedPropertyDefaultWillBePreserved()
|
||||
{
|
||||
$instance = new ClassWithProtectedProperties();
|
||||
$proxyName = $this->generateProxy(get_class($instance));
|
||||
/* @var $proxy ClassWithProtectedProperties */
|
||||
$proxy = new $proxyName(function () {
|
||||
});
|
||||
|
||||
// Check protected property via reflection
|
||||
$reflectionProperty = new ReflectionProperty($instance, 'property0');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
|
||||
$this->assertSame('property0', $reflectionProperty->getValue($proxy));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that private properties' default values are preserved
|
||||
*/
|
||||
public function testPrivatePropertyDefaultWillBePreserved()
|
||||
{
|
||||
$instance = new ClassWithPrivateProperties();
|
||||
$proxyName = $this->generateProxy(get_class($instance));
|
||||
/* @var $proxy ClassWithPrivateProperties */
|
||||
$proxy = new $proxyName(function () {
|
||||
});
|
||||
|
||||
// Check protected property via reflection
|
||||
$reflectionProperty = new ReflectionProperty($instance, 'property0');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
|
||||
$this->assertSame('property0', $reflectionProperty->getValue($proxy));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a proxy for the given class name, and retrieves its class name
|
||||
*
|
||||
* @param string $parentClassName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateProxy($parentClassName)
|
||||
{
|
||||
$generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
|
||||
$generator = new LazyLoadingGhostGenerator();
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$strategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate(new ReflectionClass($parentClassName), $generatedClass);
|
||||
$strategy->generate($generatedClass);
|
||||
|
||||
return $generatedClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param object $realInstance
|
||||
* @param Mock $initializerMatcher
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
private function createInitializer($className, $realInstance, Mock $initializerMatcher = null)
|
||||
{
|
||||
if (null === $initializerMatcher) {
|
||||
$initializerMatcher = $this->getMock('stdClass', array('__invoke'));
|
||||
|
||||
$initializerMatcher
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with(
|
||||
$this->logicalAnd(
|
||||
$this->isInstanceOf('ProxyManager\\Proxy\\GhostObjectInterface'),
|
||||
$this->isInstanceOf($className)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$initializerMatcher = $initializerMatcher ?: $this->getMock('stdClass', array('__invoke'));
|
||||
|
||||
return function (
|
||||
GhostObjectInterface $proxy,
|
||||
$method,
|
||||
$params,
|
||||
& $initializer
|
||||
) use (
|
||||
$initializerMatcher,
|
||||
$realInstance
|
||||
) {
|
||||
$initializer = null;
|
||||
$reflectionClass = new ReflectionClass($realInstance);
|
||||
|
||||
foreach ($reflectionClass->getProperties() as $property) {
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($proxy, $property->getValue($realInstance));
|
||||
}
|
||||
|
||||
$initializerMatcher->__invoke($proxy, $method, $params);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a list of object | invoked method | parameters | expected result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProxyMethods()
|
||||
{
|
||||
$selfHintParam = new ClassWithSelfHint();
|
||||
|
||||
$data = array(
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicMethod',
|
||||
array(),
|
||||
'publicMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicTypeHintedMethod',
|
||||
array(new \stdClass()),
|
||||
'publicTypeHintedMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicByReferenceMethod',
|
||||
array(),
|
||||
'publicByReferenceMethodDefault'
|
||||
),
|
||||
);
|
||||
|
||||
if (PHP_VERSION_ID >= 50401) {
|
||||
// PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573
|
||||
$data[] = array(
|
||||
'ProxyManagerTestAsset\\ClassWithSelfHint',
|
||||
new ClassWithSelfHint(),
|
||||
'selfHintMethod',
|
||||
array('parameter' => $selfHintParam),
|
||||
$selfHintParam
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates proxies and instances with a public property to feed to the property accessor methods
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyAccessProxies()
|
||||
{
|
||||
$instance1 = new BaseClass();
|
||||
$proxyName1 = $this->generateProxy(get_class($instance1));
|
||||
$instance2 = new BaseClass();
|
||||
$proxyName2 = $this->generateProxy(get_class($instance2));
|
||||
|
||||
return array(
|
||||
array(
|
||||
$instance1,
|
||||
new $proxyName1($this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance1)),
|
||||
'publicProperty',
|
||||
'publicPropertyDefault',
|
||||
),
|
||||
array(
|
||||
$instance2,
|
||||
unserialize(
|
||||
serialize(new $proxyName2($this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance2)))
|
||||
),
|
||||
'publicProperty',
|
||||
'publicPropertyDefault',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
<?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\Functional;
|
||||
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ProxyManager\Proxy\GhostObjectInterface;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator} produced objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Performance
|
||||
* @coversNothing
|
||||
*/
|
||||
class LazyLoadingGhostPerformanceTest extends BaseLazyLoadingPerformanceTest
|
||||
{
|
||||
/**
|
||||
* @outputBuffering
|
||||
* @dataProvider getTestedClasses
|
||||
*
|
||||
* @param string $className
|
||||
* @param array $methods
|
||||
* @param array $properties
|
||||
* @param \ReflectionProperty[] $reflectionProperties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testProxyInstantiationPerformance(
|
||||
$className,
|
||||
array $methods,
|
||||
array $properties,
|
||||
array $reflectionProperties
|
||||
) {
|
||||
$proxyName = $this->generateProxy($className);
|
||||
$iterations = 20000;
|
||||
$instances = array();
|
||||
/* @var $proxies \ProxyManager\Proxy\GhostObjectInterface[] */
|
||||
$proxies = array();
|
||||
$realInstance = new $className();
|
||||
$initializer = function (
|
||||
GhostObjectInterface $proxy,
|
||||
$method,
|
||||
$params,
|
||||
& $initializer
|
||||
) use (
|
||||
$reflectionProperties,
|
||||
$realInstance
|
||||
) {
|
||||
$initializer = null;
|
||||
|
||||
foreach ($reflectionProperties as $reflectionProperty) {
|
||||
$reflectionProperty->setValue($proxy, $reflectionProperty->getValue($realInstance));
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
$this->startCapturing();
|
||||
|
||||
for ($i = 0; $i < $iterations; $i += 1) {
|
||||
$instances[] = new $className();
|
||||
}
|
||||
|
||||
$baseProfile = $this->endCapturing(
|
||||
'Instantiation for ' . $iterations . ' objects of type ' . $className . ': %fms / %fKb'
|
||||
);
|
||||
$this->startCapturing();
|
||||
|
||||
for ($i = 0; $i < $iterations; $i += 1) {
|
||||
$proxies[] = new $proxyName($initializer);
|
||||
}
|
||||
|
||||
$proxyProfile = $this->endCapturing(
|
||||
'Instantiation for ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb'
|
||||
);
|
||||
$this->compareProfile($baseProfile, $proxyProfile);
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($proxies as $proxy) {
|
||||
$proxy->initializeProxy();
|
||||
}
|
||||
|
||||
$this->endCapturing('Initialization of ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb');
|
||||
|
||||
foreach ($methods as $methodName => $parameters) {
|
||||
$this->profileMethodAccess($className, $instances, $proxies, $methodName, $parameters);
|
||||
}
|
||||
|
||||
foreach ($properties as $property) {
|
||||
$this->profilePropertyWrites($className, $instances, $proxies, $property);
|
||||
$this->profilePropertyReads($className, $instances, $proxies, $property);
|
||||
$this->profilePropertyIsset($className, $instances, $proxies, $property);
|
||||
$this->profilePropertyUnset($className, $instances, $proxies, $property);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTestedClasses()
|
||||
{
|
||||
$testedClasses = array(
|
||||
array('stdClass', array(), array()),
|
||||
array('ProxyManagerTestAsset\\BaseClass', array('publicMethod' => array()), array('publicProperty')),
|
||||
);
|
||||
|
||||
foreach ($testedClasses as $key => $testedClass) {
|
||||
$reflectionProperties = array();
|
||||
$reflectionClass = new ReflectionClass($testedClass[0]);
|
||||
|
||||
foreach ($reflectionClass->getProperties() as $property) {
|
||||
$property->setAccessible(true);
|
||||
|
||||
$reflectionProperties[$property->getName()] = $property;
|
||||
}
|
||||
|
||||
$testedClasses[$key][] = $reflectionProperties;
|
||||
}
|
||||
|
||||
return $testedClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function generateProxy($parentClassName)
|
||||
{
|
||||
$generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
|
||||
$generator = new LazyLoadingGhostGenerator();
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$strategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate(new ReflectionClass($parentClassName), $generatedClass);
|
||||
$strategy->generate($generatedClass);
|
||||
|
||||
return $generatedClassName;
|
||||
}
|
||||
}
|
@ -0,0 +1,386 @@
|
||||
<?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\Functional;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPUnit_Framework_MockObject_MockObject as Mock;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ProxyManager\Proxy\VirtualProxyInterface;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
|
||||
use ProxyManagerTestAsset\BaseClass;
|
||||
use ProxyManagerTestAsset\ClassWithPublicArrayProperty;
|
||||
use ProxyManagerTestAsset\ClassWithPublicProperties;
|
||||
use ProxyManagerTestAsset\ClassWithSelfHint;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator} produced objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Functional
|
||||
* @coversNothing
|
||||
*/
|
||||
class LazyLoadingValueHolderFunctionalTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCalls($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */
|
||||
$proxy = new $proxyName($this->createInitializer($className, $instance));
|
||||
|
||||
$this->assertFalse($proxy->isProxyInitialized());
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
$this->assertSame($instance, $proxy->getWrappedValueHolderValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */
|
||||
$proxy = unserialize(serialize(new $proxyName($this->createInitializer($className, $instance))));
|
||||
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
$this->assertEquals($instance, $proxy->getWrappedValueHolderValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */
|
||||
$proxy = new $proxyName($this->createInitializer($className, $instance));
|
||||
$cloned = clone $proxy;
|
||||
|
||||
$this->assertTrue($cloned->isProxyInitialized());
|
||||
$this->assertNotSame($proxy->getWrappedValueHolderValue(), $cloned->getWrappedValueHolderValue());
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($cloned, $method), $params));
|
||||
$this->assertEquals($instance, $cloned->getWrappedValueHolderValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */
|
||||
$this->assertSame($propertyValue, $proxy->$publicProperty);
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
$this->assertEquals($instance, $proxy->getWrappedValueHolderValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyWriteAccess($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */
|
||||
$newValue = uniqid();
|
||||
$proxy->$publicProperty = $newValue;
|
||||
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
$this->assertSame($newValue, $proxy->$publicProperty);
|
||||
$this->assertSame($newValue, $proxy->getWrappedValueHolderValue()->$publicProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyExistence($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */
|
||||
$this->assertSame(isset($instance->$publicProperty), isset($proxy->$publicProperty));
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
$this->assertEquals($instance, $proxy->getWrappedValueHolderValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyAbsence($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */
|
||||
$instance = $proxy->getWrappedValueHolderValue() ? $proxy->getWrappedValueHolderValue() : $instance;
|
||||
$instance->$publicProperty = null;
|
||||
$this->assertFalse(isset($proxy->$publicProperty));
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyUnset($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\VirtualProxyInterface|BaseClass */
|
||||
$instance = $proxy->getWrappedValueHolderValue() ? $proxy->getWrappedValueHolderValue() : $instance;
|
||||
unset($proxy->$publicProperty);
|
||||
|
||||
$this->assertTrue($proxy->isProxyInitialized());
|
||||
|
||||
$this->assertFalse(isset($instance->$publicProperty));
|
||||
$this->assertFalse(isset($proxy->$publicProperty));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that accessing a public property containing an array behaves like in a normal context
|
||||
*/
|
||||
public function testCanWriteToArrayKeysInPublicProperty()
|
||||
{
|
||||
$instance = new ClassWithPublicArrayProperty();
|
||||
$className = get_class($instance);
|
||||
$initializer = $this->createInitializer($className, $instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicArrayProperty */
|
||||
$proxy = new $proxyName($initializer);
|
||||
|
||||
$proxy->arrayProperty['foo'] = 'bar';
|
||||
|
||||
$this->assertSame('bar', $proxy->arrayProperty['foo']);
|
||||
|
||||
$proxy->arrayProperty = array('tab' => 'taz');
|
||||
|
||||
$this->assertSame(array('tab' => 'taz'), $proxy->arrayProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that public properties retrieved via `__get` don't get modified in the object itself
|
||||
*/
|
||||
public function testWillNotModifyRetrievedPublicProperties()
|
||||
{
|
||||
$instance = new ClassWithPublicProperties();
|
||||
$className = get_class($instance);
|
||||
$initializer = $this->createInitializer($className, $instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicProperties */
|
||||
$proxy = new $proxyName($initializer);
|
||||
$variable = $proxy->property0;
|
||||
|
||||
$this->assertSame('property0', $variable);
|
||||
|
||||
$variable = 'foo';
|
||||
|
||||
$this->assertSame('property0', $proxy->property0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that public properties references retrieved via `__get` modify in the object state
|
||||
*/
|
||||
public function testWillModifyByRefRetrievedPublicProperties()
|
||||
{
|
||||
$instance = new ClassWithPublicProperties();
|
||||
$className = get_class($instance);
|
||||
$initializer = $this->createInitializer($className, $instance);
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy ClassWithPublicProperties */
|
||||
$proxy = new $proxyName($initializer);
|
||||
$variable = & $proxy->property0;
|
||||
|
||||
$this->assertSame('property0', $variable);
|
||||
|
||||
$variable = 'foo';
|
||||
|
||||
$this->assertSame('foo', $proxy->property0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 16
|
||||
*
|
||||
* Verifies that initialization of a value holder proxy may happen multiple times
|
||||
*/
|
||||
public function testWillAllowMultipleProxyInitialization()
|
||||
{
|
||||
$proxyClass = $this->generateProxy('ProxyManagerTestAsset\\BaseClass');
|
||||
$counter = 0;
|
||||
$initializer = function (& $wrappedInstance) use (& $counter) {
|
||||
$wrappedInstance = new BaseClass();
|
||||
|
||||
$wrappedInstance->publicProperty = (string) ($counter += 1);
|
||||
};
|
||||
|
||||
/* @var $proxy BaseClass */
|
||||
$proxy = new $proxyClass($initializer);
|
||||
|
||||
$this->assertSame('1', $proxy->publicProperty);
|
||||
$this->assertSame('2', $proxy->publicProperty);
|
||||
$this->assertSame('3', $proxy->publicProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a proxy for the given class name, and retrieves its class name
|
||||
*
|
||||
* @param string $parentClassName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateProxy($parentClassName)
|
||||
{
|
||||
$generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
|
||||
$generator = new LazyLoadingValueHolderGenerator();
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$strategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate(new ReflectionClass($parentClassName), $generatedClass);
|
||||
$strategy->generate($generatedClass);
|
||||
|
||||
return $generatedClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param object $realInstance
|
||||
* @param Mock $initializerMatcher
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
private function createInitializer($className, $realInstance, Mock $initializerMatcher = null)
|
||||
{
|
||||
if (null === $initializerMatcher) {
|
||||
$initializerMatcher = $this->getMock('stdClass', array('__invoke'));
|
||||
|
||||
$initializerMatcher
|
||||
->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with(
|
||||
$this->logicalAnd(
|
||||
$this->isInstanceOf('ProxyManager\\Proxy\\VirtualProxyInterface'),
|
||||
$this->isInstanceOf($className)
|
||||
),
|
||||
$realInstance
|
||||
);
|
||||
}
|
||||
|
||||
$initializerMatcher = $initializerMatcher ?: $this->getMock('stdClass', array('__invoke'));
|
||||
|
||||
return function (
|
||||
& $wrappedObject,
|
||||
VirtualProxyInterface $proxy,
|
||||
$method,
|
||||
$params,
|
||||
& $initializer
|
||||
) use (
|
||||
$initializerMatcher,
|
||||
$realInstance
|
||||
) {
|
||||
$initializer = null;
|
||||
$wrappedObject = $realInstance;
|
||||
|
||||
$initializerMatcher->__invoke($proxy, $wrappedObject, $method, $params);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a list of object | invoked method | parameters | expected result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProxyMethods()
|
||||
{
|
||||
$selfHintParam = new ClassWithSelfHint();
|
||||
|
||||
$data = array(
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicMethod',
|
||||
array(),
|
||||
'publicMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicTypeHintedMethod',
|
||||
array(new \stdClass()),
|
||||
'publicTypeHintedMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicByReferenceMethod',
|
||||
array(),
|
||||
'publicByReferenceMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseInterface',
|
||||
new BaseClass(),
|
||||
'publicMethod',
|
||||
array(),
|
||||
'publicMethodDefault'
|
||||
),
|
||||
);
|
||||
|
||||
if (PHP_VERSION_ID >= 50401) {
|
||||
// PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573
|
||||
$data[] = array(
|
||||
'ProxyManagerTestAsset\\ClassWithSelfHint',
|
||||
new ClassWithSelfHint(),
|
||||
'selfHintMethod',
|
||||
array('parameter' => $selfHintParam),
|
||||
$selfHintParam
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates proxies and instances with a public property to feed to the property accessor methods
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyAccessProxies()
|
||||
{
|
||||
$instance1 = new BaseClass();
|
||||
$proxyName1 = $this->generateProxy(get_class($instance1));
|
||||
$instance2 = new BaseClass();
|
||||
$proxyName2 = $this->generateProxy(get_class($instance2));
|
||||
|
||||
return array(
|
||||
array(
|
||||
$instance1,
|
||||
new $proxyName1($this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance1)),
|
||||
'publicProperty',
|
||||
'publicPropertyDefault',
|
||||
),
|
||||
array(
|
||||
$instance2,
|
||||
unserialize(
|
||||
serialize(new $proxyName2($this->createInitializer('ProxyManagerTestAsset\\BaseClass', $instance2)))
|
||||
),
|
||||
'publicProperty',
|
||||
'publicPropertyDefault',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
<?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\Functional;
|
||||
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ProxyManager\Proxy\VirtualProxyInterface;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator} produced objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Performance
|
||||
* @coversNothing
|
||||
*/
|
||||
class LazyLoadingValueHolderPerformanceTest extends BaseLazyLoadingPerformanceTest
|
||||
{
|
||||
/**
|
||||
* @outputBuffering
|
||||
* @dataProvider getTestedClasses
|
||||
*
|
||||
* @param string $className
|
||||
* @param array $methods
|
||||
* @param array $properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testProxyInstantiationPerformance($className, array $methods, array $properties)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
$iterations = 20000;
|
||||
$instances = array();
|
||||
/* @var $proxies \ProxyManager\Proxy\VirtualProxyInterface[] */
|
||||
$proxies = array();
|
||||
$initializer = function (
|
||||
& $valueHolder,
|
||||
VirtualProxyInterface $proxy,
|
||||
$method,
|
||||
$params,
|
||||
& $initializer
|
||||
) use ($className) {
|
||||
$initializer = null;
|
||||
$valueHolder = new $className();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
$this->startCapturing();
|
||||
|
||||
for ($i = 0; $i < $iterations; $i += 1) {
|
||||
$instances[] = new $className();
|
||||
}
|
||||
|
||||
$baseProfile = $this->endCapturing(
|
||||
'Instantiation for ' . $iterations . ' objects of type ' . $className . ': %fms / %fKb'
|
||||
);
|
||||
$this->startCapturing();
|
||||
|
||||
for ($i = 0; $i < $iterations; $i += 1) {
|
||||
$proxies[] = new $proxyName($initializer);
|
||||
}
|
||||
|
||||
$proxyProfile = $this->endCapturing(
|
||||
'Instantiation for ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb'
|
||||
);
|
||||
$this->compareProfile($baseProfile, $proxyProfile);
|
||||
$this->startCapturing();
|
||||
|
||||
foreach ($proxies as $proxy) {
|
||||
$proxy->initializeProxy();
|
||||
}
|
||||
|
||||
$this->endCapturing('Initialization of ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb');
|
||||
|
||||
foreach ($methods as $methodName => $parameters) {
|
||||
$this->profileMethodAccess($className, $instances, $proxies, $methodName, $parameters);
|
||||
}
|
||||
|
||||
foreach ($properties as $property) {
|
||||
$this->profilePropertyWrites($className, $instances, $proxies, $property);
|
||||
$this->profilePropertyReads($className, $instances, $proxies, $property);
|
||||
$this->profilePropertyIsset($className, $instances, $proxies, $property);
|
||||
$this->profilePropertyUnset($className, $instances, $proxies, $property);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTestedClasses()
|
||||
{
|
||||
return array(
|
||||
array('stdClass', array(), array()),
|
||||
array('ProxyManagerTestAsset\\BaseClass', array('publicMethod' => array()), array('publicProperty')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function generateProxy($parentClassName)
|
||||
{
|
||||
$generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
|
||||
$generator = new LazyLoadingValueHolderGenerator();
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$strategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate(new ReflectionClass($parentClassName), $generatedClass);
|
||||
$strategy->generate($generatedClass);
|
||||
|
||||
return $generatedClassName;
|
||||
}
|
||||
}
|
@ -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\Functional;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory;
|
||||
use ProxyManager\Factory\AccessInterceptorValueHolderFactory;
|
||||
use ProxyManager\Factory\LazyLoadingGhostFactory;
|
||||
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Verifies that proxy factories don't conflict with each other when generating proxies
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @link https://github.com/Ocramius/ProxyManager/issues/10
|
||||
*
|
||||
* @group Functional
|
||||
* @group issue-10
|
||||
* @coversNothing
|
||||
*/
|
||||
class MultipleProxyGenerationTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Verifies that proxies generated from different factories will retain their specific implementation
|
||||
* and won't conflict
|
||||
*
|
||||
* @dataProvider getTestedClasses
|
||||
*/
|
||||
public function testCanGenerateMultipleDifferentProxiesForSameClass($className)
|
||||
{
|
||||
$skipScopeLocalizerTests = false;
|
||||
$ghostProxyFactory = new LazyLoadingGhostFactory();
|
||||
$virtualProxyFactory = new LazyLoadingValueHolderFactory();
|
||||
$accessInterceptorFactory = new AccessInterceptorValueHolderFactory();
|
||||
$accessInterceptorScopeLocalizerFactory = new AccessInterceptorScopeLocalizerFactory();
|
||||
$initializer = function () {
|
||||
};
|
||||
|
||||
$reflectionClass = new ReflectionClass($className);
|
||||
|
||||
if ((! method_exists('Closure', 'bind')) && $reflectionClass->getProperties(ReflectionProperty::IS_PRIVATE)) {
|
||||
$skipScopeLocalizerTests = true;
|
||||
}
|
||||
|
||||
$generated = array(
|
||||
$ghostProxyFactory->createProxy($className, $initializer),
|
||||
$virtualProxyFactory->createProxy($className, $initializer),
|
||||
$accessInterceptorFactory->createProxy(new $className()),
|
||||
);
|
||||
|
||||
if (! $skipScopeLocalizerTests) {
|
||||
$generated[] = $accessInterceptorScopeLocalizerFactory->createProxy(new $className());
|
||||
}
|
||||
|
||||
foreach ($generated as $key => $proxy) {
|
||||
$this->assertInstanceOf($className, $proxy);
|
||||
|
||||
foreach ($generated as $comparedKey => $comparedProxy) {
|
||||
if ($comparedKey === $key) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertNotSame(get_class($comparedProxy), get_class($proxy));
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertInstanceOf('ProxyManager\Proxy\GhostObjectInterface', $generated[0]);
|
||||
$this->assertInstanceOf('ProxyManager\Proxy\VirtualProxyInterface', $generated[1]);
|
||||
$this->assertInstanceOf('ProxyManager\Proxy\AccessInterceptorInterface', $generated[2]);
|
||||
$this->assertInstanceOf('ProxyManager\Proxy\ValueHolderInterface', $generated[2]);
|
||||
|
||||
if (! $skipScopeLocalizerTests) {
|
||||
$this->assertInstanceOf('ProxyManager\Proxy\AccessInterceptorInterface', $generated[3]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function getTestedClasses()
|
||||
{
|
||||
$data = array(
|
||||
array('ProxyManagerTestAsset\\BaseClass'),
|
||||
array('ProxyManagerTestAsset\\ClassWithMagicMethods'),
|
||||
array('ProxyManagerTestAsset\\ClassWithFinalMethods'),
|
||||
array('ProxyManagerTestAsset\\ClassWithFinalMagicMethods'),
|
||||
array('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'),
|
||||
array('ProxyManagerTestAsset\\ClassWithMixedProperties'),
|
||||
array('ProxyManagerTestAsset\\ClassWithPrivateProperties'),
|
||||
array('ProxyManagerTestAsset\\ClassWithProtectedProperties'),
|
||||
array('ProxyManagerTestAsset\\ClassWithPublicProperties'),
|
||||
array('ProxyManagerTestAsset\\EmptyClass'),
|
||||
array('ProxyManagerTestAsset\\HydratedObject'),
|
||||
);
|
||||
|
||||
if (PHP_VERSION_ID >= 50401) {
|
||||
// PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573
|
||||
$data[] = array('ProxyManagerTestAsset\\ClassWithSelfHint');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -0,0 +1,223 @@
|
||||
<?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\Functional;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ProxyManager\ProxyGenerator\NullObjectGenerator;
|
||||
use ProxyManagerTestAsset\BaseClass;
|
||||
use ProxyManagerTestAsset\ClassWithSelfHint;
|
||||
use ReflectionClass;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\NullObjectGenerator} produced objects
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Functional
|
||||
* @coversNothing
|
||||
*/
|
||||
class NullObjectFunctionalTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCalls($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\NullObjectInterface */
|
||||
$proxy = new $proxyName();
|
||||
|
||||
$this->assertSame(null, call_user_func_array(array($proxy, $method), $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
/* @var $proxy \ProxyManager\Proxy\NullObjectInterface */
|
||||
$proxy = unserialize(serialize(new $proxyName()));
|
||||
|
||||
$this->assertSame(null, call_user_func_array(array($proxy, $method), $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($className);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\NullObjectInterface */
|
||||
$proxy = new $proxyName();
|
||||
$cloned = clone $proxy;
|
||||
|
||||
$this->assertSame(null, call_user_func_array(array($cloned, $method), $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\NullObjectInterface */
|
||||
$this->assertSame(null, $proxy->$publicProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyWriteAccess($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\NullObjectInterface */
|
||||
$newValue = uniqid();
|
||||
$proxy->$publicProperty = $newValue;
|
||||
|
||||
$this->assertSame($newValue, $proxy->$publicProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyExistence($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\NullObjectInterface */
|
||||
$this->assertSame(null, $proxy->$publicProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testPropertyUnset($instance, $proxy, $publicProperty)
|
||||
{
|
||||
/* @var $proxy \ProxyManager\Proxy\NullObjectInterface */
|
||||
unset($proxy->$publicProperty);
|
||||
|
||||
$this->assertTrue(isset($instance->$publicProperty));
|
||||
$this->assertFalse(isset($proxy->$publicProperty));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a proxy for the given class name, and retrieves its class name
|
||||
*
|
||||
* @param string $parentClassName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateProxy($parentClassName)
|
||||
{
|
||||
$generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
|
||||
$generator = new NullObjectGenerator();
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$strategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate(new ReflectionClass($parentClassName), $generatedClass);
|
||||
$strategy->generate($generatedClass);
|
||||
|
||||
return $generatedClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a list of object | invoked method | parameters | expected result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProxyMethods()
|
||||
{
|
||||
$selfHintParam = new ClassWithSelfHint();
|
||||
|
||||
$data = array(
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicMethod',
|
||||
array(),
|
||||
'publicMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicTypeHintedMethod',
|
||||
array('param' => new \stdClass()),
|
||||
'publicTypeHintedMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
new BaseClass(),
|
||||
'publicByReferenceMethod',
|
||||
array(),
|
||||
'publicByReferenceMethodDefault'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\\BaseInterface',
|
||||
new BaseClass(),
|
||||
'publicMethod',
|
||||
array(),
|
||||
'publicMethodDefault'
|
||||
),
|
||||
);
|
||||
|
||||
if (PHP_VERSION_ID >= 50401) {
|
||||
// PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573
|
||||
$data[] = array(
|
||||
'ProxyManagerTestAsset\\ClassWithSelfHint',
|
||||
new ClassWithSelfHint(),
|
||||
'selfHintMethod',
|
||||
array('parameter' => $selfHintParam),
|
||||
$selfHintParam
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates proxies and instances with a public property to feed to the property accessor methods
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyAccessProxies()
|
||||
{
|
||||
$instance1 = new BaseClass();
|
||||
$proxyName1 = $this->generateProxy(get_class($instance1));
|
||||
$instance2 = new BaseClass();
|
||||
$proxyName2 = $this->generateProxy(get_class($instance2));
|
||||
|
||||
return array(
|
||||
array(
|
||||
$instance1,
|
||||
new $proxyName1($instance1),
|
||||
'publicProperty',
|
||||
'publicPropertyDefault',
|
||||
),
|
||||
array(
|
||||
$instance2,
|
||||
unserialize(serialize(new $proxyName2($instance2))),
|
||||
'publicProperty',
|
||||
'publicPropertyDefault',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,231 @@
|
||||
<?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\Functional;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Factory\RemoteObject\Adapter\JsonRpc as JsonRpcAdapter;
|
||||
use ProxyManager\Factory\RemoteObject\Adapter\XmlRpc as XmlRpcAdapter;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
use ProxyManager\ProxyGenerator\RemoteObjectGenerator;
|
||||
use ProxyManagerTestAsset\ClassWithSelfHint;
|
||||
use ProxyManagerTestAsset\RemoteProxy\Foo;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\ProxyGenerator\RemoteObjectGenerator} produced objects
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Functional
|
||||
* @coversNothing
|
||||
*/
|
||||
class RemoteObjectFunctionalTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @param mixed $expectedValue
|
||||
* @param string $method
|
||||
* @param array $params
|
||||
*
|
||||
* @return XmlRpcAdapter
|
||||
*/
|
||||
protected function getXmlRpcAdapter($expectedValue, $method, array $params)
|
||||
{
|
||||
$client = $this
|
||||
->getMockBuilder('Zend\Server\Client')
|
||||
->setMethods(array('call'))
|
||||
->getMock();
|
||||
|
||||
$client
|
||||
->expects($this->any())
|
||||
->method('call')
|
||||
->with($this->stringEndsWith($method), $params)
|
||||
->will($this->returnValue($expectedValue));
|
||||
|
||||
$adapter = new XmlRpcAdapter(
|
||||
$client,
|
||||
array(
|
||||
'ProxyManagerTestAsset\RemoteProxy\Foo.foo'
|
||||
=> 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface.foo'
|
||||
)
|
||||
);
|
||||
|
||||
return $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $expectedValue
|
||||
* @param string $method
|
||||
* @param array $params
|
||||
*
|
||||
* @return JsonRpcAdapter
|
||||
*/
|
||||
protected function getJsonRpcAdapter($expectedValue, $method, array $params)
|
||||
{
|
||||
$client = $this
|
||||
->getMockBuilder('Zend\Server\Client')
|
||||
->setMethods(array('call'))
|
||||
->getMock();
|
||||
|
||||
$client
|
||||
->expects($this->any())
|
||||
->method('call')
|
||||
->with($this->stringEndsWith($method), $params)
|
||||
->will($this->returnValue($expectedValue));
|
||||
|
||||
$adapter = new JsonRpcAdapter(
|
||||
$client,
|
||||
array(
|
||||
'ProxyManagerTestAsset\RemoteProxy\Foo.foo'
|
||||
=> 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface.foo'
|
||||
)
|
||||
);
|
||||
|
||||
return $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testXmlRpcMethodCalls($instanceOrClassname, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($instanceOrClassname);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */
|
||||
$proxy = new $proxyName($this->getXmlRpcAdapter($expectedValue, $method, $params));
|
||||
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProxyMethods
|
||||
*/
|
||||
public function testJsonRpcMethodCalls($instanceOrClassname, $method, $params, $expectedValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($instanceOrClassname);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */
|
||||
$proxy = new $proxyName($this->getJsonRpcAdapter($expectedValue, $method, $params));
|
||||
|
||||
$this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPropertyAccessProxies
|
||||
*/
|
||||
public function testJsonRpcPropertyReadAccess($instanceOrClassname, $publicProperty, $propertyValue)
|
||||
{
|
||||
$proxyName = $this->generateProxy($instanceOrClassname);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */
|
||||
$proxy = new $proxyName(
|
||||
$this->getJsonRpcAdapter($propertyValue, '__get', array($publicProperty))
|
||||
);
|
||||
|
||||
/* @var $proxy \ProxyManager\Proxy\NullObjectInterface */
|
||||
$this->assertSame($propertyValue, $proxy->$publicProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a proxy for the given class name, and retrieves its class name
|
||||
*
|
||||
* @param string $parentClassName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateProxy($parentClassName)
|
||||
{
|
||||
$generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
|
||||
$generator = new RemoteObjectGenerator();
|
||||
$generatedClass = new ClassGenerator($generatedClassName);
|
||||
$strategy = new EvaluatingGeneratorStrategy();
|
||||
|
||||
$generator->generate(new ReflectionClass($parentClassName), $generatedClass);
|
||||
$strategy->generate($generatedClass);
|
||||
|
||||
return $generatedClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a list of object | invoked method | parameters | expected result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProxyMethods()
|
||||
{
|
||||
$selfHintParam = new ClassWithSelfHint();
|
||||
|
||||
$data = array(
|
||||
array(
|
||||
'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface',
|
||||
'foo',
|
||||
array(),
|
||||
'bar remote'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\RemoteProxy\Foo',
|
||||
'foo',
|
||||
array(),
|
||||
'bar remote'
|
||||
),
|
||||
array(
|
||||
new Foo(),
|
||||
'foo',
|
||||
array(),
|
||||
'bar remote'
|
||||
),
|
||||
array(
|
||||
'ProxyManagerTestAsset\RemoteProxy\BazServiceInterface',
|
||||
'baz',
|
||||
array('baz'),
|
||||
'baz remote'
|
||||
),
|
||||
);
|
||||
|
||||
if (PHP_VERSION_ID >= 50401) {
|
||||
// PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573
|
||||
$data[] = array(
|
||||
new ClassWithSelfHint(),
|
||||
'selfHintMethod',
|
||||
array($selfHintParam),
|
||||
$selfHintParam
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates proxies and instances with a public property to feed to the property accessor methods
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyAccessProxies()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface',
|
||||
'publicProperty',
|
||||
'publicProperty remote',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -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\Generator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Generator\ClassGenerator}
|
||||
*
|
||||
* @author Gordon Stratton <gordon.stratton@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class ClassGeneratorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\Generator\ClassGenerator::setExtendedClass
|
||||
*/
|
||||
public function testExtendedClassesAreFQCNs()
|
||||
{
|
||||
$desiredFqcn = '\\stdClass';
|
||||
$classNameInputs = array('stdClass', '\\stdClass\\');
|
||||
|
||||
foreach ($classNameInputs as $className) {
|
||||
$classGenerator = new ClassGenerator();
|
||||
$classGenerator->setExtendedClass($className);
|
||||
|
||||
$this->assertEquals($desiredFqcn, $classGenerator->getExtendedClass());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Generator\ClassGenerator::setImplementedInterfaces
|
||||
*/
|
||||
public function testImplementedInterfacesAreFQCNs()
|
||||
{
|
||||
$desiredFqcns = array('\\Countable');
|
||||
$interfaceNameInputs = array(array('Countable'), array('\\Countable\\'));
|
||||
|
||||
foreach ($interfaceNameInputs as $interfaceNames) {
|
||||
$classGenerator = new ClassGenerator();
|
||||
$classGenerator->setImplementedInterfaces($interfaceNames);
|
||||
|
||||
$this->assertEquals($desiredFqcns, $classGenerator->getImplementedInterfaces());
|
||||
}
|
||||
}
|
||||
}
|
@ -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\Generator;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Generator\MagicMethodGenerator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class MagicMethodGeneratorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\Generator\MagicMethodGenerator::__construct
|
||||
*/
|
||||
public function testGeneratesCorrectByRefReturnValue()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithByRefMagicMethods');
|
||||
$magicMethod = new MagicMethodGenerator($reflection, '__get', array('name'));
|
||||
|
||||
$this->assertTrue($magicMethod->returnsReference());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Generator\MagicMethodGenerator::__construct
|
||||
*/
|
||||
public function testGeneratesCorrectByValReturnValue()
|
||||
{
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
|
||||
$magicMethod = new MagicMethodGenerator($reflection, '__get', array('name'));
|
||||
|
||||
$this->assertFalse($magicMethod->returnsReference());
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
<?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\Generator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Generator\MethodGenerator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\Generator\MethodGenerator
|
||||
* @group Coverage
|
||||
*/
|
||||
class MethodGeneratorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGenerateSimpleMethod()
|
||||
{
|
||||
$methodGenerator = new MethodGenerator();
|
||||
|
||||
$methodGenerator->setReturnsReference(true);
|
||||
$methodGenerator->setName('methodName');
|
||||
$methodGenerator->setVisibility('protected');
|
||||
$methodGenerator->setBody('/* body */');
|
||||
$methodGenerator->setDocBlock('docBlock');
|
||||
$methodGenerator->setParameter(new ParameterGenerator('foo'));
|
||||
|
||||
$this->assertSame(true, $methodGenerator->returnsReference());
|
||||
$this->assertStringMatchesFormat(
|
||||
'%a/**%adocBlock%a*/%aprotected function & methodName($foo)%a{%a/* body */%a}',
|
||||
$methodGenerator->generate()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that building from reflection works
|
||||
*/
|
||||
public function testGenerateFromReflection()
|
||||
{
|
||||
$method = MethodGenerator::fromReflection(new MethodReflection(__CLASS__, __FUNCTION__));
|
||||
|
||||
$this->assertSame(__FUNCTION__, $method->getName());
|
||||
$this->assertSame(MethodGenerator::VISIBILITY_PUBLIC, $method->getVisibility());
|
||||
$this->assertFalse($method->isStatic());
|
||||
$this->assertSame('Verify that building from reflection works', $method->getDocBlock()->getShortDescription());
|
||||
|
||||
$method = MethodGenerator::fromReflection(
|
||||
new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'protectedMethod')
|
||||
);
|
||||
|
||||
$this->assertSame(MethodGenerator::VISIBILITY_PROTECTED, $method->getVisibility());
|
||||
|
||||
$method = MethodGenerator::fromReflection(
|
||||
new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'privateMethod')
|
||||
);
|
||||
|
||||
$this->assertSame(MethodGenerator::VISIBILITY_PRIVATE, $method->getVisibility());
|
||||
}
|
||||
|
||||
public function testGeneratedParametersFromReflection()
|
||||
{
|
||||
$method = MethodGenerator::fromReflection(new MethodReflection(
|
||||
'ProxyManagerTestAsset\\BaseClass',
|
||||
'publicTypeHintedMethod'
|
||||
));
|
||||
|
||||
$this->assertSame('publicTypeHintedMethod', $method->getName());
|
||||
|
||||
$parameters = $method->getParameters();
|
||||
|
||||
$this->assertCount(1, $parameters);
|
||||
|
||||
$param = $parameters['param'];
|
||||
|
||||
$this->assertSame('stdClass', $param->getType());
|
||||
}
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
<?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\Generator;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use Zend\Code\Reflection\ParameterReflection;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Generator\ParameterGenerator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers \ProxyManager\Generator\ParameterGenerator
|
||||
* @group Coverage
|
||||
*/
|
||||
class ParameterGeneratorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGeneratesProperTypeHint()
|
||||
{
|
||||
$generator = new ParameterGenerator('foo');
|
||||
|
||||
$generator->setType('array');
|
||||
$this->assertSame('array $foo', $generator->generate());
|
||||
|
||||
$generator->setType('stdClass');
|
||||
$this->assertSame('\\stdClass $foo', $generator->generate());
|
||||
|
||||
$generator->setType('\\fooClass');
|
||||
$this->assertSame('\\fooClass $foo', $generator->generate());
|
||||
}
|
||||
|
||||
public function testGeneratesMethodWithCallableType()
|
||||
{
|
||||
if (PHP_VERSION_ID < 50400) {
|
||||
$this->markTestSkipped('`callable` is only supported in PHP >=5.4.0');
|
||||
}
|
||||
|
||||
$generator = new ParameterGenerator();
|
||||
|
||||
$generator->setType('callable');
|
||||
$generator->setName('foo');
|
||||
|
||||
$this->assertSame('callable $foo', $generator->generate());
|
||||
}
|
||||
|
||||
public function testVisitMethodWithCallable()
|
||||
{
|
||||
if (PHP_VERSION_ID < 50400) {
|
||||
$this->markTestSkipped('`callable` is only supported in PHP >=5.4.0');
|
||||
}
|
||||
|
||||
$parameter = new ParameterReflection(
|
||||
array('ProxyManagerTestAsset\\CallableTypeHintClass', 'callableTypeHintMethod'),
|
||||
'parameter'
|
||||
);
|
||||
|
||||
$generator = ParameterGenerator::fromReflection($parameter);
|
||||
|
||||
$this->assertSame('callable', $generator->getType());
|
||||
}
|
||||
|
||||
public function testReadsParameterDefaults()
|
||||
{
|
||||
$parameter = ParameterGenerator::fromReflection(new ParameterReflection(
|
||||
array(
|
||||
'ProxyManagerTestAsset\\ClassWithMethodWithDefaultParameters',
|
||||
'publicMethodWithDefaults'
|
||||
),
|
||||
'parameter'
|
||||
));
|
||||
|
||||
/* @var $defaultValue \Zend\Code\Generator\ValueGenerator */
|
||||
$defaultValue = $parameter->getDefaultValue();
|
||||
|
||||
$this->assertInstanceOf('Zend\\Code\\Generator\\ValueGenerator', $defaultValue);
|
||||
$this->assertSame(array('foo'), $defaultValue->getValue());
|
||||
|
||||
$this->assertStringMatchesFormat('array%a$parameter%a=%aarray(\'foo\')', $parameter->generate());
|
||||
}
|
||||
|
||||
public function testReadsParameterTypeHint()
|
||||
{
|
||||
$parameter = ParameterGenerator::fromReflection(new ParameterReflection(
|
||||
array('ProxyManagerTestAsset\\BaseClass', 'publicTypeHintedMethod'),
|
||||
'param'
|
||||
));
|
||||
|
||||
$this->assertSame('stdClass', $parameter->getType());
|
||||
}
|
||||
|
||||
public function testGeneratesParameterPassedByReference()
|
||||
{
|
||||
$parameter = new ParameterGenerator('foo');
|
||||
|
||||
$parameter->setPassedByReference(true);
|
||||
|
||||
$this->assertStringMatchesFormat('&%A$foo', $parameter->generate());
|
||||
}
|
||||
|
||||
public function testGeneratesDefaultParameterForInternalPhpClasses()
|
||||
{
|
||||
$parameter = ParameterGenerator::fromReflection(new ParameterReflection(
|
||||
array(
|
||||
'Phar',
|
||||
'compress'
|
||||
),
|
||||
1
|
||||
));
|
||||
|
||||
$this->assertSame('null', strtolower((string) $parameter->getDefaultValue()));
|
||||
}
|
||||
|
||||
public function testGeneratedParametersAreProperlyEscaped()
|
||||
{
|
||||
$parameter = new ParameterGenerator();
|
||||
|
||||
$parameter->setName('foo');
|
||||
$parameter->setDefaultValue('\'bar\\baz');
|
||||
|
||||
$this->assertThat(
|
||||
$parameter->generate(),
|
||||
$this->logicalOr(
|
||||
$this->equalTo('$foo = \'\\\'bar\\baz\''),
|
||||
$this->equalTo('$foo = \'\\\'bar\\\\baz\'')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -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\Generator\Util;
|
||||
|
||||
use ReflectionClass;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\Util\ClassGeneratorUtils;
|
||||
|
||||
/**
|
||||
* Test to {@see ProxyManager\Generator\Util\ClassGeneratorUtils}
|
||||
*
|
||||
* @author Jefersson Nathan <malukenho@phpse.net>
|
||||
* @license MIT
|
||||
*
|
||||
* @covers ProxyManager\Generator\Util\ClassGeneratorUtils
|
||||
*/
|
||||
class ClassGeneratorUtilsTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCantAddAFinalMethod()
|
||||
{
|
||||
$classGenerator = $this->getMock('Zend\\Code\\Generator\\ClassGenerator');
|
||||
$methodGenerator = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
|
||||
$methodGenerator
|
||||
->expects($this->once())
|
||||
->method('getName')
|
||||
->willReturn('foo');
|
||||
|
||||
$classGenerator
|
||||
->expects($this->never())
|
||||
->method('addMethodFromGenerator');
|
||||
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithFinalMethods');
|
||||
|
||||
ClassGeneratorUtils::addMethodIfNotFinal($reflection, $classGenerator, $methodGenerator);
|
||||
}
|
||||
|
||||
public function testCanAddANotFinalMethod()
|
||||
{
|
||||
$classGenerator = $this->getMock('Zend\\Code\\Generator\\ClassGenerator');
|
||||
$methodGenerator = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
|
||||
|
||||
$methodGenerator
|
||||
->expects($this->once())
|
||||
->method('getName')
|
||||
->willReturn('publicMethod');
|
||||
|
||||
$classGenerator
|
||||
->expects($this->once())
|
||||
->method('addMethodFromGenerator');
|
||||
|
||||
$reflection = new ReflectionClass('ProxyManagerTestAsset\\BaseClass');
|
||||
|
||||
ClassGeneratorUtils::addMethodIfNotFinal($reflection, $classGenerator, $methodGenerator);
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
<?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\Generator\Util;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Generator\Util\UniqueIdentifierGenerator}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class UniqueIdentifierGeneratorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getBaseIdentifierNames
|
||||
*
|
||||
* @covers \ProxyManager\Generator\Util\UniqueIdentifierGenerator::getIdentifier
|
||||
*/
|
||||
public function testGeneratesUniqueIdentifiers($name)
|
||||
{
|
||||
$this->assertNotSame(
|
||||
UniqueIdentifierGenerator::getIdentifier($name),
|
||||
UniqueIdentifierGenerator::getIdentifier($name)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getBaseIdentifierNames
|
||||
*
|
||||
* @covers \ProxyManager\Generator\Util\UniqueIdentifierGenerator::getIdentifier
|
||||
*/
|
||||
public function testGeneratesValidIdentifiers($name)
|
||||
{
|
||||
$this->assertRegExp(
|
||||
'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/',
|
||||
UniqueIdentifierGenerator::getIdentifier($name)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider generating identifier names to be checked
|
||||
*
|
||||
* @return string[][]
|
||||
*/
|
||||
public function getBaseIdentifierNames()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('1'),
|
||||
array('foo'),
|
||||
array('Foo'),
|
||||
array('bar'),
|
||||
array('Bar'),
|
||||
array('foo_bar'),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?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\GeneratorStrategy;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\GeneratorStrategy\BaseGeneratorStrategy}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class BaseGeneratorStrategyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\GeneratorStrategy\BaseGeneratorStrategy::generate
|
||||
*/
|
||||
public function testGenerate()
|
||||
{
|
||||
$strategy = new BaseGeneratorStrategy();
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('Foo');
|
||||
$classGenerator = new ClassGenerator($className);
|
||||
$generated = $strategy->generate($classGenerator);
|
||||
|
||||
$this->assertGreaterThan(0, strpos($generated, $className));
|
||||
}
|
||||
}
|
@ -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\GeneratorStrategy;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class EvaluatingGeneratorStrategyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::generate
|
||||
* @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::__construct
|
||||
*/
|
||||
public function testGenerate()
|
||||
{
|
||||
$strategy = new EvaluatingGeneratorStrategy();
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('Foo');
|
||||
$classGenerator = new ClassGenerator($className);
|
||||
$generated = $strategy->generate($classGenerator);
|
||||
|
||||
$this->assertGreaterThan(0, strpos($generated, $className));
|
||||
$this->assertTrue(class_exists($className, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::generate
|
||||
* @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::__construct
|
||||
*/
|
||||
public function testGenerateWithDisabledEval()
|
||||
{
|
||||
if (! ini_get('suhosin.executor.disable_eval')) {
|
||||
$this->markTestSkipped('Ini setting "suhosin.executor.disable_eval" is needed to run this test');
|
||||
}
|
||||
|
||||
$strategy = new EvaluatingGeneratorStrategy();
|
||||
$className = 'Foo' . uniqid();
|
||||
$classGenerator = new ClassGenerator($className);
|
||||
$generated = $strategy->generate($classGenerator);
|
||||
|
||||
$this->assertGreaterThan(0, strpos($generated, $className));
|
||||
$this->assertTrue(class_exists($className, false));
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
<?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\GeneratorStrategy;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Exception\FileNotWritableException;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*
|
||||
* Note: this test generates temporary files that are not deleted
|
||||
*/
|
||||
class FileWriterGeneratorStrategyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy::__construct
|
||||
* @covers \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy::generate
|
||||
*/
|
||||
public function testGenerate()
|
||||
{
|
||||
/* @var $locator \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject */
|
||||
$locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
|
||||
$generator = new FileWriterGeneratorStrategy($locator);
|
||||
$tmpFile = sys_get_temp_dir() . '/' . uniqid('FileWriterGeneratorStrategyTest', true) . '.php';
|
||||
$namespace = 'Foo';
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('Bar');
|
||||
$fqcn = $namespace . '\\' . $className;
|
||||
|
||||
$locator
|
||||
->expects($this->any())
|
||||
->method('getProxyFileName')
|
||||
->with($fqcn)
|
||||
->will($this->returnValue($tmpFile));
|
||||
|
||||
$body = $generator->generate(new ClassGenerator($fqcn));
|
||||
|
||||
$this->assertGreaterThan(0, strpos($body, $className));
|
||||
$this->assertFalse(class_exists($fqcn, false));
|
||||
$this->assertTrue(file_exists($tmpFile));
|
||||
|
||||
require $tmpFile;
|
||||
|
||||
$this->assertTrue(class_exists($fqcn, false));
|
||||
}
|
||||
|
||||
public function testGenerateWillFailIfTmpFileCannotBeWrittenToDisk()
|
||||
{
|
||||
$tmpDirPath = sys_get_temp_dir() . '/' . uniqid('nonWritable', true);
|
||||
|
||||
mkdir($tmpDirPath, 0555, true);
|
||||
|
||||
/* @var $locator \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject */
|
||||
$locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
|
||||
$generator = new FileWriterGeneratorStrategy($locator);
|
||||
$tmpFile = $tmpDirPath . '/' . uniqid('FileWriterGeneratorStrategyFailedFileWriteTest', true) . '.php';
|
||||
$namespace = 'Foo';
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('Bar');
|
||||
$fqcn = $namespace . '\\' . $className;
|
||||
|
||||
$locator
|
||||
->expects($this->any())
|
||||
->method('getProxyFileName')
|
||||
->with($fqcn)
|
||||
->will($this->returnValue($tmpFile));
|
||||
|
||||
$this->setExpectedException('ProxyManager\\Exception\\FileNotWritableException');
|
||||
$generator->generate(new ClassGenerator($fqcn));
|
||||
}
|
||||
|
||||
public function testGenerateWillFailIfTmpFileCannotBeMovedToFinalDestination()
|
||||
{
|
||||
/* @var $locator \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject */
|
||||
$locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
|
||||
$generator = new FileWriterGeneratorStrategy($locator);
|
||||
$tmpFile = sys_get_temp_dir() . '/' . uniqid('FileWriterGeneratorStrategyFailedFileMoveTest', true) . '.php';
|
||||
$namespace = 'Foo';
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('Bar');
|
||||
$fqcn = $namespace . '\\' . $className;
|
||||
|
||||
$locator
|
||||
->expects($this->any())
|
||||
->method('getProxyFileName')
|
||||
->with($fqcn)
|
||||
->will($this->returnValue($tmpFile));
|
||||
|
||||
mkdir($tmpFile);
|
||||
|
||||
$this->setExpectedException('ProxyManager\\Exception\\FileNotWritableException');
|
||||
$generator->generate(new ClassGenerator($fqcn));
|
||||
}
|
||||
|
||||
public function testWhenFailingAllTemporaryFilesAreRemoved()
|
||||
{
|
||||
$tmpDirPath = sys_get_temp_dir() . '/' . uniqid('noTempFilesLeftBehind', true);
|
||||
|
||||
mkdir($tmpDirPath);
|
||||
|
||||
/* @var $locator \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject */
|
||||
$locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
|
||||
$generator = new FileWriterGeneratorStrategy($locator);
|
||||
$tmpFile = $tmpDirPath . '/' . uniqid('FileWriterGeneratorStrategyFailedFileMoveTest', true) . '.php';
|
||||
$namespace = 'Foo';
|
||||
$className = UniqueIdentifierGenerator::getIdentifier('Bar');
|
||||
$fqcn = $namespace . '\\' . $className;
|
||||
|
||||
$locator
|
||||
->expects($this->any())
|
||||
->method('getProxyFileName')
|
||||
->with($fqcn)
|
||||
->will($this->returnValue($tmpFile));
|
||||
|
||||
mkdir($tmpFile);
|
||||
|
||||
try {
|
||||
$generator->generate(new ClassGenerator($fqcn));
|
||||
|
||||
$this->fail('An exception was supposed to be thrown');
|
||||
} catch (FileNotWritableException $exception) {
|
||||
rmdir($tmpFile);
|
||||
|
||||
$this->assertEquals(array('.', '..'), scandir($tmpDirPath));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,161 @@
|
||||
<?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\Inflector;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Inflector\ClassNameInflector;
|
||||
use ProxyManager\Inflector\ClassNameInflectorInterface;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Inflector\ClassNameInflector}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class ClassNameInflectorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getClassNames
|
||||
*
|
||||
* @covers \ProxyManager\Inflector\ClassNameInflector::__construct
|
||||
* @covers \ProxyManager\Inflector\ClassNameInflector::getUserClassName
|
||||
* @covers \ProxyManager\Inflector\ClassNameInflector::getProxyClassName
|
||||
* @covers \ProxyManager\Inflector\ClassNameInflector::isProxyClassName
|
||||
*/
|
||||
public function testInflector($realClassName, $proxyClassName)
|
||||
{
|
||||
$inflector = new ClassNameInflector('ProxyNS');
|
||||
|
||||
$this->assertFalse($inflector->isProxyClassName($realClassName));
|
||||
$this->assertTrue($inflector->isProxyClassName($proxyClassName));
|
||||
$this->assertStringMatchesFormat($realClassName, $inflector->getUserClassName($realClassName));
|
||||
$this->assertStringMatchesFormat($proxyClassName, $inflector->getProxyClassName($proxyClassName));
|
||||
$this->assertStringMatchesFormat($proxyClassName, $inflector->getProxyClassName($realClassName));
|
||||
$this->assertStringMatchesFormat($realClassName, $inflector->getUserClassName($proxyClassName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Inflector\ClassNameInflector::getProxyClassName
|
||||
*/
|
||||
public function testGeneratesSameClassNameWithSameParameters()
|
||||
{
|
||||
$inflector = new ClassNameInflector('ProxyNS');
|
||||
|
||||
$this->assertSame($inflector->getProxyClassName('Foo\\Bar'), $inflector->getProxyClassName('Foo\\Bar'));
|
||||
$this->assertSame(
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('baz' => 'tab')),
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('baz' => 'tab'))
|
||||
);
|
||||
$this->assertSame(
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('tab' => 'baz')),
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('tab' => 'baz'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Inflector\ClassNameInflector::getProxyClassName
|
||||
*/
|
||||
public function testGeneratesDifferentClassNameWithDifferentParameters()
|
||||
{
|
||||
$inflector = new ClassNameInflector('ProxyNS');
|
||||
|
||||
$this->assertNotSame(
|
||||
$inflector->getProxyClassName('Foo\\Bar'),
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('foo' => 'bar'))
|
||||
);
|
||||
$this->assertNotSame(
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('baz' => 'tab')),
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('tab' => 'baz'))
|
||||
);
|
||||
$this->assertNotSame(
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('foo' => 'bar', 'tab' => 'baz')),
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('foo' => 'bar'))
|
||||
);
|
||||
$this->assertNotSame(
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('foo' => 'bar', 'tab' => 'baz')),
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('tab' => 'baz', 'foo' => 'bar'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Inflector\ClassNameInflector::getProxyClassName
|
||||
*/
|
||||
public function testGeneratesCorrectClassNameWhenGivenLeadingBackslash()
|
||||
{
|
||||
$inflector = new ClassNameInflector('ProxyNS');
|
||||
|
||||
$this->assertSame(
|
||||
$inflector->getProxyClassName('\\Foo\\Bar', array('tab' => 'baz')),
|
||||
$inflector->getProxyClassName('Foo\\Bar', array('tab' => 'baz'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \ProxyManager\Inflector\ClassNameInflector::getProxyClassName
|
||||
*
|
||||
* @dataProvider getClassAndParametersCombinations
|
||||
*
|
||||
* @param string $className
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function testClassNameIsValidClassIdentifier($className, array $parameters)
|
||||
{
|
||||
$inflector = new ClassNameInflector('ProxyNS');
|
||||
|
||||
$this->assertRegExp(
|
||||
'/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+)(\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+)*/',
|
||||
$inflector->getProxyClassName($className, $parameters),
|
||||
'Class name string is a valid class identifier'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function getClassNames()
|
||||
{
|
||||
return array(
|
||||
array('Foo', 'ProxyNS\\' . ClassNameInflectorInterface::PROXY_MARKER . '\\Foo\\%s'),
|
||||
array('Foo\\Bar', 'ProxyNS\\' . ClassNameInflectorInterface::PROXY_MARKER . '\\Foo\\Bar\\%s'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function getClassAndParametersCombinations()
|
||||
{
|
||||
return array(
|
||||
array('Foo', array()),
|
||||
array('Foo\\Bar', array()),
|
||||
array('Foo', array(null)),
|
||||
array('Foo\\Bar', array(null)),
|
||||
array('Foo', array('foo' => 'bar')),
|
||||
array('Foo\\Bar', array('foo' => 'bar')),
|
||||
array('Foo', array("\0" => "very \0 bad")),
|
||||
array('Foo\\Bar', array("\0" => "very \0 bad")),
|
||||
);
|
||||
}
|
||||
}
|
@ -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\Inflector\Util;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Inflector\Util\ParameterEncoder;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Inflector\Util\ParameterEncoder}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class ParameterEncoderTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getParameters
|
||||
*
|
||||
* @covers \ProxyManager\Inflector\Util\ParameterEncoder::encodeParameters
|
||||
*/
|
||||
public function testGeneratesValidClassName(array $parameters)
|
||||
{
|
||||
$encoder = new ParameterEncoder();
|
||||
|
||||
$this->assertRegExp(
|
||||
'/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+/',
|
||||
$encoder->encodeParameters($parameters),
|
||||
'Encoded string is a valid class identifier'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return array(
|
||||
array(array()),
|
||||
array(array('foo' => 'bar')),
|
||||
array(array('bar' => 'baz')),
|
||||
array(array(null)),
|
||||
array(array(null, null)),
|
||||
array(array('bar' => null)),
|
||||
array(array('bar' => 12345)),
|
||||
array(array('foo' => 'bar', 'bar' => 'baz')),
|
||||
);
|
||||
}
|
||||
}
|
@ -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\Inflector\Util;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ProxyManager\Inflector\Util\ParameterHasher;
|
||||
|
||||
/**
|
||||
* Tests for {@see \ProxyManager\Inflector\Util\ParameterHasher}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @group Coverage
|
||||
*/
|
||||
class ParameterHasherTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getParameters
|
||||
*
|
||||
* @covers \ProxyManager\Inflector\Util\ParameterHasher::hashParameters
|
||||
*/
|
||||
public function testGeneratesValidClassName(array $parameters, $expectedHash)
|
||||
{
|
||||
$encoder = new ParameterHasher();
|
||||
|
||||
$this->assertSame($expectedHash, $encoder->hashParameters($parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return array(
|
||||
array(array(), '40cd750bba9870f18aada2478b24840a'),
|
||||
array(array('foo' => 'bar'), '49a3696adf0fbfacc12383a2d7400d51'),
|
||||
array(array('bar' => 'baz'), '6ed41c8a63c1571554ecaeb998198757'),
|
||||
array(array(null), '38017a839aaeb8ff1a658fce9af6edd3'),
|
||||
array(array(null, null), '12051f9a58288e5328ad748881cc4e00'),
|
||||
array(array('bar' => null), '0dbb112e1c4e6e4126232de2daa2d660'),
|
||||
array(array('bar' => 12345), 'eb6291ea4973741bf9b6571f49b4ffd2'),
|
||||
array(array('foo' => 'bar', 'bar' => 'baz'), '4447ff857f244d24c31bd84d7a855eda'),
|
||||
);
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user