Ajout du FR

Ajout du FR + correction du "functions.php"
This commit is contained in:
Gauvain Boiché
2020-03-30 14:52:34 +02:00
commit 5e4c5f9418
4541 changed files with 608941 additions and 0 deletions

View 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'));
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View 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);
}
}

View 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\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')));
}
}

View File

@@ -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')));
}
}

View File

@@ -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')));
}
}

View File

@@ -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')));
}
}

View 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);
}
}