Vendor update && Started using DoctrineMigrations

This commit is contained in:
Polonkai Gergely
2012-07-23 17:09:03 +02:00
parent 7c36f93436
commit bf46316347
1102 changed files with 103189 additions and 7 deletions

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

View 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()
{
}
}

View File

@@ -0,0 +1,3 @@
<?php
namespace CG\Tests\Proxy

View File

@@ -0,0 +1,7 @@
<?php
namespace CG\Tests\Proxy\Fixture;
interface MarkerInterface
{
}

View File

@@ -0,0 +1,7 @@
<?php
namespace CG\Tests\Proxy\Fixture;
class SimpleClass
{
}

View File

@@ -0,0 +1,8 @@
<?php
namespace CG\Tests\Proxy\Fixture;
interface SluggableInterface
{
function getSlug();
}

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

View File

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

View File

@@ -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
{
}

View File

@@ -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()
{
}
}