Vendor update && Started using DoctrineMigrations
This commit is contained in:
14
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Core/ClassUtilsTest.php
vendored
Normal file
14
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Core/ClassUtilsTest.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Core;
|
||||
|
||||
use CG\Core\ClassUtils;
|
||||
|
||||
class ClassUtilsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetUserClassName()
|
||||
{
|
||||
$this->assertEquals('Foo', ClassUtils::getUserClass('Foo'));
|
||||
$this->assertEquals('Bar', ClassUtils::getUserClass('FOO\__CG__\Bar'));
|
||||
}
|
||||
}
|
66
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Core/DefaultGeneratorStrategyTest.php
vendored
Normal file
66
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Core/DefaultGeneratorStrategyTest.php
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Core;
|
||||
|
||||
use CG\Core\DefaultGeneratorStrategy;
|
||||
|
||||
use CG\Generator\PhpProperty;
|
||||
use CG\Generator\PhpMethod;
|
||||
use CG\Generator\PhpClass;
|
||||
|
||||
class DefaultGeneratorStrategyTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGenerate()
|
||||
{
|
||||
$strategy = new DefaultGeneratorStrategy();
|
||||
$strategy->setConstantSortFunc(function($a, $b) {
|
||||
return strcasecmp($a, $b);
|
||||
});
|
||||
$strategy->setMethodSortFunc($func = function($a, $b) {
|
||||
return strcasecmp($a->getName(), $b->getName());
|
||||
});
|
||||
$strategy->setPropertySortFunc($func);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->getContent('GenerationTestClass_A.php'),
|
||||
$strategy->generate($this->getClass())
|
||||
);
|
||||
}
|
||||
|
||||
public function testGenerateChangedConstantOrder()
|
||||
{
|
||||
$strategy = new DefaultGeneratorStrategy();
|
||||
$strategy->setConstantSortFunc(function($a, $b) {
|
||||
return -1 * strcasecmp($a, $b);
|
||||
});
|
||||
$strategy->setMethodSortFunc($func = function($a, $b) {
|
||||
return strcasecmp($a->getName(), $b->getName());
|
||||
});
|
||||
$strategy->setPropertySortFunc($func);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->getContent('GenerationTestClass_B.php'),
|
||||
$strategy->generate($this->getClass())
|
||||
);
|
||||
}
|
||||
|
||||
private function getContent($file)
|
||||
{
|
||||
return file_get_contents(__DIR__.'/generated/'.$file);
|
||||
}
|
||||
|
||||
private function getClass()
|
||||
{
|
||||
$class = PhpClass::create()
|
||||
->setName('GenerationTestClass')
|
||||
->setMethod(PhpMethod::create('a'))
|
||||
->setMethod(PhpMethod::create('b'))
|
||||
->setProperty(PhpProperty::create('a'))
|
||||
->setProperty(PhpProperty::create('b'))
|
||||
->setConstant('a', 'foo')
|
||||
->setConstant('b', 'bar')
|
||||
;
|
||||
|
||||
return $class;
|
||||
}
|
||||
}
|
48
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Core/ReflectionUtilsTest.php
vendored
Normal file
48
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Core/ReflectionUtilsTest.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Core;
|
||||
|
||||
use CG\Generator\Writer;
|
||||
use CG\Core\ReflectionUtils;
|
||||
|
||||
class ReflectionUtilsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetOverridableMethods()
|
||||
{
|
||||
$ref = new \ReflectionClass('CG\Tests\Core\OverridableReflectionTest');
|
||||
$methods = ReflectionUtils::getOverrideableMethods($ref);
|
||||
|
||||
$this->assertEquals(4, count($methods));
|
||||
|
||||
$methods = array_map(function($v) { return $v->name; }, $methods);
|
||||
sort($methods);
|
||||
$this->assertEquals(array('a', 'd', 'e', 'h'), $methods);
|
||||
}
|
||||
|
||||
public function testGetUnindentedDocComment()
|
||||
{
|
||||
$writer = new Writer();
|
||||
$comment = $writer
|
||||
->writeln('/**')
|
||||
->indent()
|
||||
->writeln(' * Foo.')
|
||||
->write(' */')
|
||||
->getContent()
|
||||
;
|
||||
|
||||
$this->assertEquals("/**\n * Foo.\n */", ReflectionUtils::getUnindentedDocComment($comment));
|
||||
}
|
||||
}
|
||||
|
||||
abstract class OverridableReflectionTest
|
||||
{
|
||||
public function a() { }
|
||||
public final function b() { }
|
||||
public static function c() { }
|
||||
abstract public function d();
|
||||
protected function e() { }
|
||||
protected final function f() {}
|
||||
protected static function g() { }
|
||||
abstract protected function h();
|
||||
private function i() { }
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
class GenerationTestClass
|
||||
{
|
||||
const a = 'foo';
|
||||
const b = 'bar';
|
||||
|
||||
public $a;
|
||||
public $b;
|
||||
|
||||
public function a()
|
||||
{
|
||||
}
|
||||
|
||||
public function b()
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
class GenerationTestClass
|
||||
{
|
||||
const b = 'bar';
|
||||
const a = 'foo';
|
||||
|
||||
public $a;
|
||||
public $b;
|
||||
|
||||
public function a()
|
||||
{
|
||||
}
|
||||
|
||||
public function b()
|
||||
{
|
||||
}
|
||||
}
|
58
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/AbstractPhpMemberTest.php
vendored
Normal file
58
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/AbstractPhpMemberTest.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Generator;
|
||||
|
||||
class AbstractPhpMemberTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetGetStatic()
|
||||
{
|
||||
$member = $this->getMember();
|
||||
|
||||
$this->assertFalse($member->isStatic());
|
||||
$this->assertSame($member, $member->setStatic(true));
|
||||
$this->assertTrue($member->isStatic());
|
||||
$this->assertSame($member, $member->setStatic(false));
|
||||
$this->assertFalse($member->isStatic());
|
||||
}
|
||||
|
||||
public function testSetGetVisibility()
|
||||
{
|
||||
$member = $this->getMember();
|
||||
|
||||
$this->assertEquals('public', $member->getVisibility());
|
||||
$this->assertSame($member, $member->setVisibility('private'));
|
||||
$this->assertEquals('private', $member->getVisibility());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testSetVisibilityThrowsExOnInvalidValue()
|
||||
{
|
||||
$member = $this->getMember();
|
||||
$member->setVisibility('foo');
|
||||
}
|
||||
|
||||
public function testSetGetName()
|
||||
{
|
||||
$member = $this->getMember();
|
||||
|
||||
$this->assertNull($member->getName());
|
||||
$this->assertSame($member, $member->setName('foo'));
|
||||
$this->assertEquals('foo', $member->getName());
|
||||
}
|
||||
|
||||
public function testSetGetDocblock()
|
||||
{
|
||||
$member = $this->getMember();
|
||||
|
||||
$this->assertNull($member->getDocblock());
|
||||
$this->assertSame($member, $member->setDocblock('foo'));
|
||||
$this->assertEquals('foo', $member->getDocblock());
|
||||
}
|
||||
|
||||
private function getMember()
|
||||
{
|
||||
return $this->getMockForAbstractClass('CG\Generator\AbstractPhpMember');
|
||||
}
|
||||
}
|
47
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/DefaultVisitorTest.php
vendored
Normal file
47
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/DefaultVisitorTest.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Generator;
|
||||
|
||||
use CG\Generator\DefaultVisitor;
|
||||
use CG\Generator\PhpParameter;
|
||||
use CG\Generator\Writer;
|
||||
use CG\Generator\PhpFunction;
|
||||
|
||||
class DefaultVisitorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testVisitFunction()
|
||||
{
|
||||
$writer = new Writer();
|
||||
|
||||
$function = new PhpFunction();
|
||||
$function
|
||||
->setName('foo')
|
||||
->addParameter(PhpParameter::create('a'))
|
||||
->addParameter(PhpParameter::create('b'))
|
||||
->setBody(
|
||||
$writer
|
||||
->writeln('if ($a === $b) {')
|
||||
->indent()
|
||||
->writeln('throw new \InvalidArgumentException(\'$a is not allowed to be the same as $b.\');')
|
||||
->outdent()
|
||||
->write("}\n\n")
|
||||
->write('return $b;')
|
||||
->getContent()
|
||||
)
|
||||
;
|
||||
|
||||
$visitor = new DefaultVisitor();
|
||||
$visitor->visitFunction($function);
|
||||
|
||||
$this->assertEquals($this->getContent('a_b_function.php'), $visitor->getContent());
|
||||
}
|
||||
|
||||
private function getContent($filename)
|
||||
{
|
||||
if (!is_file($path = __DIR__.'/Fixture/generated/'.$filename)) {
|
||||
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $path));
|
||||
}
|
||||
|
||||
return file_get_contents($path);
|
||||
}
|
||||
}
|
35
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/Fixture/Entity.php
vendored
Normal file
35
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/Fixture/Entity.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Generator\Fixture;
|
||||
|
||||
/**
|
||||
* Doc Comment.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
abstract class Entity
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
private $id;
|
||||
private $enabled = false;
|
||||
|
||||
/**
|
||||
* Another doc comment.
|
||||
*
|
||||
* @param unknown_type $a
|
||||
* @param array $b
|
||||
* @param \stdClass $c
|
||||
* @param unknown_type $d
|
||||
*/
|
||||
public final function __construct($a, array &$b, \stdClass $c, $d = 'foo')
|
||||
{
|
||||
}
|
||||
|
||||
abstract protected function foo();
|
||||
|
||||
private static function bar()
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
function foo($a, $b)
|
||||
{
|
||||
if ($a === $b) {
|
||||
throw new \InvalidArgumentException('$a is not allowed to be the same as $b.');
|
||||
}
|
||||
|
||||
return $b;
|
||||
}
|
215
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/PhpClassTest.php
vendored
Normal file
215
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/PhpClassTest.php
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Generator;
|
||||
|
||||
use CG\Generator\PhpProperty;
|
||||
|
||||
use CG\Generator\PhpParameter;
|
||||
use CG\Generator\PhpMethod;
|
||||
use CG\Generator\PhpClass;
|
||||
|
||||
class PhpClassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFromReflection()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
$class
|
||||
->setName('CG\Tests\Generator\Fixture\Entity')
|
||||
->setAbstract(true)
|
||||
->setDocblock('/**
|
||||
* Doc Comment.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/')
|
||||
->setProperty(PhpProperty::create('id')
|
||||
->setVisibility('private')
|
||||
->setDocblock('/**
|
||||
* @var integer
|
||||
*/')
|
||||
)
|
||||
->setProperty(PhpProperty::create('enabled')
|
||||
->setVisibility('private')
|
||||
->setDefaultValue(false)
|
||||
)
|
||||
;
|
||||
|
||||
$method = PhpMethod::create()
|
||||
->setName('__construct')
|
||||
->setFinal(true)
|
||||
->addParameter(new PhpParameter('a'))
|
||||
->addParameter(PhpParameter::create()
|
||||
->setName('b')
|
||||
->setType('array')
|
||||
->setPassedByReference(true)
|
||||
)
|
||||
->addParameter(PhpParameter::create()
|
||||
->setName('c')
|
||||
->setType('stdClass')
|
||||
)
|
||||
->addParameter(PhpParameter::create()
|
||||
->setName('d')
|
||||
->setDefaultValue('foo')
|
||||
)->setDocblock('/**
|
||||
* Another doc comment.
|
||||
*
|
||||
* @param unknown_type $a
|
||||
* @param array $b
|
||||
* @param \stdClass $c
|
||||
* @param unknown_type $d
|
||||
*/')
|
||||
;
|
||||
$class->setMethod($method);
|
||||
|
||||
$class->setMethod(PhpMethod::create()
|
||||
->setName('foo')
|
||||
->setAbstract(true)
|
||||
->setVisibility('protected')
|
||||
);
|
||||
|
||||
$class->setMethod(PhpMethod::create()
|
||||
->setName('bar')
|
||||
->setStatic(true)
|
||||
->setVisibility('private')
|
||||
);
|
||||
|
||||
$this->assertEquals($class, PhpClass::fromReflection(new \ReflectionClass('CG\Tests\Generator\Fixture\Entity')));
|
||||
}
|
||||
|
||||
public function testGetSetName()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
$this->assertNull($class->getName());
|
||||
|
||||
$class = new PhpClass('foo');
|
||||
$this->assertEquals('foo', $class->getName());
|
||||
$this->assertSame($class, $class->setName('bar'));
|
||||
$this->assertEquals('bar', $class->getName());
|
||||
}
|
||||
|
||||
public function testSetGetConstants()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
|
||||
$this->assertEquals(array(), $class->getConstants());
|
||||
$this->assertSame($class, $class->setConstants(array('foo' => 'bar')));
|
||||
$this->assertEquals(array('foo' => 'bar'), $class->getConstants());
|
||||
$this->assertSame($class, $class->setConstant('bar', 'baz'));
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $class->getConstants());
|
||||
$this->assertSame($class, $class->removeConstant('foo'));
|
||||
$this->assertEquals(array('bar' => 'baz'), $class->getConstants());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testRemoveConstantThrowsExceptionWhenConstantDoesNotExist()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
$class->removeConstant('foo');
|
||||
}
|
||||
|
||||
public function testSetIsAbstract()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
|
||||
$this->assertFalse($class->isAbstract());
|
||||
$this->assertSame($class, $class->setAbstract(true));
|
||||
$this->assertTrue($class->isAbstract());
|
||||
$this->assertSame($class, $class->setAbstract(false));
|
||||
$this->assertFalse($class->isAbstract());
|
||||
}
|
||||
|
||||
public function testSetIsFinal()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
|
||||
$this->assertFalse($class->isFinal());
|
||||
$this->assertSame($class, $class->setFinal(true));
|
||||
$this->assertTrue($class->isFinal());
|
||||
$this->assertSame($class, $class->setFinal(false));
|
||||
$this->assertFalse($class->isFinal());
|
||||
}
|
||||
|
||||
public function testSetGetParentClassName()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
|
||||
$this->assertNull($class->getParentClassName());
|
||||
$this->assertSame($class, $class->setParentClassName('stdClass'));
|
||||
$this->assertEquals('stdClass', $class->getParentClassName());
|
||||
$this->assertSame($class, $class->setParentClassName(null));
|
||||
$this->assertNull($class->getParentClassName());
|
||||
}
|
||||
|
||||
public function testSetGetInterfaceNames()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
|
||||
$this->assertEquals(array(), $class->getInterfaceNames());
|
||||
$this->assertSame($class, $class->setInterfaceNames(array('foo', 'bar')));
|
||||
$this->assertEquals(array('foo', 'bar'), $class->getInterfaceNames());
|
||||
$this->assertSame($class, $class->addInterfaceName('stdClass'));
|
||||
$this->assertEquals(array('foo', 'bar', 'stdClass'), $class->getInterfaceNames());
|
||||
}
|
||||
|
||||
public function testSetGetUseStatements()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
|
||||
$this->assertEquals(array(), $class->getUseStatements());
|
||||
$this->assertSame($class, $class->setUseStatements(array('foo' => 'bar')));
|
||||
$this->assertEquals(array('foo' => 'bar'), $class->getUseStatements());
|
||||
$this->assertSame($class, $class->addUseStatement('Foo\Bar'));
|
||||
$this->assertEquals(array('foo' => 'bar', 'Bar' => 'Foo\Bar'), $class->getUseStatements());
|
||||
$this->assertSame($class, $class->addUseStatement('Foo\Bar', 'Baz'));
|
||||
$this->assertEquals(array('foo' => 'bar', 'Bar' => 'Foo\Bar', 'Baz' => 'Foo\Bar'), $class->getUseStatements());
|
||||
}
|
||||
|
||||
public function testSetGetProperties()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
|
||||
$this->assertEquals(array(), $class->getProperties());
|
||||
$this->assertSame($class, $class->setProperties($props = array('foo' => new PhpProperty())));
|
||||
$this->assertSame($props, $class->getProperties());
|
||||
$this->assertSame($class, $class->setProperty($prop = new PhpProperty('foo')));
|
||||
$this->assertSame(array('foo' => $prop), $class->getProperties());
|
||||
$this->assertTrue($class->hasProperty('foo'));
|
||||
$this->assertSame($class, $class->removeProperty('foo'));
|
||||
$this->assertEquals(array(), $class->getProperties());
|
||||
}
|
||||
|
||||
public function testSetGetMethods()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
|
||||
$this->assertEquals(array(), $class->getMethods());
|
||||
$this->assertSame($class, $class->setMethods($methods = array('foo' => new PhpMethod())));
|
||||
$this->assertSame($methods, $class->getMethods());
|
||||
$this->assertSame($class, $class->setMethod($method = new PhpMethod('foo')));
|
||||
$this->assertSame(array('foo' => $method), $class->getMethods());
|
||||
$this->assertTrue($class->hasMethod('foo'));
|
||||
$this->assertSame($class, $class->removeMethod('foo'));
|
||||
$this->assertEquals(array(), $class->getMethods());
|
||||
}
|
||||
|
||||
public function testSetGetDocblock()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
|
||||
$this->assertNull($class->getDocblock());
|
||||
$this->assertSame($class, $class->setDocblock('foo'));
|
||||
$this->assertEquals('foo', $class->getDocblock());
|
||||
}
|
||||
|
||||
public function testSetGetRequiredFiles()
|
||||
{
|
||||
$class = new PhpClass();
|
||||
|
||||
$this->assertEquals(array(), $class->getRequiredFiles());
|
||||
$this->assertSame($class, $class->setRequiredFiles(array('foo')));
|
||||
$this->assertEquals(array('foo'), $class->getRequiredFiles());
|
||||
$this->assertSame($class, $class->addRequiredFile('bar'));
|
||||
$this->assertEquals(array('foo', 'bar'), $class->getRequiredFiles());
|
||||
}
|
||||
}
|
75
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/PhpFunctionTest.php
vendored
Normal file
75
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/PhpFunctionTest.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Generator;
|
||||
|
||||
use CG\Generator\PhpParameter;
|
||||
|
||||
use CG\Generator\PhpFunction;
|
||||
|
||||
class PhpFunctionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetGetName()
|
||||
{
|
||||
$func = new PhpFunction();
|
||||
|
||||
$this->assertNull($func->getName());
|
||||
$this->assertSame($func, $func->setName('foo'));
|
||||
$this->assertEquals('foo', $func->getName());
|
||||
|
||||
$func = new PhpFunction('foo');
|
||||
$this->assertEquals('foo', $func->getName());
|
||||
}
|
||||
|
||||
public function testSetGetNamespace()
|
||||
{
|
||||
$func = new PhpFunction();
|
||||
|
||||
$this->assertNull($func->getNamespace());
|
||||
$this->assertSame($func, $func->setNamespace('foo'));
|
||||
$this->assertEquals('foo', $func->getNamespace());
|
||||
}
|
||||
|
||||
public function testSetGetBody()
|
||||
{
|
||||
$func = new PhpFunction();
|
||||
|
||||
$this->assertSame('', $func->getBody());
|
||||
$this->assertSame($func, $func->setBody('foo'));
|
||||
$this->assertEquals('foo', $func->getBody());
|
||||
}
|
||||
|
||||
public function testSetGetParameters()
|
||||
{
|
||||
$func = new PhpFunction();
|
||||
|
||||
$this->assertEquals(array(), $func->getParameters());
|
||||
$this->assertSame($func, $func->setParameters(array($param = new PhpParameter())));
|
||||
$this->assertSame(array($param), $func->getParameters());
|
||||
$this->assertSame($func, $func->addParameter($param2 = new PhpParameter()));
|
||||
$this->assertSame(array($param, $param2), $func->getParameters());
|
||||
$this->assertSame($func, $func->replaceParameter(1, $param3 = new PhpParameter()));
|
||||
$this->assertSame(array($param, $param3), $func->getParameters());
|
||||
$this->assertSame($func, $func->removeParameter(0));
|
||||
$this->assertSame(array($param3), $func->getParameters());
|
||||
}
|
||||
|
||||
public function testSetGetDocblock()
|
||||
{
|
||||
$func = new PhpFunction();
|
||||
|
||||
$this->assertNull($func->getDocblock());
|
||||
$this->assertSame($func, $func->setDocblock('foo'));
|
||||
$this->assertEquals('foo', $func->getDocblock());
|
||||
}
|
||||
|
||||
public function testSetIsReferenceReturned()
|
||||
{
|
||||
$func = new PhpFunction();
|
||||
|
||||
$this->assertFalse($func->isReferenceReturned());
|
||||
$this->assertSame($func, $func->setReferenceReturned(true));
|
||||
$this->assertTrue($func->isReferenceReturned());
|
||||
$this->assertSame($func, $func->setReferenceReturned(false));
|
||||
$this->assertFalse($func->isReferenceReturned());
|
||||
}
|
||||
}
|
74
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/PhpMethodTest.php
vendored
Normal file
74
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/PhpMethodTest.php
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Generator;
|
||||
|
||||
use CG\Generator\PhpParameter;
|
||||
|
||||
use CG\Generator\PhpMethod;
|
||||
|
||||
class PhpMethodTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetIsFinal()
|
||||
{
|
||||
$method = new PhpMethod();
|
||||
|
||||
$this->assertFalse($method->isFinal());
|
||||
$this->assertSame($method, $method->setFinal(true));
|
||||
$this->assertTrue($method->isFinal());
|
||||
$this->assertSame($method, $method->setFinal(false));
|
||||
$this->assertFalse($method->isFinal());
|
||||
}
|
||||
|
||||
public function testSetIsAbstract()
|
||||
{
|
||||
$method = new PhpMethod();
|
||||
|
||||
$this->assertFalse($method->isAbstract());
|
||||
$this->assertSame($method, $method->setAbstract(true));
|
||||
$this->assertTrue($method->isAbstract());
|
||||
$this->assertSame($method, $method->setAbstract(false));
|
||||
$this->assertFalse($method->isAbstract());
|
||||
}
|
||||
|
||||
public function testSetGetParameters()
|
||||
{
|
||||
$method = new PhpMethod();
|
||||
|
||||
$this->assertEquals(array(), $method->getParameters());
|
||||
$this->assertSame($method, $method->setParameters($params = array(new PhpParameter())));
|
||||
$this->assertSame($params, $method->getParameters());
|
||||
|
||||
$this->assertSame($method, $method->addParameter($param = new PhpParameter()));
|
||||
$params[] = $param;
|
||||
$this->assertSame($params, $method->getParameters());
|
||||
|
||||
$this->assertSame($method, $method->removeParameter(0));
|
||||
unset($params[0]);
|
||||
$this->assertSame(array($param), $method->getParameters());
|
||||
|
||||
$this->assertSame($method, $method->addParameter($param = new PhpParameter()));
|
||||
$params[] = $param;
|
||||
$params = array_values($params);
|
||||
$this->assertSame($params, $method->getParameters());
|
||||
}
|
||||
|
||||
public function testSetGetBody()
|
||||
{
|
||||
$method = new PhpMethod();
|
||||
|
||||
$this->assertSame('', $method->getBody());
|
||||
$this->assertSame($method, $method->setBody('foo'));
|
||||
$this->assertEquals('foo', $method->getBody());
|
||||
}
|
||||
|
||||
public function testSetIsReferenceReturned()
|
||||
{
|
||||
$method = new PhpMethod();
|
||||
|
||||
$this->assertFalse($method->isReferenceReturned());
|
||||
$this->assertSame($method, $method->setReferenceReturned(true));
|
||||
$this->assertTrue($method->isReferenceReturned());
|
||||
$this->assertSame($method, $method->setReferenceReturned(false));
|
||||
$this->assertFalse($method->isReferenceReturned());
|
||||
}
|
||||
}
|
51
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/PhpParameterTest.php
vendored
Normal file
51
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/PhpParameterTest.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Generator;
|
||||
|
||||
use CG\Generator\PhpParameter;
|
||||
|
||||
class PhpParameterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetGetName()
|
||||
{
|
||||
$param = new PhpParameter();
|
||||
|
||||
$this->assertNull($param->getName());
|
||||
$this->assertSame($param, $param->setName('foo'));
|
||||
$this->assertEquals('foo', $param->getName());
|
||||
}
|
||||
|
||||
public function testSetGetDefaultValue()
|
||||
{
|
||||
$param = new PhpParameter();
|
||||
|
||||
$this->assertNull($param->getDefaultValue());
|
||||
$this->assertFalse($param->hasDefaultValue());
|
||||
$this->assertSame($param, $param->setDefaultValue('foo'));
|
||||
$this->assertEquals('foo', $param->getDefaultValue());
|
||||
$this->assertTrue($param->hasDefaultValue());
|
||||
$this->assertSame($param, $param->unsetDefaultValue());
|
||||
$this->assertNull($param->getDefaultValue());
|
||||
$this->assertFalse($param->hasDefaultValue());
|
||||
}
|
||||
|
||||
public function testSetIsPassedByReference()
|
||||
{
|
||||
$param = new PhpParameter();
|
||||
|
||||
$this->assertFalse($param->isPassedByReference());
|
||||
$this->assertSame($param, $param->setPassedByReference(true));
|
||||
$this->assertTrue($param->isPassedByReference());
|
||||
$this->assertSame($param, $param->setPassedByReference(false));
|
||||
$this->assertFalse($param->isPassedByReference());
|
||||
}
|
||||
|
||||
public function testSetGetType()
|
||||
{
|
||||
$param = new PhpParameter();
|
||||
|
||||
$this->assertNull($param->getType());
|
||||
$this->assertSame($param, $param->setType('array'));
|
||||
$this->assertEquals('array', $param->getType());
|
||||
}
|
||||
}
|
22
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/PhpPropertyTest.php
vendored
Normal file
22
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Generator/PhpPropertyTest.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Generator;
|
||||
|
||||
use CG\Generator\PhpProperty;
|
||||
|
||||
class PhpPropertyTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetGetDefaultValue()
|
||||
{
|
||||
$prop = new PhpProperty();
|
||||
|
||||
$this->assertNull($prop->getDefaultValue());
|
||||
$this->assertFalse($prop->hasDefaultValue());
|
||||
$this->assertSame($prop, $prop->setDefaultValue('foo'));
|
||||
$this->assertEquals('foo', $prop->getDefaultValue());
|
||||
$this->assertTrue($prop->hasDefaultValue());
|
||||
$this->assertSame($prop, $prop->unsetDefaultValue());
|
||||
$this->assertNull($prop->getDefaultValue());
|
||||
$this->assertFalse($prop->hasDefaultValue());
|
||||
}
|
||||
}
|
111
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Proxy/EnhancerTest.php
vendored
Normal file
111
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Proxy/EnhancerTest.php
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Proxy;
|
||||
|
||||
use CG\Proxy\LazyInitializerInterface;
|
||||
use CG\Proxy\InterceptionGenerator;
|
||||
use CG\Proxy\LazyInitializerGenerator;
|
||||
use CG\Proxy\Enhancer;
|
||||
use CG\Tests\Proxy\Fixture\TraceInterceptor;
|
||||
|
||||
class EnhancerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getGenerationTests
|
||||
*/
|
||||
public function testGenerateClass($class, $generatedClass, array $interfaces, array $generators)
|
||||
{
|
||||
$enhancer = new Enhancer(new \ReflectionClass($class), $interfaces, $generators);
|
||||
$enhancer->setNamingStrategy($this->getNamingStrategy($generatedClass));
|
||||
|
||||
$this->assertEquals($this->getContent(substr($generatedClass, strrpos($generatedClass, '\\') + 1)), $enhancer->generateClass());
|
||||
}
|
||||
|
||||
public function getGenerationTests()
|
||||
{
|
||||
return array(
|
||||
array('CG\Tests\Proxy\Fixture\SimpleClass', 'CG\Tests\Proxy\Fixture\SimpleClass__CG__Enhanced', array('CG\Tests\Proxy\Fixture\MarkerInterface'), array()),
|
||||
array('CG\Tests\Proxy\Fixture\SimpleClass', 'CG\Tests\Proxy\Fixture\SimpleClass__CG__Sluggable', array('CG\Tests\Proxy\Fixture\SluggableInterface'), array()),
|
||||
array('CG\Tests\Proxy\Fixture\Entity', 'CG\Tests\Proxy\Fixture\Entity__CG__LazyInitializing', array(), array(
|
||||
new LazyInitializerGenerator(),
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
public function testInterceptionGenerator()
|
||||
{
|
||||
$enhancer = new Enhancer(new \ReflectionClass('CG\Tests\Proxy\Fixture\Entity'), array(), array(
|
||||
$generator = new InterceptionGenerator()
|
||||
));
|
||||
$enhancer->setNamingStrategy($this->getNamingStrategy('CG\Tests\Proxy\Fixture\Entity__CG__Traceable_'.sha1(microtime(true))));
|
||||
$generator->setPrefix('');
|
||||
|
||||
$traceable = $enhancer->createInstance();
|
||||
$traceable->setLoader($this->getLoader(array(
|
||||
$interceptor1 = new TraceInterceptor(),
|
||||
$interceptor2 = new TraceInterceptor(),
|
||||
)));
|
||||
|
||||
$this->assertEquals('foo', $traceable->getName());
|
||||
$this->assertEquals('foo', $traceable->getName());
|
||||
$this->assertEquals(2, count($interceptor1->getLog()));
|
||||
$this->assertEquals(2, count($interceptor2->getLog()));
|
||||
}
|
||||
|
||||
public function testLazyInitializerGenerator()
|
||||
{
|
||||
$enhancer = new Enhancer(new \ReflectionClass('CG\Tests\Proxy\Fixture\Entity'), array(), array(
|
||||
$generator = new LazyInitializerGenerator(),
|
||||
));
|
||||
$generator->setPrefix('');
|
||||
|
||||
$entity = $enhancer->createInstance();
|
||||
$entity->setLazyInitializer($initializer = new Initializer());
|
||||
$this->assertEquals('foo', $entity->getName());
|
||||
$this->assertSame($entity, $initializer->getLastObject());
|
||||
}
|
||||
|
||||
private function getLoader(array $interceptors)
|
||||
{
|
||||
$loader = $this->getMock('CG\Proxy\InterceptorLoaderInterface');
|
||||
$loader
|
||||
->expects($this->any())
|
||||
->method('loadInterceptors')
|
||||
->will($this->returnValue($interceptors))
|
||||
;
|
||||
|
||||
return $loader;
|
||||
}
|
||||
|
||||
private function getContent($file)
|
||||
{
|
||||
return file_get_contents(__DIR__.'/Fixture/generated/'.$file.'.php.gen');
|
||||
}
|
||||
|
||||
private function getNamingStrategy($name)
|
||||
{
|
||||
$namingStrategy = $this->getMock('CG\Core\NamingStrategyInterface');
|
||||
$namingStrategy
|
||||
->expects($this->any())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue($name))
|
||||
;
|
||||
|
||||
return $namingStrategy;
|
||||
}
|
||||
}
|
||||
|
||||
class Initializer implements LazyInitializerInterface
|
||||
{
|
||||
private $lastObject;
|
||||
|
||||
public function initializeObject($object)
|
||||
{
|
||||
$this->lastObject = $object;
|
||||
}
|
||||
|
||||
public function getLastObject()
|
||||
{
|
||||
return $this->lastObject;
|
||||
}
|
||||
}
|
23
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Proxy/Fixture/Entity.php
vendored
Normal file
23
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Proxy/Fixture/Entity.php
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Proxy\Fixture;
|
||||
|
||||
class Entity
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
public final function getBaz()
|
||||
{
|
||||
}
|
||||
|
||||
protected function getFoo()
|
||||
{
|
||||
}
|
||||
|
||||
private function getBar()
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Proxy
|
7
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Proxy/Fixture/MarkerInterface.php
vendored
Normal file
7
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Proxy/Fixture/MarkerInterface.php
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Proxy\Fixture;
|
||||
|
||||
interface MarkerInterface
|
||||
{
|
||||
}
|
7
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Proxy/Fixture/SimpleClass.php
vendored
Normal file
7
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Proxy/Fixture/SimpleClass.php
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Proxy\Fixture;
|
||||
|
||||
class SimpleClass
|
||||
{
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Proxy\Fixture;
|
||||
|
||||
interface SluggableInterface
|
||||
{
|
||||
function getSlug();
|
||||
}
|
29
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Proxy/Fixture/TraceInterceptor.php
vendored
Normal file
29
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/CG/Tests/Proxy/Fixture/TraceInterceptor.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace CG\Tests\Proxy\Fixture;
|
||||
|
||||
use CG\Proxy\MethodInvocation;
|
||||
use CG\Proxy\MethodInterceptorInterface;
|
||||
|
||||
class TraceInterceptor implements MethodInterceptorInterface
|
||||
{
|
||||
private $log;
|
||||
|
||||
public function getLog()
|
||||
{
|
||||
return $this->log;
|
||||
}
|
||||
|
||||
public function intercept(MethodInvocation $method)
|
||||
{
|
||||
$message = sprintf('%s::%s(', $method->reflection->class, $method->reflection->name);
|
||||
|
||||
$logArgs = array();
|
||||
foreach ($method->arguments as $arg) {
|
||||
$logArgs[] = var_export($arg, true);
|
||||
}
|
||||
$this->log[] = $message.implode(', ', $logArgs).')';
|
||||
|
||||
return $method->proceed();
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
namespace CG\Tests\Proxy\Fixture;
|
||||
|
||||
/**
|
||||
* CG library enhanced proxy class.
|
||||
*
|
||||
* This code was generated automatically by the CG library, manual changes to it
|
||||
* will be lost upon next generation.
|
||||
*/
|
||||
class Entity__CG__LazyInitializing extends \CG\Tests\Proxy\Fixture\Entity
|
||||
{
|
||||
private $__CG__lazyInitializer;
|
||||
private $__CG__initialized = false;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
if (false === $this->__CG__initialized) {
|
||||
$this->__CG__initialize();
|
||||
}
|
||||
|
||||
return \CG\Tests\Proxy\Fixture\Entity::getName();
|
||||
}
|
||||
|
||||
public function __CG__setLazyInitializer(\CG\Proxy\LazyInitializerInterface $initializer)
|
||||
{
|
||||
$this->__CG__lazyInitializer = $initializer;
|
||||
}
|
||||
|
||||
private function __CG__initialize()
|
||||
{
|
||||
if (null === $this->__CG__lazyInitializer) {
|
||||
throw new \RuntimeException("__CG__setLazyInitializer() must be called prior to any other public method on this object.");
|
||||
}
|
||||
|
||||
$this->__CG__lazyInitializer->initializeObject($this);
|
||||
$this->__CG__initialized = true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
namespace CG\Tests\Proxy\Fixture;
|
||||
|
||||
/**
|
||||
* CG library enhanced proxy class.
|
||||
*
|
||||
* This code was generated automatically by the CG library, manual changes to it
|
||||
* will be lost upon next generation.
|
||||
*/
|
||||
class SimpleClass__CG__Enhanced extends \CG\Tests\Proxy\Fixture\SimpleClass implements \CG\Tests\Proxy\Fixture\MarkerInterface
|
||||
{
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
namespace CG\Tests\Proxy\Fixture;
|
||||
|
||||
/**
|
||||
* CG library enhanced proxy class.
|
||||
*
|
||||
* This code was generated automatically by the CG library, manual changes to it
|
||||
* will be lost upon next generation.
|
||||
*/
|
||||
class SimpleClass__CG__Sluggable extends \CG\Tests\Proxy\Fixture\SimpleClass implements \CG\Tests\Proxy\Fixture\SluggableInterface
|
||||
{
|
||||
public function getSlug()
|
||||
{
|
||||
}
|
||||
}
|
35
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/bootstrap.php
vendored
Normal file
35
vendor/jms/cg/schmittjoh-cg-library-ce8ef43/tests/bootstrap.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the CG library.
|
||||
*
|
||||
* (C) 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
spl_autoload_register(function($class)
|
||||
{
|
||||
if (0 === strpos($class, 'CG\Tests\\')) {
|
||||
$path = __DIR__.'/../tests/'.strtr($class, '\\', '/').'.php';
|
||||
if (file_exists($path) && is_readable($path)) {
|
||||
require_once $path;
|
||||
|
||||
return true;
|
||||
}
|
||||
} else if (0 === strpos($class, 'CG\\')) {
|
||||
$path = __DIR__.'/../src/'.($class = strtr($class, '\\', '/')).'.php';
|
||||
if (file_exists($path) && is_readable($path)) {
|
||||
require_once $path;
|
||||
|
||||
return true;
|
||||
}
|
||||
} else if (0 === strpos($class, 'Zend\\')) {
|
||||
$path = __DIR__.'/../../zend-framework2/library/'.($class = strtr($class, '\\', '/')).'.php';
|
||||
if (file_exists($path) && is_readable($path)) {
|
||||
require_once $path;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user