first commit
This commit is contained in:
65
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/ClassGeneratorTest.php
vendored
Normal file
65
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/ClassGeneratorTest.php
vendored
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
56
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/MagicMethodGeneratorTest.php
vendored
Normal file
56
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/MagicMethodGeneratorTest.php
vendored
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
97
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/MethodGeneratorTest.php
vendored
Normal file
97
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/MethodGeneratorTest.php
vendored
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
146
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/ParameterGeneratorTest.php
vendored
Normal file
146
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/ParameterGeneratorTest.php
vendored
Normal file
@@ -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\'')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
72
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/Util/ClassGeneratorUtilsTest.php
vendored
Normal file
72
vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Generator/Util/ClassGeneratorUtilsTest.php
vendored
Normal file
@@ -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'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user