1
0
Fork 0
forked from lino/radar-wp

Initial import.

This commit is contained in:
ekes 2015-02-24 16:25:12 +01:00
commit 86383280c9
428 changed files with 68738 additions and 0 deletions

View file

@ -0,0 +1,517 @@
<?php
namespace Doctrine\Tests\Common\Annotations;
use Doctrine\Common\Annotations\DoctrineReader;
use Doctrine\Common\Reflection\StaticReflectionParser;
use Doctrine\Common\Reflection\Psr0FindFile;
use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Doctrine\Common\Annotations\Annotation\IgnorePhpDoc;
use ReflectionClass, Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Tests\Common\Annotations\DummyAnnotation;
use Doctrine\Tests\Common\Annotations\Name;
use Doctrine\Tests\Common\Annotations\DummyId;
use Doctrine\Tests\Common\Annotations\DummyJoinTable;
use Doctrine\Tests\Common\Annotations\DummyJoinColumn;
use Doctrine\Tests\Common\Annotations\DummyColumn;
use Doctrine\Tests\Common\Annotations\DummyGeneratedValue;
require_once __DIR__ . '/TopLevelAnnotation.php';
abstract class AbstractReaderTest extends \PHPUnit_Framework_TestCase
{
public function getReflectionClass()
{
$className = 'Doctrine\Tests\Common\Annotations\DummyClass';
$testsRoot = substr(__DIR__, 0, -strlen(__NAMESPACE__) - 1);
$paths = array(
'Doctrine\\Tests' => array($testsRoot),
);
$staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths));
return array(
'native' => array(new ReflectionClass($className)),
'static' => array($staticReflectionParser->getReflectionClass()),
);
}
/**
* @dataProvider getReflectionClass
*/
public function testAnnotations($class)
{
$reader = $this->getReader();
$this->assertEquals(1, count($reader->getClassAnnotations($class)));
$this->assertInstanceOf($annotName = 'Doctrine\Tests\Common\Annotations\DummyAnnotation', $annot = $reader->getClassAnnotation($class, $annotName));
$this->assertEquals("hello", $annot->dummyValue);
$field1Prop = $class->getProperty('field1');
$propAnnots = $reader->getPropertyAnnotations($field1Prop);
$this->assertEquals(1, count($propAnnots));
$this->assertInstanceOf($annotName, $annot = $reader->getPropertyAnnotation($field1Prop, $annotName));
$this->assertEquals("fieldHello", $annot->dummyValue);
$getField1Method = $class->getMethod('getField1');
$methodAnnots = $reader->getMethodAnnotations($getField1Method);
$this->assertEquals(1, count($methodAnnots));
$this->assertInstanceOf($annotName, $annot = $reader->getMethodAnnotation($getField1Method, $annotName));
$this->assertEquals(array(1, 2, "three"), $annot->value);
$field2Prop = $class->getProperty('field2');
$propAnnots = $reader->getPropertyAnnotations($field2Prop);
$this->assertEquals(1, count($propAnnots));
$this->assertInstanceOf($annotName = 'Doctrine\Tests\Common\Annotations\DummyJoinTable', $joinTableAnnot = $reader->getPropertyAnnotation($field2Prop, $annotName));
$this->assertEquals(1, count($joinTableAnnot->joinColumns));
$this->assertEquals(1, count($joinTableAnnot->inverseJoinColumns));
$this->assertTrue($joinTableAnnot->joinColumns[0] instanceof DummyJoinColumn);
$this->assertTrue($joinTableAnnot->inverseJoinColumns[0] instanceof DummyJoinColumn);
$this->assertEquals('col1', $joinTableAnnot->joinColumns[0]->name);
$this->assertEquals('col2', $joinTableAnnot->joinColumns[0]->referencedColumnName);
$this->assertEquals('col3', $joinTableAnnot->inverseJoinColumns[0]->name);
$this->assertEquals('col4', $joinTableAnnot->inverseJoinColumns[0]->referencedColumnName);
$dummyAnnot = $reader->getMethodAnnotation($class->getMethod('getField1'), 'Doctrine\Tests\Common\Annotations\DummyAnnotation');
$this->assertEquals('', $dummyAnnot->dummyValue);
$this->assertEquals(array(1, 2, 'three'), $dummyAnnot->value);
$dummyAnnot = $reader->getPropertyAnnotation($class->getProperty('field1'), 'Doctrine\Tests\Common\Annotations\DummyAnnotation');
$this->assertEquals('fieldHello', $dummyAnnot->dummyValue);
$classAnnot = $reader->getClassAnnotation($class, 'Doctrine\Tests\Common\Annotations\DummyAnnotation');
$this->assertEquals('hello', $classAnnot->dummyValue);
}
public function testAnnotationsWithValidTargets()
{
$reader = $this->getReader();
$class = new ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithValidAnnotationTarget');
$this->assertEquals(1,count($reader->getClassAnnotations($class)));
$this->assertEquals(1,count($reader->getPropertyAnnotations($class->getProperty('foo'))));
$this->assertEquals(1,count($reader->getMethodAnnotations($class->getMethod('someFunction'))));
$this->assertEquals(1,count($reader->getPropertyAnnotations($class->getProperty('nested'))));
}
public function testAnnotationsWithVarType()
{
$reader = $this->getReader();
$class = new ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithVarType');
$this->assertEquals(1,count($fooAnnot = $reader->getPropertyAnnotations($class->getProperty('foo'))));
$this->assertEquals(1,count($barAnnot = $reader->getMethodAnnotations($class->getMethod('bar'))));
$this->assertInternalType('string', $fooAnnot[0]->string);
$this->assertInstanceOf('Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll', $barAnnot[0]->annotation);
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage [Semantical Error] Annotation @AnnotationTargetPropertyMethod is not allowed to be declared on class Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtClass. You may only use this annotation on these code elements: METHOD, PROPERTY
*/
public function testClassWithInvalidAnnotationTargetAtClassDocBlock()
{
$reader = $this->getReader();
$reader->getClassAnnotations(new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtClass'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage [Semantical Error] Annotation @AnnotationTargetClass is not allowed to be declared on property Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtProperty::$foo. You may only use this annotation on these code elements: CLASS
*/
public function testClassWithInvalidAnnotationTargetAtPropertyDocBlock()
{
$reader = $this->getReader();
$reader->getPropertyAnnotations(new \ReflectionProperty('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtProperty', 'foo'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage [Semantical Error] Annotation @AnnotationTargetAnnotation is not allowed to be declared on property Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtProperty::$bar. You may only use this annotation on these code elements: ANNOTATION
*/
public function testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock()
{
$reader = $this->getReader();
$reader->getPropertyAnnotations(new \ReflectionProperty('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtProperty', 'bar'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage [Semantical Error] Annotation @AnnotationTargetClass is not allowed to be declared on method Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtMethod::functionName(). You may only use this annotation on these code elements: CLASS
*/
public function testClassWithInvalidAnnotationTargetAtMethodDocBlock()
{
$reader = $this->getReader();
$reader->getMethodAnnotations(new \ReflectionMethod('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithInvalidAnnotationTargetAtMethod', 'functionName'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage Expected namespace separator or identifier, got ')' at position 24 in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError.
*/
public function testClassWithAnnotationWithTargetSyntaxErrorAtClassDocBlock()
{
$reader = $this->getReader();
$reader->getClassAnnotations(new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithTargetSyntaxError'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage Expected namespace separator or identifier, got ')' at position 24 in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError.
*/
public function testClassWithAnnotationWithTargetSyntaxErrorAtPropertyDocBlock()
{
$reader = $this->getReader();
$reader->getPropertyAnnotations(new \ReflectionProperty('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithTargetSyntaxError','foo'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage Expected namespace separator or identifier, got ')' at position 24 in class @Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError.
*/
public function testClassWithAnnotationWithTargetSyntaxErrorAtMethodDocBlock()
{
$reader = $this->getReader();
$reader->getMethodAnnotations(new \ReflectionMethod('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithTargetSyntaxError','bar'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage [Type Error] Attribute "string" of @AnnotationWithVarType declared on property Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithVarType::$invalidProperty expects a(n) string, but got integer.
*/
public function testClassWithPropertyInvalidVarTypeError()
{
$reader = $this->getReader();
$class = new ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithVarType');
$reader->getPropertyAnnotations($class->getProperty('invalidProperty'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage [Type Error] Attribute "annotation" of @AnnotationWithVarType declared on method Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithVarType::invalidMethod() expects a(n) Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll, but got an instance of Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation.
*/
public function testClassWithMethodInvalidVarTypeError()
{
$reader = $this->getReader();
$class = new ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithAnnotationWithVarType');
$reader->getMethodAnnotations($class->getMethod('invalidMethod'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage Expected namespace separator or identifier, got ')' at position 18 in class Doctrine\Tests\Common\Annotations\DummyClassSyntaxError.
*/
public function testClassSyntaxErrorContext()
{
$reader = $this->getReader();
$reader->getClassAnnotations(new \ReflectionClass('Doctrine\Tests\Common\Annotations\DummyClassSyntaxError'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage Expected namespace separator or identifier, got ')' at position 18 in method Doctrine\Tests\Common\Annotations\DummyClassMethodSyntaxError::foo().
*/
public function testMethodSyntaxErrorContext()
{
$reader = $this->getReader();
$reader->getMethodAnnotations(new \ReflectionMethod('Doctrine\Tests\Common\Annotations\DummyClassMethodSyntaxError', 'foo'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage Expected namespace separator or identifier, got ')' at position 18 in property Doctrine\Tests\Common\Annotations\DummyClassPropertySyntaxError::$foo.
*/
public function testPropertySyntaxErrorContext()
{
$reader = $this->getReader();
$reader->getPropertyAnnotations(new \ReflectionProperty('Doctrine\Tests\Common\Annotations\DummyClassPropertySyntaxError', 'foo'));
}
/**
* @group regression
*/
public function testMultipleAnnotationsOnSameLine()
{
$reader = $this->getReader();
$annots = $reader->getPropertyAnnotations(new \ReflectionProperty('Doctrine\Tests\Common\Annotations\DummyClass2', 'id'));
$this->assertEquals(3, count($annots));
}
public function testNonAnnotationProblem()
{
$reader = $this->getReader();
$this->assertNotNull($annot = $reader->getPropertyAnnotation(new \ReflectionProperty('Doctrine\Tests\Common\Annotations\DummyClassNonAnnotationProblem', 'foo'), $name = 'Doctrine\Tests\Common\Annotations\DummyAnnotation'));
$this->assertInstanceOf($name, $annot);
}
public function testImportWithConcreteAnnotation()
{
$reader = $this->getReader();
$property = new \ReflectionProperty('Doctrine\Tests\Common\Annotations\TestImportWithConcreteAnnotation', 'field');
$annotations = $reader->getPropertyAnnotations($property);
$this->assertEquals(1, count($annotations));
$this->assertNotNull($reader->getPropertyAnnotation($property, 'Doctrine\Tests\Common\Annotations\DummyAnnotation'));
}
public function testImportWithInheritance()
{
$reader = $this->getReader();
$class = new TestParentClass();
$ref = new \ReflectionClass($class);
$childAnnotations = $reader->getPropertyAnnotations($ref->getProperty('child'));
$this->assertEquals(1, count($childAnnotations));
$this->assertInstanceOf('Doctrine\Tests\Common\Annotations\Foo\Name', reset($childAnnotations));
$parentAnnotations = $reader->getPropertyAnnotations($ref->getProperty('parent'));
$this->assertEquals(1, count($parentAnnotations));
$this->assertInstanceOf('Doctrine\Tests\Common\Annotations\Bar\Name', reset($parentAnnotations));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage The annotation "@NameFoo" in property Doctrine\Tests\Common\Annotations\TestAnnotationNotImportedClass::$field was never imported.
*/
public function testImportDetectsNotImportedAnnotation()
{
$reader = $this->getReader();
$reader->getPropertyAnnotations(new \ReflectionProperty('Doctrine\Tests\Common\Annotations\TestAnnotationNotImportedClass', 'field'));
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage The annotation "@Foo\Bar\Name" in property Doctrine\Tests\Common\Annotations\TestNonExistentAnnotationClass::$field was never imported.
*/
public function testImportDetectsNonExistentAnnotation()
{
$reader = $this->getReader();
$reader->getPropertyAnnotations(new \ReflectionProperty('Doctrine\Tests\Common\Annotations\TestNonExistentAnnotationClass', 'field'));
}
public function testTopLevelAnnotation()
{
$reader = $this->getReader();
$annotations = $reader->getPropertyAnnotations(new \ReflectionProperty('Doctrine\Tests\Common\Annotations\TestTopLevelAnnotationClass', 'field'));
$this->assertEquals(1, count($annotations));
$this->assertInstanceOf('\TopLevelAnnotation', reset($annotations));
}
public function testIgnoresAnnotationsNotPrefixedWithWhitespace()
{
$reader = $this->getReader();
$annotation = $reader->getClassAnnotation(new \ReflectionClass(new TestIgnoresNonAnnotationsClass()), 'Doctrine\Tests\Common\Annotations\Name');
$this->assertInstanceOf('Doctrine\Tests\Common\Annotations\Name', $annotation);
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage The class "Doctrine\Tests\Common\Annotations\Fixtures\NoAnnotation" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "Doctrine\Tests\Common\Annotations\Fixtures\NoAnnotation". If it is indeed no annotation, then you need to add @IgnoreAnnotation("NoAnnotation") to the _class_ doc comment of class Doctrine\Tests\Common\Annotations\Fixtures\InvalidAnnotationUsageClass.
*/
public function testErrorWhenInvalidAnnotationIsUsed()
{
$reader = $this->getReader();
$ref = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\InvalidAnnotationUsageClass');
$reader->getClassAnnotations($ref);
}
public function testInvalidAnnotationUsageButIgnoredClass()
{
$reader = $this->getReader();
$ref = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\InvalidAnnotationUsageButIgnoredClass');
$annots = $reader->getClassAnnotations($ref);
$this->assertEquals(2, count($annots));
}
/**
* @group DDC-1660
* @group regression
*/
public function testInvalidAnnotationButIgnored()
{
$reader = $this->getReader();
$class = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassDDC1660');
$this->assertTrue(class_exists('Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Version'));
$this->assertCount(0, $reader->getClassAnnotations($class));
$this->assertCount(0, $reader->getMethodAnnotations($class->getMethod('bar')));
$this->assertCount(0, $reader->getPropertyAnnotations($class->getProperty('foo')));
}
abstract protected function getReader();
}
/**
* @parseAnnotation("var")
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
*/
class TestParseAnnotationClass
{
/**
* @var
*/
private $field;
}
/**
* @Name
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class TestIgnoresNonAnnotationsClass
{
}
class TestTopLevelAnnotationClass
{
/**
* @\TopLevelAnnotation
*/
private $field;
}
class TestNonExistentAnnotationClass
{
/**
* @Foo\Bar\Name
*/
private $field;
}
class TestAnnotationNotImportedClass
{
/**
* @NameFoo
*/
private $field;
}
class TestChildClass
{
/**
* @\Doctrine\Tests\Common\Annotations\Foo\Name(name = "foo")
*/
protected $child;
}
class TestParentClass extends TestChildClass
{
/**
* @\Doctrine\Tests\Common\Annotations\Bar\Name(name = "bar")
*/
private $parent;
}
class TestImportWithConcreteAnnotation
{
/**
* @DummyAnnotation(dummyValue = "bar")
*/
private $field;
}
/**
* @ignoreAnnotation("var")
*/
class DummyClass2 {
/**
* @DummyId @DummyColumn(type="integer") @DummyGeneratedValue
* @var integer
*/
private $id;
}
/** @Annotation */
class DummyId extends \Doctrine\Common\Annotations\Annotation {}
/** @Annotation */
class DummyColumn extends \Doctrine\Common\Annotations\Annotation {
public $type;
}
/** @Annotation */
class DummyGeneratedValue extends \Doctrine\Common\Annotations\Annotation {}
/** @Annotation */
class DummyAnnotation extends \Doctrine\Common\Annotations\Annotation {
public $dummyValue;
}
/** @Annotation */
class DummyJoinColumn extends \Doctrine\Common\Annotations\Annotation {
public $name;
public $referencedColumnName;
}
/** @Annotation */
class DummyJoinTable extends \Doctrine\Common\Annotations\Annotation {
public $name;
public $joinColumns;
public $inverseJoinColumns;
}
/**
* @DummyAnnotation(@)
*/
class DummyClassSyntaxError
{
}
class DummyClassMethodSyntaxError
{
/**
* @DummyAnnotation(@)
*/
public function foo()
{
}
}
class DummyClassPropertySyntaxError
{
/**
* @DummyAnnotation(@)
*/
public $foo;
}
/**
* @ignoreAnnotation({"since", "var"})
*/
class DummyClassNonAnnotationProblem
{
/**
* @DummyAnnotation
*
* @var \Test
* @since 0.1
*/
public $foo;
}
/**
* @DummyAnnotation Foo bar <foobar@1domain.com>
*/
class DummyClassWithEmail
{
}
namespace Doctrine\Tests\Common\Annotations\Foo;
/** @Annotation */
class Name extends \Doctrine\Common\Annotations\Annotation
{
public $name;
}
namespace Doctrine\Tests\Common\Annotations\Bar;
/** @Annotation */
class Name extends \Doctrine\Common\Annotations\Annotation
{
public $name;
}

View file

@ -0,0 +1,13 @@
<?php
namespace Doctrine\Tests\Common\Annotations;
use Doctrine\Common\Annotations\AnnotationReader;
class AnnotationReaderTest extends AbstractReaderTest
{
protected function getReader()
{
return new AnnotationReader();
}
}

View file

@ -0,0 +1,56 @@
<?php
namespace Doctrine\Tests\Common\Annotations;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Cache\ArrayCache;
class CachedReaderTest extends AbstractReaderTest
{
private $cache;
public function testIgnoresStaleCache()
{
$file = __DIR__.'/Fixtures/Controller.php';
touch($file);
$name = 'Doctrine\Tests\Common\Annotations\Fixtures\Controller';
$cacheKey = $name.'@[Annot]';
$cache = $this->getMock('Doctrine\Common\Cache\Cache');
$cache
->expects($this->at(0))
->method('fetch')
->with($this->equalTo($cacheKey))
->will($this->returnValue(array()))
;
$cache
->expects($this->at(1))
->method('fetch')
->with($this->equalTo('[C]'.$cacheKey))
->will($this->returnValue(time() - 10))
;
$cache
->expects($this->at(2))
->method('save')
->with($this->equalTo($cacheKey))
;
$cache
->expects($this->at(3))
->method('save')
->with($this->equalTo('[C]'.$cacheKey))
;
$reader = new CachedReader(new AnnotationReader(), $cache, true);
$route = new Route();
$route->pattern = '/someprefix';
$this->assertEquals(array($route), $reader->getClassAnnotations(new \ReflectionClass($name)));
}
protected function getReader()
{
$this->cache = new ArrayCache();
return new CachedReader(new AnnotationReader(), $this->cache);
}
}

View file

@ -0,0 +1,137 @@
<?php
namespace Doctrine\Tests\Common\Annotations;
use Doctrine\Common\Annotations\DocLexer;
class DocLexerTest extends \PHPUnit_Framework_TestCase
{
public function testMarkerAnnotation()
{
$lexer = new DocLexer;
$lexer->setInput("@Name");
$this->assertNull($lexer->token);
$this->assertNull($lexer->lookahead);
$this->assertTrue($lexer->moveNext());
$this->assertNull($lexer->token);
$this->assertEquals('@', $lexer->lookahead['value']);
$this->assertTrue($lexer->moveNext());
$this->assertEquals('@', $lexer->token['value']);
$this->assertEquals('Name', $lexer->lookahead['value']);
$this->assertFalse($lexer->moveNext());
}
public function testScannerTokenizesDocBlockWhitConstants()
{
$lexer = new DocLexer();
$docblock = '@AnnotationWithConstants(PHP_EOL, ClassWithConstants::SOME_VALUE, \Doctrine\Tests\Common\Annotations\Fixtures\IntefaceWithConstants::SOME_VALUE)';
$tokens = array (
array(
'value' => '@',
'position' => 0,
'type' => DocLexer::T_AT,
),
array(
'value' => 'AnnotationWithConstants',
'position' => 1,
'type' => DocLexer::T_IDENTIFIER,
),
array(
'value' => '(',
'position' => 24,
'type' => DocLexer::T_OPEN_PARENTHESIS,
),
array(
'value' => 'PHP_EOL',
'position' => 25,
'type' => DocLexer::T_IDENTIFIER,
),
array(
'value' => ',',
'position' => 32,
'type' => DocLexer::T_COMMA,
),
array(
'value' => 'ClassWithConstants::SOME_VALUE',
'position' => 34,
'type' => DocLexer::T_IDENTIFIER,
),
array(
'value' => ',',
'position' => 64,
'type' => DocLexer::T_COMMA,
),
array(
'value' => '\\Doctrine\\Tests\\Common\\Annotations\\Fixtures\\IntefaceWithConstants::SOME_VALUE',
'position' => 66,
'type' => DocLexer::T_IDENTIFIER,
),
array(
'value' => ')',
'position' => 143,
'type' => DocLexer::T_CLOSE_PARENTHESIS,
)
);
$lexer->setInput($docblock);
foreach ($tokens as $expected) {
$lexer->moveNext();
$lookahead = $lexer->lookahead;
$this->assertEquals($expected['value'], $lookahead['value']);
$this->assertEquals($expected['type'], $lookahead['type']);
$this->assertEquals($expected['position'], $lookahead['position']);
}
$this->assertFalse($lexer->moveNext());
}
public function testScannerTokenizesDocBlockWhitInvalidIdentifier()
{
$lexer = new DocLexer();
$docblock = '@Foo\3.42';
$tokens = array (
array(
'value' => '@',
'position' => 0,
'type' => DocLexer::T_AT,
),
array(
'value' => 'Foo',
'position' => 1,
'type' => DocLexer::T_IDENTIFIER,
),
array(
'value' => '\\',
'position' => 4,
'type' => DocLexer::T_NAMESPACE_SEPARATOR,
),
array(
'value' => 3.42,
'position' => 5,
'type' => DocLexer::T_FLOAT,
)
);
$lexer->setInput($docblock);
foreach ($tokens as $expected) {
$lexer->moveNext();
$lookahead = $lexer->lookahead;
$this->assertEquals($expected['value'], $lookahead['value']);
$this->assertEquals($expected['type'], $lookahead['type']);
$this->assertEquals($expected['position'], $lookahead['position']);
}
$this->assertFalse($lexer->moveNext());
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,48 @@
<?php
namespace Doctrine\Tests\Common\Annotations;
use Doctrine\Tests\Common\Annotations\DummyAnnotation;
use Doctrine\Tests\Common\Annotations\Name;
use Doctrine\Tests\Common\Annotations\DummyJoinTable;
use Doctrine\Tests\Common\Annotations\DummyJoinColumn;
/**
* A description of this class.
*
* Let's see if the parser recognizes that this @ is not really referring to an
* annotation. Also make sure that @var \ is not concated to "@var\is".
*
* @author robo
* @since 2.0
* @DummyAnnotation(dummyValue="hello")
*/
class DummyClass
{
/**
* A nice property.
*
* @var mixed
* @DummyAnnotation(dummyValue="fieldHello")
*/
private $field1;
/**
* @DummyJoinTable(name="join_table",
* joinColumns={@DummyJoinColumn(name="col1", referencedColumnName="col2")},
* inverseJoinColumns={
* @DummyJoinColumn(name="col3", referencedColumnName="col4")
* })
*/
private $field2;
/**
* Gets the value of field1.
*
* @return mixed
* @DummyAnnotation({1,2,"three"})
*/
public function getField1()
{
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Doctrine\Tests\Common\Annotations;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\FileCacheReader;
class FileCacheReaderTest extends AbstractReaderTest
{
private $cacheDir;
protected function getReader()
{
$this->cacheDir = sys_get_temp_dir() . "/annotations_". uniqid();
@mkdir($this->cacheDir);
return new FileCacheReader(new AnnotationReader(), $this->cacheDir);
}
public function tearDown()
{
foreach (glob($this->cacheDir.'/*.php') AS $file) {
unlink($file);
}
rmdir($this->cacheDir);
}
/**
* @group DCOM-81
*/
public function testAttemptToCreateAnnotationCacheDir()
{
$this->cacheDir = sys_get_temp_dir() . "/not_existed_dir_". uniqid();
$this->assertFalse(is_dir($this->cacheDir));
$cache = new FileCacheReader(new AnnotationReader(), $this->cacheDir);
$this->assertTrue(is_dir($this->cacheDir));
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures\Annotation;
/** @Annotation */
class AnnotWithDefaultValue
{
/** @var string */
public $foo = 'bar';
}

View file

@ -0,0 +1,10 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures\Annotation;
/**
* @Annotation
*/
class Autoload
{
}

View file

@ -0,0 +1,11 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures\Annotation;
/** @Annotation */
class Route
{
/** @var string @Required */
public $pattern;
public $name;
}

View file

@ -0,0 +1,18 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures\Annotation;
/** @Annotation */
class Secure
{
private $roles;
public function __construct(array $values)
{
if (is_string($values['value'])) {
$values['value'] = array($values['value']);
}
$this->roles = $values['value'];
}
}

View file

@ -0,0 +1,14 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures\Annotation;
/** @Annotation */
class Template
{
private $name;
public function __construct(array $values)
{
$this->name = isset($values['value']) ? $values['value'] : null;
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures\Annotation;
/**
* @Annotation
* @Target("PROPERTY")
*/
final class Version
{
}

View file

@ -0,0 +1,14 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target("ALL")
*/
class AnnotationTargetAll
{
public $data;
public $name;
public $target;
}

View file

@ -0,0 +1,14 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target({ "ANNOTATION" })
*/
final class AnnotationTargetAnnotation
{
public $data;
public $name;
public $target;
}

View file

@ -0,0 +1,15 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target("CLASS")
*/
final class AnnotationTargetClass
{
public $data;
public $name;
public $target;
}

View file

@ -0,0 +1,15 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target("METHOD")
*/
final class AnnotationTargetMethod
{
public $data;
public $name;
public $target;
}

View file

@ -0,0 +1,14 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target({ "METHOD", "PROPERTY" })
*/
final class AnnotationTargetPropertyMethod
{
public $data;
public $name;
public $target;
}

View file

@ -0,0 +1,119 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target("ALL")
* @Attributes({
@Attribute("mixed", type = "mixed"),
@Attribute("boolean", type = "boolean"),
@Attribute("bool", type = "bool"),
@Attribute("float", type = "float"),
@Attribute("string", type = "string"),
@Attribute("integer", type = "integer"),
@Attribute("array", type = "array"),
@Attribute("arrayOfIntegers", type = "array<integer>"),
@Attribute("annotation", type = "Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll"),
@Attribute("arrayOfAnnotations", type = "array<Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll>"),
})
*/
final class AnnotationWithAttributes
{
public final function __construct(array $data)
{
foreach ($data as $key => $value) {
$this->$key = $value;
}
}
private $mixed;
private $boolean;
private $bool;
private $float;
private $string;
private $integer;
private $array;
private $annotation;
private $arrayOfIntegers;
private $arrayOfAnnotations;
/**
* @return mixed
*/
public function getMixed()
{
return $this->mixed;
}
/**
* @return boolean
*/
public function getBoolean()
{
return $this->boolean;
}
/**
* @return bool
*/
public function getBool()
{
return $this->bool;
}
/**
* @return float
*/
public function getFloat()
{
return $this->float;
}
/**
* @return string
*/
public function getString()
{
return $this->string;
}
public function getInteger()
{
return $this->integer;
}
/**
* @return array
*/
public function getArray()
{
return $this->array;
}
/**
* @return Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll
*/
public function getAnnotation()
{
return $this->annotation;
}
/**
* @return array<integer>
*/
public function getArrayOfIntegers()
{
return $this->arrayOfIntegers;
}
/**
* @return array<Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll>
*/
public function getArrayOfAnnotations()
{
return $this->arrayOfAnnotations;
}
}

View file

@ -0,0 +1,20 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target("ALL")
*/
final class AnnotationWithConstants
{
const INTEGER = 1;
const FLOAT = 1.2;
const STRING = '1.2.3';
/**
* @var mixed
*/
public $value;
}

View file

@ -0,0 +1,50 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target("ALL")
* @Attributes({
@Attribute("value", required = true , type = "string"),
@Attribute("annot", required = true , type = "Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation"),
})
*/
final class AnnotationWithRequiredAttributes
{
public final function __construct(array $data)
{
foreach ($data as $key => $value) {
$this->$key = $value;
}
}
/**
* @var string
*/
private $value;
/**
*
* @var Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation
*/
private $annot;
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* @return Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation
*/
public function getAnnot()
{
return $this->annot;
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target("ALL")
*/
final class AnnotationWithRequiredAttributesWithoutContructor
{
/**
* @Required
* @var string
*/
public $value;
/**
* @Required
* @var Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation
*/
public $annot;
}

View file

@ -0,0 +1,11 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target(@)
*/
final class AnnotationWithTargetSyntaxError
{
}

View file

@ -0,0 +1,62 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @Annotation
* @Target("ALL")
*/
final class AnnotationWithVarType
{
/**
* @var mixed
*/
public $mixed;
/**
* @var boolean
*/
public $boolean;
/**
* @var bool
*/
public $bool;
/**
* @var float
*/
public $float;
/**
* @var string
*/
public $string;
/**
* @var integer
*/
public $integer;
/**
* @var array
*/
public $array;
/**
* @var Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll
*/
public $annotation;
/**
* @var array<integer>
*/
public $arrayOfIntegers;
/**
* @var array<Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll>
*/
public $arrayOfAnnotations;
}

View file

@ -0,0 +1,30 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @since 2.0
* @version $Id: SomeEntityClass.php 509 2012-02-03 09:38:48Z mf $
*/
class ClassDDC1660
{
/**
* @var string
* @since 2.0
* @version 1
*/
public $foo;
/**
* @param string
* @return string
* @since 2.0
* @version 1
*/
public function bar($param)
{
return null;
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithTargetSyntaxError;
/**
* @AnnotationWithTargetSyntaxError()
*/
class ClassWithAnnotationWithTargetSyntaxError
{
/**
* @AnnotationWithTargetSyntaxError()
*/
public $foo;
/**
* @AnnotationWithTargetSyntaxError()
*/
public function bar(){}
}

View file

@ -0,0 +1,31 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithVarType;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation;
class ClassWithAnnotationWithVarType
{
/**
* @AnnotationWithVarType(string = "String Value")
*/
public $foo;
/**
* @AnnotationWithVarType(annotation = @AnnotationTargetAll)
*/
public function bar(){}
/**
* @AnnotationWithVarType(string = 123)
*/
public $invalidProperty;
/**
* @AnnotationWithVarType(annotation = @AnnotationTargetAnnotation)
*/
public function invalidMethod(){}
}

View file

@ -0,0 +1,52 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation;
/**
* @AnnotationTargetAll("Foo")
*/
final class ClassWithClosure
{
/**
* @AnnotationTargetAll(@AnnotationTargetAnnotation)
* @var string
*/
public $value;
/**
* @AnnotationTargetAll(@AnnotationTargetAnnotation)
*
* @param \Closure $callback
* @return \Closure
*/
public function methodName(\Closure $callback)
{
$self = $this;
return function() use ($self, $callback) {
return $callback;
};
}
/**
* @param integer $year
* @param integer $month
* @param integer $day
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getEventsForDate($year, $month, $day){
$extractEvents = null; // check if date of item is inside day given
$extractEvents = $this->events->filter(function ($item) use ($year, $month, $day) {
$leftDate = new \DateTime($year.'-'.$month.'-'.$day.' 00:00');
$rigthDate = new \DateTime($year.'-'.$month.'-'.$day.' +1 day 00:00');
return ( ( $leftDate <= $item->getDateStart() ) && ( $item->getDateStart() < $rigthDate ) );
}
);
return $extractEvents;
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
class ClassWithConstants
{
const SOME_VALUE = 'ClassWithConstants.SOME_VALUE';
const SOME_KEY = 'ClassWithConstants.SOME_KEY';
}

View file

@ -0,0 +1,11 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use
\Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure,
\Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route
;
use \Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;
class ClassWithFullyQualifiedUseStatements {}

View file

@ -0,0 +1,17 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetPropertyMethod;
/**
* @AnnotationTargetPropertyMethod("Some data")
*/
class ClassWithInvalidAnnotationTargetAtClass
{
/**
* @AnnotationTargetPropertyMethod("Bar")
*/
public $foo;
}

View file

@ -0,0 +1,20 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetClass;
/**
* @AnnotationTargetClass("Some data")
*/
class ClassWithInvalidAnnotationTargetAtMethod
{
/**
* @AnnotationTargetClass("functionName")
*/
public function functionName($param)
{
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetClass;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAnnotation;
/**
* @AnnotationTargetClass("Some data")
*/
class ClassWithInvalidAnnotationTargetAtProperty
{
/**
* @AnnotationTargetClass("Bar")
*/
public $foo;
/**
* @AnnotationTargetAnnotation("Foo")
*/
public $bar;
}

View file

@ -0,0 +1,41 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetClass;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetPropertyMethod;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetNestedAnnotation;
/**
* @AnnotationTargetClass("Some data")
*/
class ClassWithValidAnnotationTarget
{
/**
* @AnnotationTargetPropertyMethod("Some data")
*/
public $foo;
/**
* @AnnotationTargetAll("Some data",name="Some name")
*/
public $name;
/**
* @AnnotationTargetPropertyMethod("Some data",name="Some name")
*/
public function someFunction()
{
}
/**
* @AnnotationTargetAll(@AnnotationTargetAnnotation)
*/
public $nested;
}

View file

@ -0,0 +1,300 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
/**
* @Route("/someprefix")
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class Controller
{
/**
* @Route("/", name="_demo")
* @Template()
*/
public function indexAction()
{
return array();
}
/**
* @Route("/hello/{name}", name="_demo_hello")
* @Template()
*/
public function helloAction($name)
{
return array('name' => $name);
}
/**
* @Route("/contact", name="_demo_contact")
* @Template()
*/
public function contactAction()
{
$form = ContactForm::create($this->get('form.context'), 'contact');
$form->bind($this->container->get('request'), $form);
if ($form->isValid()) {
$form->send($this->get('mailer'));
$this->get('session')->setFlash('notice', 'Message sent!');
return new RedirectResponse($this->generateUrl('_demo'));
}
return array('form' => $form);
}
/**
* Creates the ACL for the passed object identity
*
* @param ObjectIdentityInterface $oid
* @return void
*/
private function createObjectIdentity(ObjectIdentityInterface $oid)
{
$classId = $this->createOrRetrieveClassId($oid->getType());
$this->connection->executeQuery($this->getInsertObjectIdentitySql($oid->getIdentifier(), $classId, true));
}
/**
* Returns the primary key for the passed class type.
*
* If the type does not yet exist in the database, it will be created.
*
* @param string $classType
* @return integer
*/
private function createOrRetrieveClassId($classType)
{
if (false !== $id = $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn()) {
return $id;
}
$this->connection->executeQuery($this->getInsertClassSql($classType));
return $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn();
}
/**
* Returns the primary key for the passed security identity.
*
* If the security identity does not yet exist in the database, it will be
* created.
*
* @param SecurityIdentityInterface $sid
* @return integer
*/
private function createOrRetrieveSecurityIdentityId(SecurityIdentityInterface $sid)
{
if (false !== $id = $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn()) {
return $id;
}
$this->connection->executeQuery($this->getInsertSecurityIdentitySql($sid));
return $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn();
}
/**
* Deletes all ACEs for the given object identity primary key.
*
* @param integer $oidPK
* @return void
*/
private function deleteAccessControlEntries($oidPK)
{
$this->connection->executeQuery($this->getDeleteAccessControlEntriesSql($oidPK));
}
/**
* Deletes the object identity from the database.
*
* @param integer $pk
* @return void
*/
private function deleteObjectIdentity($pk)
{
$this->connection->executeQuery($this->getDeleteObjectIdentitySql($pk));
}
/**
* Deletes all entries from the relations table from the database.
*
* @param integer $pk
* @return void
*/
private function deleteObjectIdentityRelations($pk)
{
$this->connection->executeQuery($this->getDeleteObjectIdentityRelationsSql($pk));
}
/**
* This regenerates the ancestor table which is used for fast read access.
*
* @param AclInterface $acl
* @return void
*/
private function regenerateAncestorRelations(AclInterface $acl)
{
$pk = $acl->getId();
$this->connection->executeQuery($this->getDeleteObjectIdentityRelationsSql($pk));
$this->connection->executeQuery($this->getInsertObjectIdentityRelationSql($pk, $pk));
$parentAcl = $acl->getParentAcl();
while (null !== $parentAcl) {
$this->connection->executeQuery($this->getInsertObjectIdentityRelationSql($pk, $parentAcl->getId()));
$parentAcl = $parentAcl->getParentAcl();
}
}
/**
* This processes changes on an ACE related property (classFieldAces, or objectFieldAces).
*
* @param string $name
* @param array $changes
* @return void
*/
private function updateFieldAceProperty($name, array $changes)
{
$sids = new \SplObjectStorage();
$classIds = new \SplObjectStorage();
$currentIds = array();
foreach ($changes[1] as $field => $new) {
for ($i=0,$c=count($new); $i<$c; $i++) {
$ace = $new[$i];
if (null === $ace->getId()) {
if ($sids->contains($ace->getSecurityIdentity())) {
$sid = $sids->offsetGet($ace->getSecurityIdentity());
} else {
$sid = $this->createOrRetrieveSecurityIdentityId($ace->getSecurityIdentity());
}
$oid = $ace->getAcl()->getObjectIdentity();
if ($classIds->contains($oid)) {
$classId = $classIds->offsetGet($oid);
} else {
$classId = $this->createOrRetrieveClassId($oid->getType());
}
$objectIdentityId = $name === 'classFieldAces' ? null : $ace->getAcl()->getId();
$this->connection->executeQuery($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, $field, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, $field, $i))->fetchColumn();
$this->loadedAces[$aceId] = $ace;
$aceIdProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Entry', 'id');
$aceIdProperty->setAccessible(true);
$aceIdProperty->setValue($ace, intval($aceId));
} else {
$currentIds[$ace->getId()] = true;
}
}
}
foreach ($changes[0] as $old) {
for ($i=0,$c=count($old); $i<$c; $i++) {
$ace = $old[$i];
if (!isset($currentIds[$ace->getId()])) {
$this->connection->executeQuery($this->getDeleteAccessControlEntrySql($ace->getId()));
unset($this->loadedAces[$ace->getId()]);
}
}
}
}
/**
* This processes changes on an ACE related property (classAces, or objectAces).
*
* @param string $name
* @param array $changes
* @return void
*/
private function updateAceProperty($name, array $changes)
{
list($old, $new) = $changes;
$sids = new \SplObjectStorage();
$classIds = new \SplObjectStorage();
$currentIds = array();
for ($i=0,$c=count($new); $i<$c; $i++) {
$ace = $new[$i];
if (null === $ace->getId()) {
if ($sids->contains($ace->getSecurityIdentity())) {
$sid = $sids->offsetGet($ace->getSecurityIdentity());
} else {
$sid = $this->createOrRetrieveSecurityIdentityId($ace->getSecurityIdentity());
}
$oid = $ace->getAcl()->getObjectIdentity();
if ($classIds->contains($oid)) {
$classId = $classIds->offsetGet($oid);
} else {
$classId = $this->createOrRetrieveClassId($oid->getType());
}
$objectIdentityId = $name === 'classAces' ? null : $ace->getAcl()->getId();
$this->connection->executeQuery($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, null, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, null, $i))->fetchColumn();
$this->loadedAces[$aceId] = $ace;
$aceIdProperty = new \ReflectionProperty($ace, 'id');
$aceIdProperty->setAccessible(true);
$aceIdProperty->setValue($ace, intval($aceId));
} else {
$currentIds[$ace->getId()] = true;
}
}
for ($i=0,$c=count($old); $i<$c; $i++) {
$ace = $old[$i];
if (!isset($currentIds[$ace->getId()])) {
$this->connection->executeQuery($this->getDeleteAccessControlEntrySql($ace->getId()));
unset($this->loadedAces[$ace->getId()]);
}
}
}
/**
* Persists the changes which were made to ACEs to the database.
*
* @param \SplObjectStorage $aces
* @return void
*/
private function updateAces(\SplObjectStorage $aces)
{
foreach ($aces as $ace) {
$propertyChanges = $aces->offsetGet($ace);
$sets = array();
if (isset($propertyChanges['mask'])) {
$sets[] = sprintf('mask = %d', $propertyChanges['mask'][1]);
}
if (isset($propertyChanges['strategy'])) {
$sets[] = sprintf('granting_strategy = %s', $this->connection->quote($propertyChanges['strategy']));
}
if (isset($propertyChanges['aceOrder'])) {
$sets[] = sprintf('ace_order = %d', $propertyChanges['aceOrder'][1]);
}
if (isset($propertyChanges['auditSuccess'])) {
$sets[] = sprintf('audit_success = %s', $this->connection->getDatabasePlatform()->convertBooleans($propertyChanges['auditSuccess'][1]));
}
if (isset($propertyChanges['auditFailure'])) {
$sets[] = sprintf('audit_failure = %s', $this->connection->getDatabasePlatform()->convertBooleans($propertyChanges['auditFailure'][1]));
}
$this->connection->executeQuery($this->getUpdateAccessControlEntrySql($ace->getId(), $sets));
}
}
}

View file

@ -0,0 +1,15 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure;
class DifferentNamespacesPerFileWithClassAsFirst {}
}
namespace {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
}
namespace Doctrine\Tests\Common\Annotations\Fixtures\Foo {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;
}

View file

@ -0,0 +1,15 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures\Foo {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure;
}
namespace {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
}
namespace Doctrine\Tests\Common\Annotations\Fixtures {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;
class DifferentNamespacesPerFileWithClassAsLast {}
}

View file

@ -0,0 +1,13 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
class EqualNamespacesPerFileWithClassAsFirst {}
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;

View file

@ -0,0 +1,12 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure;
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;
class EqualNamespacesPerFileWithClassAsLast {}

View file

@ -0,0 +1,12 @@
<?php
namespace {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
class GlobalNamespacesPerFileWithClassAsFirst {}
}
namespace {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;
}

View file

@ -0,0 +1,12 @@
<?php
namespace {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure;
}
namespace {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;
class GlobalNamespacesPerFileWithClassAsLast {}
}

View file

@ -0,0 +1,10 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
interface IntefaceWithConstants
{
const SOME_VALUE = 'IntefaceWithConstants.SOME_VALUE';
const SOME_KEY = 'IntefaceWithConstants.SOME_KEY';
}

View file

@ -0,0 +1,14 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
/**
* @NoAnnotation
* @IgnoreAnnotation("NoAnnotation")
* @Route("foo")
*/
class InvalidAnnotationUsageButIgnoredClass
{
}

View file

@ -0,0 +1,10 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
/**
* @NoAnnotation
*/
class InvalidAnnotationUsageClass
{
}

View file

@ -0,0 +1,9 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
class AnotherClass { }
class MultipleClassesInFile { }

View file

@ -0,0 +1,10 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use
Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route,
Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure
;
class MultipleImportsInUseStatement {}

View file

@ -0,0 +1,20 @@
<?php
// namespace Doctrine\Tests\Common\Annotations\Fixtures;
namespace Doctrine\Tests\Common\Annotations\Fixtures\Foo {
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure;
// class NamespaceAndClassCommentedOut {}
}
namespace Doctrine\Tests\Common\Annotations\Fixtures {
// class NamespaceAndClassCommentedOut {}
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
// namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;
class NamespaceAndClassCommentedOut {}
}

View file

@ -0,0 +1,15 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
$var = 1;
function () use ($var) {};
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;
$var = 1;
function () use ($var) {};
class NamespaceWithClosureDeclaration {}

View file

@ -0,0 +1,5 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
class NoAnnotation {}

View file

@ -0,0 +1,10 @@
<?php
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
/**
* @Route("foo")
* @Template
*/
class AnnotationsTestsFixturesNonNamespacedClass { }

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Fixtures;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure;
interface TestInterface
{
/**
* @Secure
*/
function foo();
}

View file

@ -0,0 +1,194 @@
<?php
namespace Doctrine\Tests\Common\Annotations;
use Doctrine\Common\Annotations\FileCacheReader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\DocLexer;
use Doctrine\Common\Annotations\DocParser;
use Doctrine\Common\Annotations\PhpParser;
use Doctrine\Common\Annotations\AnnotationReader;
require_once __DIR__ . '/Fixtures/Annotation/Route.php';
require_once __DIR__ . '/Fixtures/Annotation/Template.php';
require_once __DIR__ . '/Fixtures/Annotation/Secure.php';
require_once __DIR__ . '/Fixtures/SingleClassLOC1000.php';
class PerformanceTest extends \PHPUnit_Framework_TestCase
{
/**
* @group performance
*/
public function testCachedReadPerformanceWithInMemory()
{
$reader = new CachedReader(new AnnotationReader(), new ArrayCache());
$method = $this->getMethod();
$time = microtime(true);
for ($i=0,$c=500; $i<$c; $i++) {
$reader->getMethodAnnotations($method);
}
$time = microtime(true) - $time;
$this->printResults('cached reader (in-memory)', $time, $c);
}
/**
* @group performance
*/
public function testCachedReadPerformanceWithFileCache()
{
$method = $this->getMethod();
// prime cache
$reader = new FileCacheReader(new AnnotationReader(), sys_get_temp_dir());
$reader->getMethodAnnotations($method);
$time = microtime(true);
for ($i=0,$c=500; $i<$c; $i++) {
$reader = new FileCacheReader(new AnnotationReader(), sys_get_temp_dir());
$reader->getMethodAnnotations($method);
clearstatcache();
}
$time = microtime(true) - $time;
$this->printResults('cached reader (file)', $time, $c);
}
/**
* @group performance
*/
public function testReadPerformance()
{
$method = $this->getMethod();
$time = microtime(true);
for ($i=0,$c=150; $i<$c; $i++) {
$reader = new AnnotationReader();
$reader->getMethodAnnotations($method);
}
$time = microtime(true) - $time;
$this->printResults('reader', $time, $c);
}
/**
* @group performance
*/
public function testDocParsePerformance()
{
$imports = array(
'ignorephpdoc' => 'Annotations\Annotation\IgnorePhpDoc',
'ignoreannotation' => 'Annotations\Annotation\IgnoreAnnotation',
'route' => 'Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route',
'template' => 'Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template',
'__NAMESPACE__' => 'Doctrine\Tests\Common\Annotations\Fixtures',
);
$ignored = array(
'access', 'author', 'copyright', 'deprecated', 'example', 'ignore',
'internal', 'link', 'see', 'since', 'tutorial', 'version', 'package',
'subpackage', 'name', 'global', 'param', 'return', 'staticvar',
'static', 'var', 'throws', 'inheritdoc',
);
$method = $this->getMethod();
$methodComment = $method->getDocComment();
$classComment = $method->getDeclaringClass()->getDocComment();
$time = microtime(true);
for ($i=0,$c=200; $i<$c; $i++) {
$parser = new DocParser();
$parser->setImports($imports);
$parser->setIgnoredAnnotationNames($ignored);
$parser->setIgnoreNotImportedAnnotations(true);
$parser->parse($methodComment);
$parser->parse($classComment);
}
$time = microtime(true) - $time;
$this->printResults('doc-parser', $time, $c);
}
/**
* @group performance
*/
public function testDocLexerPerformance()
{
$method = $this->getMethod();
$methodComment = $method->getDocComment();
$classComment = $method->getDeclaringClass()->getDocComment();
$time = microtime(true);
for ($i=0,$c=500; $i<$c; $i++) {
$lexer = new DocLexer();
$lexer->setInput($methodComment);
$lexer->setInput($classComment);
}
$time = microtime(true) - $time;
$this->printResults('doc-lexer', $time, $c);
}
/**
* @group performance
*/
public function testPhpParserPerformanceWithShortCut()
{
$class = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\NamespacedSingleClassLOC1000');
$time = microtime(true);
for ($i=0,$c=500; $i<$c; $i++) {
$parser = new PhpParser();
$parser->parseClass($class);
}
$time = microtime(true) - $time;
$this->printResults('doc-parser-with-short-cut', $time, $c);
}
/**
* @group performance
*/
public function testPhpParserPerformanceWithoutShortCut()
{
$class = new \ReflectionClass('SingleClassLOC1000');
$time = microtime(true);
for ($i=0,$c=500; $i<$c; $i++) {
$parser = new PhpParser();
$parser->parseClass($class);
}
$time = microtime(true) - $time;
$this->printResults('doc-parser-without-short-cut', $time, $c);
}
private function getMethod()
{
return new \ReflectionMethod('Doctrine\Tests\Common\Annotations\Fixtures\Controller', 'helloAction');
}
private function printResults($test, $time, $iterations)
{
if (0 == $iterations) {
throw new \InvalidArgumentException('$iterations cannot be zero.');
}
$title = $test." results:\n";
$iterationsText = sprintf("Iterations: %d\n", $iterations);
$totalTime = sprintf("Total Time: %.3f s\n", $time);
$iterationTime = sprintf("Time per iteration: %.3f ms\n", $time/$iterations * 1000);
$max = max(strlen($title), strlen($iterationTime)) - 1;
echo "\n".str_repeat('-', $max)."\n";
echo $title;
echo str_repeat('=', $max)."\n";
echo $iterationsText;
echo $totalTime;
echo $iterationTime;
echo str_repeat('-', $max)."\n";
}
}

View file

@ -0,0 +1,194 @@
<?php
namespace Doctrine\Tests\Common\Annotations;
use ReflectionClass;
use Doctrine\Common\Annotations\PhpParser;
require_once __DIR__.'/Fixtures/NonNamespacedClass.php';
require_once __DIR__.'/Fixtures/GlobalNamespacesPerFileWithClassAsFirst.php';
require_once __DIR__.'/Fixtures/GlobalNamespacesPerFileWithClassAsLast.php';
class PhpParserTest extends \PHPUnit_Framework_TestCase
{
public function testParseClassWithMultipleClassesInFile()
{
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\MultipleClassesInFile');
$parser = new PhpParser();
$this->assertEquals(array(
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
'secure' => __NAMESPACE__ . '\Fixtures\Annotation\Secure',
), $parser->parseClass($class));
}
public function testParseClassWithMultipleImportsInUseStatement()
{
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\MultipleImportsInUseStatement');
$parser = new PhpParser();
$this->assertEquals(array(
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
'secure' => __NAMESPACE__ . '\Fixtures\Annotation\Secure',
), $parser->parseClass($class));
}
public function testParseClassWhenNotUserDefined()
{
$parser = new PhpParser();
$this->assertEquals(array(), $parser->parseClass(new \ReflectionClass('\stdClass')));
}
public function testParseClassWhenClassIsNotNamespaced()
{
$parser = new PhpParser();
$class = new ReflectionClass('\AnnotationsTestsFixturesNonNamespacedClass');
$this->assertEquals(array(
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
'template' => __NAMESPACE__ . '\Fixtures\Annotation\Template',
), $parser->parseClass($class));
}
public function testParseClassWhenClassIsInterface()
{
$parser = new PhpParser();
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\TestInterface');
$this->assertEquals(array(
'secure' => __NAMESPACE__ . '\Fixtures\Annotation\Secure',
), $parser->parseClass($class));
}
public function testClassWithFullyQualifiedUseStatements()
{
$parser = new PhpParser();
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\ClassWithFullyQualifiedUseStatements');
$this->assertEquals(array(
'secure' => '\\' . __NAMESPACE__ . '\Fixtures\Annotation\Secure',
'route' => '\\' . __NAMESPACE__ . '\Fixtures\Annotation\Route',
'template' => '\\' . __NAMESPACE__ . '\Fixtures\Annotation\Template',
), $parser->parseClass($class));
}
public function testNamespaceAndClassCommentedOut()
{
$parser = new PhpParser();
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\NamespaceAndClassCommentedOut');
$this->assertEquals(array(
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
'template' => __NAMESPACE__ . '\Fixtures\Annotation\Template',
), $parser->parseClass($class));
}
public function testEqualNamespacesPerFileWithClassAsFirst()
{
$parser = new PhpParser();
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\EqualNamespacesPerFileWithClassAsFirst');
$this->assertEquals(array(
'secure' => __NAMESPACE__ . '\Fixtures\Annotation\Secure',
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
), $parser->parseClass($class));
}
public function testEqualNamespacesPerFileWithClassAsLast()
{
$parser = new PhpParser();
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\EqualNamespacesPerFileWithClassAsLast');
$this->assertEquals(array(
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
'template' => __NAMESPACE__ . '\Fixtures\Annotation\Template',
), $parser->parseClass($class));
}
public function testDifferentNamespacesPerFileWithClassAsFirst()
{
$parser = new PhpParser();
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\DifferentNamespacesPerFileWithClassAsFirst');
$this->assertEquals(array(
'secure' => __NAMESPACE__ . '\Fixtures\Annotation\Secure',
), $parser->parseClass($class));
}
public function testDifferentNamespacesPerFileWithClassAsLast()
{
$parser = new PhpParser();
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\DifferentNamespacesPerFileWithClassAsLast');
$this->assertEquals(array(
'template' => __NAMESPACE__ . '\Fixtures\Annotation\Template',
), $parser->parseClass($class));
}
public function testGlobalNamespacesPerFileWithClassAsFirst()
{
$parser = new PhpParser();
$class = new \ReflectionClass('\GlobalNamespacesPerFileWithClassAsFirst');
$this->assertEquals(array(
'secure' => __NAMESPACE__ . '\Fixtures\Annotation\Secure',
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
), $parser->parseClass($class));
}
public function testGlobalNamespacesPerFileWithClassAsLast()
{
$parser = new PhpParser();
$class = new ReflectionClass('\GlobalNamespacesPerFileWithClassAsLast');
$this->assertEquals(array(
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
'template' => __NAMESPACE__ . '\Fixtures\Annotation\Template',
), $parser->parseClass($class));
}
public function testNamespaceWithClosureDeclaration()
{
$parser = new PhpParser();
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\NamespaceWithClosureDeclaration');
$this->assertEquals(array(
'secure' => __NAMESPACE__ . '\Fixtures\Annotation\Secure',
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
'template' => __NAMESPACE__ . '\Fixtures\Annotation\Template',
), $parser->parseClass($class));
}
public function testIfPointerResetsOnMultipleParsingTries()
{
$parser = new PhpParser();
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\NamespaceWithClosureDeclaration');
$this->assertEquals(array(
'secure' => __NAMESPACE__ . '\Fixtures\Annotation\Secure',
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
'template' => __NAMESPACE__ . '\Fixtures\Annotation\Template',
), $parser->parseClass($class));
$this->assertEquals(array(
'secure' => __NAMESPACE__ . '\Fixtures\Annotation\Secure',
'route' => __NAMESPACE__ . '\Fixtures\Annotation\Route',
'template' => __NAMESPACE__ . '\Fixtures\Annotation\Template',
), $parser->parseClass($class));
}
/**
* @group DCOM-97
* @group regression
*/
public function testClassWithClosure()
{
$parser = new PhpParser();
$class = new ReflectionClass(__NAMESPACE__ . '\Fixtures\ClassWithClosure');
$this->assertEquals(array(
'annotationtargetall' => __NAMESPACE__ . '\Fixtures\AnnotationTargetAll',
'annotationtargetannotation' => __NAMESPACE__ . '\Fixtures\AnnotationTargetAnnotation',
), $parser->parseClass($class));
}
}

View file

@ -0,0 +1,97 @@
<?php
namespace Doctrine\Tests\Common\Annotations;
use Doctrine\Common\Annotations\SimpleAnnotationReader;
class SimpleAnnotationReaderTest extends AbstractReaderTest
{
/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testImportDetectsNotImportedAnnotation()
{
parent::testImportDetectsNotImportedAnnotation();
}
/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testImportDetectsNonExistentAnnotation()
{
parent::testImportDetectsNonExistentAnnotation();
}
/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testClassWithInvalidAnnotationTargetAtClassDocBlock()
{
parent::testClassWithInvalidAnnotationTargetAtClassDocBlock();
}
/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testClassWithInvalidAnnotationTargetAtPropertyDocBlock()
{
parent::testClassWithInvalidAnnotationTargetAtPropertyDocBlock();
}
/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock()
{
parent::testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock();
}
/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testClassWithInvalidAnnotationTargetAtMethodDocBlock()
{
parent::testClassWithInvalidAnnotationTargetAtMethodDocBlock();
}
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
*/
public function testInvalidAnnotationUsageButIgnoredClass()
{
parent::testInvalidAnnotationUsageButIgnoredClass();
}
/**
* @group DDC-1660
* @group regression
*
* Contrary to the behavior of the default annotation reader, @version is not ignored
*/
public function testInvalidAnnotationButIgnored()
{
$reader = $this->getReader();
$class = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassDDC1660');
$this->assertTrue(class_exists('Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Version'));
$this->assertCount(1, $reader->getClassAnnotations($class));
$this->assertCount(1, $reader->getMethodAnnotations($class->getMethod('bar')));
$this->assertCount(1, $reader->getPropertyAnnotations($class->getProperty('foo')));
}
protected function getReader()
{
$reader = new SimpleAnnotationReader();
$reader->addNamespace(__NAMESPACE__);
$reader->addNamespace(__NAMESPACE__ . '\Fixtures');
$reader->addNamespace(__NAMESPACE__ . '\Fixtures\Annotation');
return $reader;
}
}

View file

@ -0,0 +1,65 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Ticket;
use Doctrine\Tests\Common\Annotations\Fixtures\Controller;
/**
* @group
*/
class DCOM55Test extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException Doctrine\Common\Annotations\AnnotationException
* @expectedExceptionMessage [Semantical Error] The class "Doctrine\Tests\Common\Annotations\Fixtures\Controller" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "Doctrine\Tests\Common\Annotations\Fixtures\Controller". If it is indeed no annotation, then you need to add @IgnoreAnnotation("Controller") to the _class_ doc comment of class Doctrine\Tests\Common\Annotations\Ticket\Dummy.
*/
public function testIssue()
{
$class = new \ReflectionClass(__NAMESPACE__ . '\\Dummy');
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader->getClassAnnotations($class);
}
public function testAnnotation()
{
$class = new \ReflectionClass(__NAMESPACE__ . '\\DCOM55Consumer');
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$annots = $reader->getClassAnnotations($class);
$this->assertEquals(1, count($annots));
$this->assertInstanceOf(__NAMESPACE__.'\\DCOM55Annotation', $annots[0]);
}
public function testParseAnnotationDocblocks()
{
$class = new \ReflectionClass(__NAMESPACE__ . '\\DCOM55Annotation');
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$annots = $reader->getClassAnnotations($class);
$this->assertEquals(0, count($annots));
}
}
/**
* @Controller
*/
class Dummy
{
}
/**
* @Annotation
*/
class DCOM55Annotation
{
}
/**
* @DCOM55Annotation
*/
class DCOM55Consumer
{
}

View file

@ -0,0 +1,8 @@
<?php
// Some class named Entity in the global namespace
/**
* @Annotation
*/
class Entity
{
}

View file

@ -0,0 +1,112 @@
<?php
namespace Doctrine\Tests\Common\Annotations\Ticket;
//Some class named Entity in the global namespace
include __DIR__ .'/DCOM58Entity.php';
/**
* @group DCOM58
*/
class DCOM58Test extends \PHPUnit_Framework_TestCase
{
public function testIssue()
{
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$result = $reader->getClassAnnotations(new \ReflectionClass(__NAMESPACE__."\MappedClass"));
foreach ($result as $annot) {
$classAnnotations[get_class($annot)] = $annot;
}
$this->assertTrue(!isset($classAnnotations['']), 'Class "xxx" is not a valid entity or mapped super class.');
}
public function testIssueGlobalNamespace()
{
$docblock = "@Entity";
$parser = new \Doctrine\Common\Annotations\DocParser();
$parser->setImports(array(
"__NAMESPACE__" =>"Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM\Mapping"
));
$annots = $parser->parse($docblock);
$this->assertEquals(1, count($annots));
$this->assertInstanceOf("Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM\Mapping\Entity", $annots[0]);
}
public function testIssueNamespaces()
{
$docblock = "@Entity";
$parser = new \Doctrine\Common\Annotations\DocParser();
$parser->addNamespace("Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM");
$annots = $parser->parse($docblock);
$this->assertEquals(1, count($annots));
$this->assertInstanceOf("Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM\Entity", $annots[0]);
}
public function testIssueMultipleNamespaces()
{
$docblock = "@Entity";
$parser = new \Doctrine\Common\Annotations\DocParser();
$parser->addNamespace("Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM\Mapping");
$parser->addNamespace("Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM");
$annots = $parser->parse($docblock);
$this->assertEquals(1, count($annots));
$this->assertInstanceOf("Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM\Mapping\Entity", $annots[0]);
}
public function testIssueWithNamespacesOrImports()
{
$docblock = "@Entity";
$parser = new \Doctrine\Common\Annotations\DocParser();
$annots = $parser->parse($docblock);
$this->assertEquals(1, count($annots));
$this->assertInstanceOf("Entity", $annots[0]);
$this->assertEquals(1, count($annots));
}
public function testIssueSimpleAnnotationReader()
{
$reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
$reader->addNamespace('Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM\Mapping');
$annots = $reader->getClassAnnotations(new \ReflectionClass(__NAMESPACE__."\MappedClass"));
$this->assertEquals(1, count($annots));
$this->assertInstanceOf("Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM\Mapping\Entity", $annots[0]);
}
}
/**
* @Entity
*/
class MappedClass
{
}
namespace Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM\Mapping;
/**
* @Annotation
*/
class Entity
{
}
namespace Doctrine\Tests\Common\Annotations\Ticket\Doctrine\ORM;
/**
* @Annotation
*/
class Entity
{
}

View file

@ -0,0 +1,8 @@
<?php
use Doctrine\Common\Annotations\Annotation;
/** @Annotation */
class TopLevelAnnotation extends Annotation
{
}

View file

@ -0,0 +1,20 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\ApcCache;
class ApcCacheTest extends CacheTest
{
public function setUp()
{
if ( ! extension_loaded('apc') || false === @apc_cache_info()) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of APC');
}
}
protected function _getCacheDriver()
{
return new ApcCache();
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\ArrayCache;
class ArrayCacheTest extends CacheTest
{
protected function _getCacheDriver()
{
return new ArrayCache();
}
public function testGetStats()
{
$cache = $this->_getCacheDriver();
$stats = $cache->getStats();
$this->assertNull($stats);
}
}

View file

@ -0,0 +1,91 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\Cache;
abstract class CacheTest extends \Doctrine\Tests\DoctrineTestCase
{
public function testBasics()
{
$cache = $this->_getCacheDriver();
// Test save
$cache->save('test_key', 'testing this out');
// Test contains to test that save() worked
$this->assertTrue($cache->contains('test_key'));
// Test fetch
$this->assertEquals('testing this out', $cache->fetch('test_key'));
// Test delete
$cache->save('test_key2', 'test2');
$cache->delete('test_key2');
$this->assertFalse($cache->contains('test_key2'));
}
public function testObjects()
{
$cache = $this->_getCacheDriver();
// Fetch/save test with objects (Is cache driver serializes/unserializes objects correctly ?)
$cache->save('test_object_key', new \ArrayObject());
$this->assertTrue($cache->fetch('test_object_key') instanceof \ArrayObject);
}
public function testDeleteAll()
{
$cache = $this->_getCacheDriver();
$cache->save('test_key1', '1');
$cache->save('test_key2', '2');
$cache->deleteAll();
$this->assertFalse($cache->contains('test_key1'));
$this->assertFalse($cache->contains('test_key2'));
}
public function testFlushAll()
{
$cache = $this->_getCacheDriver();
$cache->save('test_key1', '1');
$cache->save('test_key2', '2');
$cache->flushAll();
$this->assertFalse($cache->contains('test_key1'));
$this->assertFalse($cache->contains('test_key2'));
}
public function testNamespace()
{
$cache = $this->_getCacheDriver();
$cache->setNamespace('test_');
$cache->save('key1', 'test');
$this->assertTrue($cache->contains('key1'));
$cache->setNamespace('test2_');
$this->assertFalse($cache->contains('key1'));
}
/**
* @group DCOM-43
*/
public function testGetStats()
{
$cache = $this->_getCacheDriver();
$stats = $cache->getStats();
$this->assertArrayHasKey(Cache::STATS_HITS, $stats);
$this->assertArrayHasKey(Cache::STATS_MISSES, $stats);
$this->assertArrayHasKey(Cache::STATS_UPTIME, $stats);
$this->assertArrayHasKey(Cache::STATS_MEMORY_USAGE, $stats);
$this->assertArrayHasKey(Cache::STATS_MEMORY_AVAILIABLE, $stats);
}
/**
* @return \Doctrine\Common\Cache\CacheProvider
*/
abstract protected function _getCacheDriver();
}

View file

@ -0,0 +1,97 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\FilesystemCache;
/**
* @group DCOM-101
*/
class FilesystemCacheTest extends CacheTest
{
/**
* @var \Doctrine\Common\Cache\FilesystemCache
*/
private $driver;
protected function _getCacheDriver()
{
$dir = sys_get_temp_dir() . "/doctrine_cache_". uniqid();
$this->assertFalse(is_dir($dir));
$this->driver = new FilesystemCache($dir);
$this->assertTrue(is_dir($dir));
return $this->driver;
}
public function testLifetime()
{
$cache = $this->_getCacheDriver();
// Test save
$cache->save('test_key', 'testing this out', 10);
// Test contains to test that save() worked
$this->assertTrue($cache->contains('test_key'));
// Test fetch
$this->assertEquals('testing this out', $cache->fetch('test_key'));
// access private methods
$getFilename = new \ReflectionMethod($cache, 'getFilename');
$getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId');
$getFilename->setAccessible(true);
$getNamespacedId->setAccessible(true);
$id = $getNamespacedId->invoke($cache, 'test_key');
$filename = $getFilename->invoke($cache, $id);
$data = '';
$lifetime = 0;
$resource = fopen($filename, "r");
if (false !== ($line = fgets($resource))) {
$lifetime = (integer) $line;
}
while (false !== ($line = fgets($resource))) {
$data .= $line;
}
$this->assertNotEquals(0, $lifetime, "previous lifetime could not be loaded");
// update lifetime
$lifetime = $lifetime - 20;
file_put_contents($filename, $lifetime . PHP_EOL . $data);
// test expired data
$this->assertFalse($cache->contains('test_key'));
$this->assertFalse($cache->fetch('test_key'));
}
public function testGetStats()
{
$cache = $this->_getCacheDriver();
$stats = $cache->getStats();
$this->assertNull($stats);
}
public function tearDown()
{
$dir = $this->driver->getDirectory();
$ext = $this->driver->getExtension();
$iterator = new \RecursiveDirectoryIterator($dir);
foreach (new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) {
if ($file->isFile()) {
@unlink($file->getRealPath());
} else {
@rmdir($file->getRealPath());
}
}
}
}

View file

@ -0,0 +1,45 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\MemcacheCache;
class MemcacheCacheTest extends CacheTest
{
private $_memcache;
public function setUp()
{
if (extension_loaded('memcache')) {
$this->_memcache = new \Memcache;
$ok = @$this->_memcache->connect('localhost', 11211);
if (!$ok) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
}
} else {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
}
}
public function testNoExpire() {
$cache = $this->_getCacheDriver();
$cache->save('noexpire', 'value', 0);
sleep(1);
$this->assertTrue($cache->contains('noexpire'), 'Memcache provider should support no-expire');
}
public function testLongLifetime()
{
$cache = $this->_getCacheDriver();
$cache->save('key', 'value', 30 * 24 * 3600 + 1);
$this->assertTrue($cache->contains('key'), 'Memcache provider should support TTL > 30 days');
}
protected function _getCacheDriver()
{
$driver = new MemcacheCache();
$driver->setMemcache($this->_memcache);
return $driver;
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\MemcachedCache;
class MemcachedCacheTest extends CacheTest
{
private $memcached;
public function setUp()
{
if (extension_loaded('memcached')) {
$this->memcached = new \Memcached();
$this->memcached->setOption(\Memcached::OPT_COMPRESSION, false);
$this->memcached->addServer('127.0.0.1', 11211);
$fh = @fsockopen('127.0.0.1', 11211);
if (!$fh) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
}
} else {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
}
}
public function testNoExpire() {
$cache = $this->_getCacheDriver();
$cache->save('noexpire', 'value', 0);
sleep(1);
$this->assertTrue($cache->contains('noexpire'), 'Memcache provider should support no-expire');
}
public function testLongLifetime()
{
$cache = $this->_getCacheDriver();
$cache->save('key', 'value', 30 * 24 * 3600 + 1);
$this->assertTrue($cache->contains('key'), 'Memcached provider should support TTL > 30 days');
}
protected function _getCacheDriver()
{
$driver = new MemcachedCache();
$driver->setMemcached($this->memcached);
return $driver;
}
}

View file

@ -0,0 +1,149 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\PhpFileCache;
/**
* @group DCOM-101
*/
class PhpFileCacheTest extends CacheTest
{
/**
* @var \Doctrine\Common\Cache\PhpFileCache
*/
private $driver;
protected function _getCacheDriver()
{
$dir = sys_get_temp_dir() . "/doctrine_cache_". uniqid();
$this->assertFalse(is_dir($dir));
$this->driver = new PhpFileCache($dir);
$this->assertTrue(is_dir($dir));
return $this->driver;
}
public function testObjects()
{
$this->markTestSkipped('PhpFileCache does not support saving objects that dont implement __set_state()');
}
public function testLifetime()
{
$cache = $this->_getCacheDriver();
// Test save
$cache->save('test_key', 'testing this out', 10);
// Test contains to test that save() worked
$this->assertTrue($cache->contains('test_key'));
// Test fetch
$this->assertEquals('testing this out', $cache->fetch('test_key'));
// access private methods
$getFilename = new \ReflectionMethod($cache, 'getFilename');
$getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId');
$getFilename->setAccessible(true);
$getNamespacedId->setAccessible(true);
$id = $getNamespacedId->invoke($cache, 'test_key');
$path = $getFilename->invoke($cache, $id);
$value = include $path;
// update lifetime
$value['lifetime'] = $value['lifetime'] - 20;
file_put_contents($path, '<?php return unserialize(' . var_export(serialize($value), true) . ');');
// test expired data
$this->assertFalse($cache->contains('test_key'));
$this->assertFalse($cache->fetch('test_key'));
}
public function testImplementsSetState()
{
$cache = $this->_getCacheDriver();
// Test save
$cache->save('test_set_state', new SetStateClass(array(1,2,3)));
//Test __set_state call
$this->assertCount(0, SetStateClass::$values);
// Test fetch
$value = $cache->fetch('test_set_state');
$this->assertInstanceOf('Doctrine\Tests\Common\Cache\SetStateClass', $value);
$this->assertEquals(array(1,2,3), $value->getValue());
//Test __set_state call
$this->assertCount(1, SetStateClass::$values);
// Test contains
$this->assertTrue($cache->contains('test_set_state'));
}
public function testNotImplementsSetState()
{
$cache = $this->_getCacheDriver();
$this->setExpectedException('InvalidArgumentException');
$cache->save('test_not_set_state', new NotSetStateClass(array(1,2,3)));
}
public function testGetStats()
{
$cache = $this->_getCacheDriver();
$stats = $cache->getStats();
$this->assertNull($stats);
}
public function tearDown()
{
if (!$this->driver) {
return;
}
$dir = $this->driver->getDirectory();
$ext = $this->driver->getExtension();
$iterator = new \RecursiveDirectoryIterator($dir);
foreach (new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) {
if ($file->isFile()) {
@unlink($file->getRealPath());
} else {
@rmdir($file->getRealPath());
}
}
}
}
class NotSetStateClass
{
private $value;
public function __construct($value)
{
$this->value = $value;
}
public function getValue()
{
return $this->value;
}
}
class SetStateClass extends NotSetStateClass
{
public static $values = array();
public static function __set_state($data)
{
self::$values = $data;
return new self($data['value']);
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\RedisCache;
class RedisCacheTest extends CacheTest
{
private $_redis;
public function setUp()
{
if (extension_loaded('redis')) {
$this->_redis = new \Redis();
$ok = @$this->_redis->connect('127.0.0.1');
if (!$ok) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of redis');
}
} else {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of redis');
}
}
protected function _getCacheDriver()
{
$driver = new RedisCache();
$driver->setRedis($this->_redis);
return $driver;
}
}

View file

@ -0,0 +1,20 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\WincacheCache;
class WincacheCacheTest extends CacheTest
{
public function setUp()
{
if ( ! extension_loaded('wincache') || ! function_exists('wincache_ucache_info')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of Wincache');
}
}
protected function _getCacheDriver()
{
return new WincacheCache();
}
}

View file

@ -0,0 +1,20 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\XcacheCache;
class XcacheCacheTest extends CacheTest
{
public function setUp()
{
if ( ! extension_loaded('xcache')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of xcache');
}
}
protected function _getCacheDriver()
{
return new XcacheCache();
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\ZendDataCache;
class ZendDataCacheTest extends CacheTest
{
public function setUp()
{
if (!function_exists('zend_shm_cache_fetch') || (php_sapi_name() != 'apache2handler')) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of Zend Data Cache which only works in apache2handler SAPI');
}
}
public function testGetStats()
{
$cache = $this->_getCacheDriver();
$stats = $cache->getStats();
$this->assertNull($stats);
}
protected function _getCacheDriver()
{
return new ZendDataCache();
}
}

View file

@ -0,0 +1,45 @@
<?php
namespace Doctrine\Tests\Common;
use Doctrine\Common\ClassLoader;
class ClassLoaderTest extends \Doctrine\Tests\DoctrineTestCase
{
public function testClassLoader()
{
$classLoader = new ClassLoader('ClassLoaderTest');
$classLoader->setIncludePath(__DIR__);
$classLoader->setFileExtension('.class.php');
$classLoader->setNamespaceSeparator('_');
$this->assertTrue($classLoader->canLoadClass('ClassLoaderTest_ClassA'));
$this->assertTrue($classLoader->canLoadClass('ClassLoaderTest_ClassB'));
$this->assertTrue($classLoader->canLoadClass('ClassLoaderTest_ClassC'));
$this->assertFalse($classLoader->canLoadClass('OtherClass'));
$this->assertEquals($classLoader->loadClass('ClassLoaderTest_ClassA'), true);
$this->assertEquals($classLoader->loadClass('ClassLoaderTest_ClassB'), true);
$this->assertEquals($classLoader->loadClass('ClassLoaderTest_ClassC'), true);
}
public function testClassExists()
{
$this->assertFalse(ClassLoader::classExists('ClassLoaderTest\ClassD'));
$badLoader = function($className) {
require __DIR__ . '/ClassLoaderTest/ClassD.php';
return true;
};
spl_autoload_register($badLoader);
$this->assertTrue(ClassLoader::classExists('ClassLoaderTest\ClassD'));
spl_autoload_unregister($badLoader);
}
public function testGetClassLoader()
{
$cl = new ClassLoader('ClassLoaderTest', __DIR__);
$cl->register();
$this->assertTrue(ClassLoader::getClassLoader('ClassLoaderTest\ClassD') instanceof \Doctrine\Common\ClassLoader);
$this->assertNull(ClassLoader::getClassLoader('This\Class\Does\Not\Exist'));
$cl->unregister();
}
}

View file

@ -0,0 +1,6 @@
<?php
class ClassLoaderTest_ClassA
{
}

View file

@ -0,0 +1,6 @@
<?php
class ClassLoaderTest_ClassB
{
}

View file

@ -0,0 +1,6 @@
<?php
class ClassLoaderTest_ClassC
{
}

View file

@ -0,0 +1,5 @@
<?php
namespace ClassLoaderTest;
class ClassD {}

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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Tests\Common\Collections;
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
use Doctrine\Common\Collections\ExpressionBuilder;
/**
* @group DDC-1637
*/
class ClosureExpressionVisitorTest extends \PHPUnit_Framework_TestCase
{
private $visitor;
private $builder;
public function setUp()
{
$this->visitor = new ClosureExpressionVisitor();
$this->builder = new ExpressionBuilder();
}
public function testWalkEqualsComparison()
{
$closure = $this->visitor->walkComparison($this->builder->eq("foo", 1));
$this->assertTrue($closure(new TestObject(1)));
$this->assertFalse($closure(new TestObject(2)));
}
public function testWalkNotEqualsComparison()
{
$closure = $this->visitor->walkComparison($this->builder->neq("foo", 1));
$this->assertFalse($closure(new TestObject(1)));
$this->assertTrue($closure(new TestObject(2)));
}
public function testWalkLessThanComparison()
{
$closure = $this->visitor->walkComparison($this->builder->lt("foo", 1));
$this->assertFalse($closure(new TestObject(1)));
$this->assertTrue($closure(new TestObject(0)));
}
public function testWalkLessThanEqualsComparison()
{
$closure = $this->visitor->walkComparison($this->builder->lte("foo", 1));
$this->assertFalse($closure(new TestObject(2)));
$this->assertTrue($closure(new TestObject(1)));
$this->assertTrue($closure(new TestObject(0)));
}
public function testWalkGreaterThanEqualsComparison()
{
$closure = $this->visitor->walkComparison($this->builder->gte("foo", 1));
$this->assertTrue($closure(new TestObject(2)));
$this->assertTrue($closure(new TestObject(1)));
$this->assertFalse($closure(new TestObject(0)));
}
public function testWalkGreaterThanComparison()
{
$closure = $this->visitor->walkComparison($this->builder->gt("foo", 1));
$this->assertTrue($closure(new TestObject(2)));
$this->assertFalse($closure(new TestObject(1)));
$this->assertFalse($closure(new TestObject(0)));
}
public function testWalkInComparison()
{
$closure = $this->visitor->walkComparison($this->builder->in("foo", array(1, 2, 3)));
$this->assertTrue($closure(new TestObject(2)));
$this->assertTrue($closure(new TestObject(1)));
$this->assertFalse($closure(new TestObject(0)));
}
public function testWalkNotInComparison()
{
$closure = $this->visitor->walkComparison($this->builder->notIn("foo", array(1, 2, 3)));
$this->assertFalse($closure(new TestObject(1)));
$this->assertFalse($closure(new TestObject(2)));
$this->assertTrue($closure(new TestObject(0)));
$this->assertTrue($closure(new TestObject(4)));
}
public function testWalkAndCompositeExpression()
{
$closure = $this->visitor->walkCompositeExpression(
$this->builder->andX(
$this->builder->eq("foo", 1),
$this->builder->eq("bar", 1)
)
);
$this->assertTrue($closure(new TestObject(1, 1)));
$this->assertFalse($closure(new TestObject(1, 0)));
$this->assertFalse($closure(new TestObject(0, 1)));
$this->assertFalse($closure(new TestObject(0, 0)));
}
public function testWalkOrCompositeExpression()
{
$closure = $this->visitor->walkCompositeExpression(
$this->builder->orX(
$this->builder->eq("foo", 1),
$this->builder->eq("bar", 1)
)
);
$this->assertTrue($closure(new TestObject(1, 1)));
$this->assertTrue($closure(new TestObject(1, 0)));
$this->assertTrue($closure(new TestObject(0, 1)));
$this->assertFalse($closure(new TestObject(0, 0)));
}
public function testSortByFieldAscending()
{
$objects = array(new TestObject("b"), new TestObject("a"), new TestObject("c"));
$sort = ClosureExpressionVisitor::sortByField("foo");
usort($objects, $sort);
$this->assertEquals("a", $objects[0]->getFoo());
$this->assertEquals("b", $objects[1]->getFoo());
$this->assertEquals("c", $objects[2]->getFoo());
}
public function testSortByFieldDescending()
{
$objects = array(new TestObject("b"), new TestObject("a"), new TestObject("c"));
$sort = ClosureExpressionVisitor::sortByField("foo", -1);
usort($objects, $sort);
$this->assertEquals("c", $objects[0]->getFoo());
$this->assertEquals("b", $objects[1]->getFoo());
$this->assertEquals("a", $objects[2]->getFoo());
}
public function testSortDelegate()
{
$objects = array(new TestObject("a", "c"), new TestObject("a", "b"), new TestObject("a", "a"));
$sort = ClosureExpressionVisitor::sortByField("bar", 1);
$sort = ClosureExpressionVisitor::sortByField("foo", 1, $sort);
usort($objects, $sort);
$this->assertEquals("a", $objects[0]->getBar());
$this->assertEquals("b", $objects[1]->getBar());
$this->assertEquals("c", $objects[2]->getBar());
}
}
class TestObject
{
private $foo;
private $bar;
public function __construct($foo = null, $bar = null)
{
$this->foo = $foo;
$this->bar = $bar;
}
public function getFoo()
{
return $this->foo;
}
public function getBar()
{
return $this->bar;
}
}

View file

@ -0,0 +1,251 @@
<?php
namespace Doctrine\Tests\Common\Collections;
use Doctrine\Tests;
use Doctrine\Common\Collections\Criteria;
class CollectionTest extends \Doctrine\Tests\DoctrineTestCase
{
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $_coll;
protected function setUp()
{
$this->_coll = new \Doctrine\Common\Collections\ArrayCollection;
}
public function testIssetAndUnset()
{
$this->assertFalse(isset($this->_coll[0]));
$this->_coll->add('testing');
$this->assertTrue(isset($this->_coll[0]));
unset($this->_coll[0]);
$this->assertFalse(isset($this->_coll[0]));
}
public function testToString()
{
$this->_coll->add('testing');
$this->assertTrue(is_string((string) $this->_coll));
}
public function testRemovingNonExistentEntryReturnsNull()
{
$this->assertEquals(null, $this->_coll->remove('testing_does_not_exist'));
}
public function testExists()
{
$this->_coll->add("one");
$this->_coll->add("two");
$exists = $this->_coll->exists(function($k, $e) { return $e == "one"; });
$this->assertTrue($exists);
$exists = $this->_coll->exists(function($k, $e) { return $e == "other"; });
$this->assertFalse($exists);
}
public function testMap()
{
$this->_coll->add(1);
$this->_coll->add(2);
$res = $this->_coll->map(function($e) { return $e * 2; });
$this->assertEquals(array(2, 4), $res->toArray());
}
public function testFilter()
{
$this->_coll->add(1);
$this->_coll->add("foo");
$this->_coll->add(3);
$res = $this->_coll->filter(function($e) { return is_numeric($e); });
$this->assertEquals(array(0 => 1, 2 => 3), $res->toArray());
}
public function testFirstAndLast()
{
$this->_coll->add('one');
$this->_coll->add('two');
$this->assertEquals($this->_coll->first(), 'one');
$this->assertEquals($this->_coll->last(), 'two');
}
public function testArrayAccess()
{
$this->_coll[] = 'one';
$this->_coll[] = 'two';
$this->assertEquals($this->_coll[0], 'one');
$this->assertEquals($this->_coll[1], 'two');
unset($this->_coll[0]);
$this->assertEquals($this->_coll->count(), 1);
}
public function testContainsKey()
{
$this->_coll[5] = 'five';
$this->assertTrue($this->_coll->containsKey(5));
}
public function testContains()
{
$this->_coll[0] = 'test';
$this->assertTrue($this->_coll->contains('test'));
}
public function testSearch()
{
$this->_coll[0] = 'test';
$this->assertEquals(0, $this->_coll->indexOf('test'));
}
public function testGet()
{
$this->_coll[0] = 'test';
$this->assertEquals('test', $this->_coll->get(0));
}
public function testGetKeys()
{
$this->_coll[] = 'one';
$this->_coll[] = 'two';
$this->assertEquals(array(0, 1), $this->_coll->getKeys());
}
public function testGetValues()
{
$this->_coll[] = 'one';
$this->_coll[] = 'two';
$this->assertEquals(array('one', 'two'), $this->_coll->getValues());
}
public function testCount()
{
$this->_coll[] = 'one';
$this->_coll[] = 'two';
$this->assertEquals($this->_coll->count(), 2);
$this->assertEquals(count($this->_coll), 2);
}
public function testForAll()
{
$this->_coll[] = 'one';
$this->_coll[] = 'two';
$this->assertEquals($this->_coll->forAll(function($k, $e) { return is_string($e); }), true);
$this->assertEquals($this->_coll->forAll(function($k, $e) { return is_array($e); }), false);
}
public function testPartition()
{
$this->_coll[] = true;
$this->_coll[] = false;
$partition = $this->_coll->partition(function($k, $e) { return $e == true; });
$this->assertEquals($partition[0][0], true);
$this->assertEquals($partition[1][0], false);
}
public function testClear()
{
$this->_coll[] = 'one';
$this->_coll[] = 'two';
$this->_coll->clear();
$this->assertEquals($this->_coll->isEmpty(), true);
}
public function testRemove()
{
$this->_coll[] = 'one';
$this->_coll[] = 'two';
$el = $this->_coll->remove(0);
$this->assertEquals('one', $el);
$this->assertEquals($this->_coll->contains('one'), false);
$this->assertNull($this->_coll->remove(0));
}
public function testRemoveElement()
{
$this->_coll[] = 'one';
$this->_coll[] = 'two';
$this->assertTrue($this->_coll->removeElement('two'));
$this->assertFalse($this->_coll->contains('two'));
$this->assertFalse($this->_coll->removeElement('two'));
}
public function testSlice()
{
$this->_coll[] = 'one';
$this->_coll[] = 'two';
$this->_coll[] = 'three';
$slice = $this->_coll->slice(0, 1);
$this->assertInternalType('array', $slice);
$this->assertEquals(array('one'), $slice);
$slice = $this->_coll->slice(1);
$this->assertEquals(array(1 => 'two', 2 => 'three'), $slice);
$slice = $this->_coll->slice(1, 1);
$this->assertEquals(array(1 => 'two'), $slice);
}
public function fillMatchingFixture()
{
$std1 = new \stdClass();
$std1->foo = "bar";
$this->_coll[] = $std1;
$std2 = new \stdClass();
$std2->foo = "baz";
$this->_coll[] = $std2;
}
/**
* @group DDC-1637
*/
public function testMatching()
{
$this->fillMatchingFixture();
$col = $this->_coll->matching(new Criteria(Criteria::expr()->eq("foo", "bar")));
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $col);
$this->assertNotSame($col, $this->_coll);
$this->assertEquals(1, count($col));
}
/**
* @group DDC-1637
*/
public function testMatchingOrdering()
{
$this->fillMatchingFixture();
$col = $this->_coll->matching(new Criteria(null, array('foo' => 'DESC')));
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $col);
$this->assertNotSame($col, $this->_coll);
$this->assertEquals(2, count($col));
$this->assertEquals('baz', $col[0]->foo);
$this->assertEquals('bar', $col[1]->foo);
}
/**
* @group DDC-1637
*/
public function testMatchingSlice()
{
$this->fillMatchingFixture();
$col = $this->_coll->matching(new Criteria(null, null, 1, 1));
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $col);
$this->assertNotSame($col, $this->_coll);
$this->assertEquals(1, count($col));
$this->assertEquals('baz', $col[0]->foo);
}
}

View file

@ -0,0 +1,82 @@
<?php
namespace Doctrine\Tests\Common\Collections;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Expr\Comparison;
use Doctrine\Common\Collections\Expr\CompositeExpression;
class CriteriaTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
$criteria = Criteria::create();
$this->assertInstanceOf("Doctrine\Common\Collections\Criteria", $criteria);
}
public function testConstructor()
{
$expr = new Comparison("field", "=", "value");
$criteria = new Criteria($expr, array("foo" => "ASC"), 10, 20);
$this->assertSame($expr, $criteria->getWhereExpression());
$this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
$this->assertEquals(10, $criteria->getFirstResult());
$this->assertEquals(20, $criteria->getMaxResults());
}
public function testWhere()
{
$expr = new Comparison("field", "=", "value");
$criteria = new Criteria();
$criteria->where($expr);
$this->assertSame($expr, $criteria->getWhereExpression());
}
public function testAndWhere()
{
$expr = new Comparison("field", "=", "value");
$criteria = new Criteria();
$criteria->where($expr);
$expr = $criteria->getWhereExpression();
$criteria->andWhere($expr);
$where = $criteria->getWhereExpression();
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where);
$this->assertEquals(CompositeExpression::TYPE_AND, $where->getType());
$this->assertSame(array($expr, $expr), $where->getExpressionList());
}
public function testOrWhere()
{
$expr = new Comparison("field", "=", "value");
$criteria = new Criteria();
$criteria->where($expr);
$expr = $criteria->getWhereExpression();
$criteria->orWhere($expr);
$where = $criteria->getWhereExpression();
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where);
$this->assertEquals(CompositeExpression::TYPE_OR, $where->getType());
$this->assertSame(array($expr, $expr), $where->getExpressionList());
}
public function testOrderings()
{
$criteria = Criteria::create()
->orderBy(array("foo" => "ASC"));
$this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
}
public function testExpr()
{
$this->assertInstanceOf('Doctrine\Common\Collections\ExpressionBuilder', Criteria::expr());
}
}

View file

@ -0,0 +1,114 @@
<?php
namespace Doctrine\Tests\Common\Collections;
use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\Common\Collections\Expr\Comparison;
use Doctrine\Common\Collections\Expr\CompositeExpression;
/**
* @group DDC-1637
*/
class ExpressionBuilderTest extends \PHPUnit_Framework_TestCase
{
private $builder;
public function setUp()
{
$this->builder = new ExpressionBuilder();
}
public function testAndX()
{
$expr = $this->builder->andX($this->builder->eq("a", "b"));
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\CompositeExpression", $expr);
$this->assertEquals(CompositeExpression::TYPE_AND, $expr->getType());
}
public function testOrX()
{
$expr = $this->builder->orX($this->builder->eq("a", "b"));
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\CompositeExpression", $expr);
$this->assertEquals(CompositeExpression::TYPE_OR, $expr->getType());
}
public function testInvalidAndXArgument()
{
$this->setExpectedException("RuntimeException");
$this->builder->andX("foo");
}
public function testEq()
{
$expr = $this->builder->eq("a", "b");
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
$this->assertEquals(Comparison::EQ, $expr->getOperator());
}
public function testNeq()
{
$expr = $this->builder->neq("a", "b");
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
$this->assertEquals(Comparison::NEQ, $expr->getOperator());
}
public function testLt()
{
$expr = $this->builder->lt("a", "b");
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
$this->assertEquals(Comparison::LT, $expr->getOperator());
}
public function testGt()
{
$expr = $this->builder->gt("a", "b");
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
$this->assertEquals(Comparison::GT, $expr->getOperator());
}
public function testGte()
{
$expr = $this->builder->gte("a", "b");
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
$this->assertEquals(Comparison::GTE, $expr->getOperator());
}
public function testLte()
{
$expr = $this->builder->lte("a", "b");
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
$this->assertEquals(Comparison::LTE, $expr->getOperator());
}
public function testIn()
{
$expr = $this->builder->in("a", array("b"));
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
$this->assertEquals(Comparison::IN, $expr->getOperator());
}
public function testNotIn()
{
$expr = $this->builder->notIn("a", array("b"));
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
$this->assertEquals(Comparison::NIN, $expr->getOperator());
}
public function testIsNull()
{
$expr = $this->builder->isNull("a");
$this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
$this->assertEquals(Comparison::IS, $expr->getOperator());
}
}

View file

@ -0,0 +1,88 @@
<?php
namespace Doctrine\Tests\Common;
use Doctrine\Common\EventManager;
use Doctrine\Common\EventArgs;
class EventManagerTest extends \Doctrine\Tests\DoctrineTestCase
{
/* Some pseudo events */
const preFoo = 'preFoo';
const postFoo = 'postFoo';
const preBar = 'preBar';
const postBar = 'postBar';
private $_preFooInvoked = false;
private $_postFooInvoked = false;
private $_eventManager;
protected function setUp()
{
$this->_eventManager = new EventManager;
$this->_preFooInvoked = false;
$this->_postFooInvoked = false;
}
public function testInitialState()
{
$this->assertEquals(array(), $this->_eventManager->getListeners());
$this->assertFalse($this->_eventManager->hasListeners(self::preFoo));
$this->assertFalse($this->_eventManager->hasListeners(self::postFoo));
}
public function testAddEventListener()
{
$this->_eventManager->addEventListener(array('preFoo', 'postFoo'), $this);
$this->assertTrue($this->_eventManager->hasListeners(self::preFoo));
$this->assertTrue($this->_eventManager->hasListeners(self::postFoo));
$this->assertEquals(1, count($this->_eventManager->getListeners(self::preFoo)));
$this->assertEquals(1, count($this->_eventManager->getListeners(self::postFoo)));
$this->assertEquals(2, count($this->_eventManager->getListeners()));
}
public function testDispatchEvent()
{
$this->_eventManager->addEventListener(array('preFoo', 'postFoo'), $this);
$this->_eventManager->dispatchEvent(self::preFoo);
$this->assertTrue($this->_preFooInvoked);
$this->assertFalse($this->_postFooInvoked);
}
public function testRemoveEventListener()
{
$this->_eventManager->addEventListener(array('preBar'), $this);
$this->assertTrue($this->_eventManager->hasListeners(self::preBar));
$this->_eventManager->removeEventListener(array('preBar'), $this);
$this->assertFalse($this->_eventManager->hasListeners(self::preBar));
}
public function testAddEventSubscriber()
{
$eventSubscriber = new TestEventSubscriber();
$this->_eventManager->addEventSubscriber($eventSubscriber);
$this->assertTrue($this->_eventManager->hasListeners(self::preFoo));
$this->assertTrue($this->_eventManager->hasListeners(self::postFoo));
}
/* Listener methods */
public function preFoo(EventArgs $e)
{
$this->_preFooInvoked = true;
}
public function postFoo(EventArgs $e)
{
$this->_postFooInvoked = true;
}
}
class TestEventSubscriber implements \Doctrine\Common\EventSubscriber
{
public function getSubscribedEvents()
{
return array('preFoo', 'postFoo');
}
}

View file

@ -0,0 +1,130 @@
<?php
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\Tests\DoctrineTestCase;
class DriverChainTest extends DoctrineTestCase
{
public function testDelegateToMatchingNamespaceDriver()
{
$className = 'Doctrine\Tests\Common\Persistence\Mapping\DriverChainEntity';
$classMetadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$chain = new MappingDriverChain();
$driver1 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$driver1->expects($this->never())
->method('loadMetadataForClass');
$driver1->expectS($this->never())
->method('isTransient');
$driver2 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$driver2->expects($this->at(0))
->method('loadMetadataForClass')
->with($this->equalTo($className), $this->equalTo($classMetadata));
$driver2->expects($this->at(1))
->method('isTransient')
->with($this->equalTo($className))
->will($this->returnValue( true ));
$chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
$chain->addDriver($driver2, 'Doctrine\Tests\Common\Persistence\Mapping');
$chain->loadMetadataForClass($className, $classMetadata);
$this->assertTrue( $chain->isTransient($className) );
}
public function testLoadMetadata_NoDelegatorFound_ThrowsMappingException()
{
$className = 'Doctrine\Tests\Common\Persistence\Mapping\DriverChainEntity';
$classMetadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$chain = new MappingDriverChain();
$this->setExpectedException('Doctrine\Common\Persistence\Mapping\MappingException');
$chain->loadMetadataForClass($className, $classMetadata);
}
public function testGatherAllClassNames()
{
$className = 'Doctrine\Tests\Common\Persistence\Mapping\DriverChainEntity';
$classMetadata = $this->getMock('Doctrine\Common\Peristence\ClassMetadata');
$chain = new MappingDriverChain();
$driver1 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$driver1->expects($this->once())
->method('getAllClassNames')
->will($this->returnValue(array('Doctrine\Tests\Models\Company\Foo')));
$driver2 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$driver2->expects($this->once())
->method('getAllClassNames')
->will($this->returnValue(array('Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz')));
$chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
$chain->addDriver($driver2, 'Doctrine\Tests\ORM\Mapping');
$this->assertEquals(array(
'Doctrine\Tests\Models\Company\Foo',
'Doctrine\Tests\ORM\Mapping\Bar',
'Doctrine\Tests\ORM\Mapping\Baz'
), $chain->getAllClassNames());
}
/**
* @group DDC-706
*/
public function testIsTransient()
{
$driver1 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$chain = new MappingDriverChain();
$chain->addDriver($driver1, 'Doctrine\Tests\Models\CMS');
$this->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient");
}
/**
* @group DDC-1412
*/
public function testDefaultDriver()
{
$companyDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$dafaultDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$entityClassName = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
$managerClassName = 'Doctrine\Tests\Models\Company\CompanyManager';
$chain = new MappingDriverChain();
$companyDriver->expects($this->never())
->method('loadMetadataForClass');
$companyDriver->expects($this->once())
->method('isTransient')
->with($this->equalTo($managerClassName))
->will($this->returnValue(false));
$dafaultDriver->expects($this->never())
->method('loadMetadataForClass');
$dafaultDriver->expects($this->once())
->method('isTransient')
->with($this->equalTo($entityClassName))
->will($this->returnValue(true));
$this->assertNull($chain->getDefaultDriver());
$chain->setDefaultDriver($dafaultDriver);
$chain->addDriver($companyDriver, 'Doctrine\Tests\Models\Company');
$this->assertSame($dafaultDriver, $chain->getDefaultDriver());
$this->assertTrue($chain->isTransient($entityClassName));
$this->assertFalse($chain->isTransient($managerClassName));
}
}
class DriverChainEntity
{
}

View file

@ -0,0 +1,139 @@
<?php
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator;
use Doctrine\Common\Persistence\Mapping\ReflectionService;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\Common\Cache\ArrayCache;
class ClassMetadataFactoryTest extends DoctrineTestCase
{
/**
* @var TestClassMetadataFactory
*/
private $cmf;
public function setUp()
{
$driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$this->cmf = new TestClassMetadataFactory($driver, $metadata);
}
public function testGetCacheDriver()
{
$this->assertNull($this->cmf->getCacheDriver());
$cache = new ArrayCache();
$this->cmf->setCacheDriver($cache);
$this->assertSame($cache, $this->cmf->getCacheDriver());
}
public function testGetMetadataFor()
{
$metadata = $this->cmf->getMetadataFor('stdClass');
$this->assertInstanceOf('Doctrine\Common\Persistence\Mapping\ClassMetadata', $metadata);
$this->assertTrue($this->cmf->hasMetadataFor('stdClass'));
}
public function testGetParentMetadata()
{
$metadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
$this->assertInstanceOf('Doctrine\Common\Persistence\Mapping\ClassMetadata', $metadata);
$this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\ChildEntity'));
$this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\RootEntity'));
}
public function testGetCachedMetadata()
{
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$cache = new ArrayCache();
$cache->save(__NAMESPACE__. '\ChildEntity$CLASSMETADATA', $metadata);
$this->cmf->setCacheDriver($cache);
$loadedMetadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
$this->assertSame($loadedMetadata, $metadata);
}
public function testCacheGetMetadataFor()
{
$cache = new ArrayCache();
$this->cmf->setCacheDriver($cache);
$loadedMetadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
$this->assertSame($loadedMetadata, $cache->fetch(__NAMESPACE__. '\ChildEntity$CLASSMETADATA'));
}
public function testGetAliasedMetadata()
{
$loadedMetadata = $this->cmf->getMetadataFor('prefix:ChildEntity');
$this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\ChildEntity'));
$this->assertTrue($this->cmf->hasMetadataFor('prefix:ChildEntity'));
}
}
class TestClassMetadataFactory extends AbstractClassMetadataFactory
{
public $driver;
public $metadata;
public function __construct($driver, $metadata)
{
$this->driver = $driver;
$this->metadata = $metadata;
}
protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents)
{
}
protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
{
return __NAMESPACE__ . '\\' . $simpleClassName;
}
protected function initialize()
{
}
protected function newClassMetadataInstance($className)
{
return $this->metadata;
}
protected function getDriver()
{
return $this->driver;
}
protected function wakeupReflection(ClassMetadata $class, ReflectionService $reflService)
{
}
protected function initializeReflection(ClassMetadata $class, ReflectionService $reflService)
{
}
protected function isEntity(ClassMetadata $class)
{
return true;
}
}
class RootEntity
{
}
class ChildEntity extends RootEntity
{
}

View file

@ -0,0 +1,90 @@
<?php
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator;
class DefaultFileLocatorTest extends DoctrineTestCase
{
public function testGetPaths()
{
$path = __DIR__ . "/_files";
$locator = new DefaultFileLocator(array($path));
$this->assertEquals(array($path), $locator->getPaths());
$locator = new DefaultFileLocator($path);
$this->assertEquals(array($path), $locator->getPaths());
}
public function testGetFileExtension()
{
$locator = new DefaultFileLocator(array(), ".yml");
$this->assertEquals(".yml", $locator->getFileExtension());
$locator->setFileExtension(".xml");
$this->assertEquals(".xml", $locator->getFileExtension());
}
public function testUniquePaths()
{
$path = __DIR__ . "/_files";
$locator = new DefaultFileLocator(array($path, $path));
$this->assertEquals(array($path), $locator->getPaths());
}
public function testFindMappingFile()
{
$path = __DIR__ . "/_files";
$locator = new DefaultFileLocator(array($path), ".yml");
$this->assertEquals(__DIR__ . '/_files' . DIRECTORY_SEPARATOR . 'stdClass.yml', $locator->findMappingFile('stdClass'));
}
public function testFindMappingFileNotFound()
{
$path = __DIR__ . "/_files";
$locator = new DefaultFileLocator(array($path), ".yml");
$this->setExpectedException(
'Doctrine\Common\Persistence\Mapping\MappingException',
"No mapping file found named 'stdClass2.yml' for class 'stdClass2'"
);
$locator->findMappingFile('stdClass2');
}
public function testGetAllClassNames()
{
$path = __DIR__ . "/_files";
$locator = new DefaultFileLocator(array($path), ".yml");
$classes = $locator->getAllClassNames(null);
sort($classes);
$this->assertEquals(array('global', 'stdClass'), $classes);
$this->assertEquals(array('stdClass'), $locator->getAllClassNames("global"));
}
public function testGetAllClassNamesNonMatchingFileExtension()
{
$path = __DIR__ . "/_files";
$locator = new DefaultFileLocator(array($path), ".xml");
$this->assertEquals(array(), $locator->getAllClassNames("global"));
}
public function testFileExists()
{
$path = __DIR__ . "/_files";
$locator = new DefaultFileLocator(array($path), ".yml");
$this->assertTrue($locator->fileExists("stdClass"));
$this->assertFalse($locator->fileExists("stdClass2"));
$this->assertTrue($locator->fileExists("global"));
$this->assertFalse($locator->fileExists("global2"));
}
}

View file

@ -0,0 +1,142 @@
<?php
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
class FileDriverTest extends DoctrineTestCase
{
public function testGlobalBasename()
{
$driver = new TestFileDriver(array());
$this->assertNull($driver->getGlobalBasename());
$driver->setGlobalBasename("global");
$this->assertEquals("global", $driver->getGlobalBasename());
}
public function testGetElementFromGlobalFile()
{
$driver = new TestFileDriver($this->newLocator());
$driver->setGlobalBasename("global");
$element = $driver->getElement('stdGlobal');
$this->assertEquals('stdGlobal', $element);
}
public function testGetElementFromFile()
{
$locator = $this->newLocator();
$locator->expects($this->once())
->method('findMappingFile')
->with($this->equalTo('stdClass'))
->will($this->returnValue(__DIR__ . '/_files/stdClass.yml'));
$driver = new TestFileDriver($locator);
$this->assertEquals('stdClass', $driver->getElement('stdClass'));
}
public function testGetAllClassNamesGlobalBasename()
{
$driver = new TestFileDriver($this->newLocator());
$driver->setGlobalBasename("global");
$classNames = $driver->getAllClassNames();
$this->assertEquals(array('stdGlobal', 'stdGlobal2'), $classNames);
}
public function testGetAllClassNamesFromMappingFile()
{
$locator = $this->newLocator();
$locator->expects($this->any())
->method('getAllClassNames')
->with($this->equalTo(null))
->will($this->returnValue(array('stdClass')));
$driver = new TestFileDriver($locator);
$classNames = $driver->getAllClassNames();
$this->assertEquals(array('stdClass'), $classNames);
}
public function testGetAllClassNamesBothSources()
{
$locator = $this->newLocator();
$locator->expects($this->any())
->method('getAllClassNames')
->with($this->equalTo('global'))
->will($this->returnValue(array('stdClass')));
$driver = new TestFileDriver($locator);
$driver->setGlobalBasename("global");
$classNames = $driver->getAllClassNames();
$this->assertEquals(array('stdGlobal', 'stdGlobal2', 'stdClass'), $classNames);
}
public function testIsNotTransient()
{
$locator = $this->newLocator();
$locator->expects($this->once())
->method('fileExists')
->with($this->equalTo('stdClass'))
->will($this->returnValue( true ));
$driver = new TestFileDriver($locator);
$driver->setGlobalBasename("global");
$this->assertFalse($driver->isTransient('stdClass'));
$this->assertFalse($driver->isTransient('stdGlobal'));
$this->assertFalse($driver->isTransient('stdGlobal2'));
}
public function testIsTransient()
{
$locator = $this->newLocator();
$locator->expects($this->once())
->method('fileExists')
->with($this->equalTo('stdClass2'))
->will($this->returnValue( false ));
$driver = new TestFileDriver($locator);
$this->assertTrue($driver->isTransient('stdClass2'));
}
public function testNonLocatorFallback()
{
$driver = new TestFileDriver(__DIR__ . '/_files', '.yml');
$this->assertTrue($driver->isTransient('stdClass2'));
$this->assertFalse($driver->isTransient('stdClass'));
}
private function newLocator()
{
$locator = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\FileLocator');
$locator->expects($this->any())->method('getFileExtension')->will($this->returnValue('.yml'));
$locator->expects($this->any())->method('getPaths')->will($this->returnValue(array(__DIR__ . "/_files")));
return $locator;
}
}
class TestFileDriver extends FileDriver
{
protected function loadMappingFile($file)
{
if (strpos($file, "global.yml") !== false) {
return array('stdGlobal' => 'stdGlobal', 'stdGlobal2' => 'stdGlobal2');
}
return array('stdClass' => 'stdClass');
}
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\Common\Persistence\Mapping\Driver\PHPDriver;
class PHPDriverTest extends DoctrineTestCase
{
public function testLoadMetadata()
{
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$metadata->expects($this->once())->method('getFieldNames');
$driver = new PHPDriver(array(__DIR__ . "/_files"));
$driver->loadMetadataForClass('TestEntity', $metadata);
}
}

View file

@ -0,0 +1,70 @@
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
/**
* @group DCOM-93
*/
class RuntimeReflectionServiceTest extends \PHPUnit_Framework_TestCase
{
private $reflectionService;
public function setUp()
{
$this->reflectionService = new RuntimeReflectionService();
}
public function testShortname()
{
$this->assertEquals("RuntimeReflectionServiceTest", $this->reflectionService->getClassShortName(__CLASS__));
}
public function testClassNamespaceName()
{
$this->assertEquals("Doctrine\Tests\Common\Persistence\Mapping", $this->reflectionService->getClassNamespace(__CLASS__));
}
public function testGetParentClasses()
{
$classes = $this->reflectionService->getParentClasses(__CLASS__);
$this->assertTrue(count($classes) >= 1, "The test class ".__CLASS__." should have at least one parent.");
}
public function testGetReflectionClass()
{
$class = $this->reflectionService->getClass(__CLASS__);
$this->assertInstanceOf("ReflectionClass", $class);
}
public function testGetMethods()
{
$this->assertTrue($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods"));
$this->assertFalse($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods2"));
}
public function testGetAccessibleProperty()
{
$reflProp = $this->reflectionService->getAccessibleProperty(__CLASS__, "reflectionService");
$this->assertInstanceOf("ReflectionProperty", $reflProp);
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver;
class StaticPHPDriverTest extends DoctrineTestCase
{
public function testLoadMetadata()
{
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$metadata->expects($this->once())->method('getFieldNames');
$driver = new StaticPHPDriver(array(__DIR__));
$driver->loadMetadataForClass(__NAMESPACE__ . '\\TestEntity', $metadata);
}
public function testGetAllClassNames()
{
$driver = new StaticPHPDriver(array(__DIR__));
$classNames = $driver->getAllClassNames();
$this->assertContains(
'Doctrine\Tests\Common\Persistence\Mapping\TestEntity', $classNames);
}
}
class TestEntity
{
static public function loadMetadata($metadata)
{
$metadata->getFieldNames();
}
}

View file

@ -0,0 +1,70 @@
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Common\Persistence\Mapping\StaticReflectionService;
/**
* @group DCOM-93
*/
class StaticReflectionServiceTest extends \PHPUnit_Framework_TestCase
{
private $reflectionService;
public function setUp()
{
$this->reflectionService = new StaticReflectionService();
}
public function testShortname()
{
$this->assertEquals("StaticReflectionServiceTest", $this->reflectionService->getClassShortName(__CLASS__));
}
public function testClassNamespaceName()
{
$this->assertEquals("Doctrine\Tests\Common\Persistence\Mapping", $this->reflectionService->getClassNamespace(__CLASS__));
}
public function testGetParentClasses()
{
$classes = $this->reflectionService->getParentClasses(__CLASS__);
$this->assertTrue(count($classes) == 0, "The test class ".__CLASS__." should have no parents according to static reflection.");
}
public function testGetReflectionClass()
{
$class = $this->reflectionService->getClass(__CLASS__);
$this->assertNull($class);
}
public function testGetMethods()
{
$this->assertTrue($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods"));
$this->assertFalse($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods2"));
}
public function testGetAccessibleProperty()
{
$reflProp = $this->reflectionService->getAccessibleProperty(__CLASS__, "reflectionService");
$this->assertNull($reflProp);
}
}

View file

@ -0,0 +1,88 @@
<?php
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator;
class SymfonyFileLocatorTest extends DoctrineTestCase
{
public function testGetPaths()
{
$path = __DIR__ . "/_files";
$prefix = "Foo";
$locator = new SymfonyFileLocator(array($path => $prefix));
$this->assertEquals(array($path), $locator->getPaths());
$locator = new SymfonyFileLocator(array($path => $prefix));
$this->assertEquals(array($path), $locator->getPaths());
}
public function testGetPrefixes()
{
$path = __DIR__ . "/_files";
$prefix = "Foo";
$locator = new SymfonyFileLocator(array($path => $prefix));
$this->assertEquals(array($path => $prefix), $locator->getNamespacePrefixes());
}
public function testGetFileExtension()
{
$locator = new SymfonyFileLocator(array(), ".yml");
$this->assertEquals(".yml", $locator->getFileExtension());
$locator->setFileExtension(".xml");
$this->assertEquals(".xml", $locator->getFileExtension());
}
public function testFileExists()
{
$path = __DIR__ . "/_files";
$prefix = "Foo";
$locator = new SymfonyFileLocator(array($path => $prefix), ".yml");
$this->assertTrue($locator->fileExists("Foo\stdClass"));
$this->assertTrue($locator->fileExists("Foo\global"));
$this->assertFalse($locator->fileExists("Foo\stdClass2"));
$this->assertFalse($locator->fileExists("Foo\global2"));
}
public function testGetAllClassNames()
{
$path = __DIR__ . "/_files";
$prefix = "Foo";
$locator = new SymfonyFileLocator(array($path => $prefix), ".yml");
$classes = $locator->getAllClassNames(null);
sort($classes);
$this->assertEquals(array("Foo\\global", "Foo\\stdClass"), $classes);
$this->assertEquals(array("Foo\\stdClass"), $locator->getAllClassNames("global"));
}
public function testFindMappingFile()
{
$path = __DIR__ . "/_files";
$prefix = "Foo";
$locator = new SymfonyFileLocator(array($path => $prefix), ".yml");
$this->assertEquals(__DIR__ . "/_files/stdClass.yml", $locator->findMappingFile("Foo\\stdClass"));
}
public function testFindMappingFileNotFound()
{
$path = __DIR__ . "/_files";
$prefix = "Foo";
$locator = new SymfonyFileLocator(array($path => $prefix), ".yml");
$this->setExpectedException(
"Doctrine\Common\Persistence\Mapping\MappingException",
"No mapping file found named '".__DIR__."/_files/stdClass2.yml' for class 'Foo\stdClass2'."
);
$locator->findMappingFile("Foo\\stdClass2");
}
}

View file

@ -0,0 +1,3 @@
<?php
$metadata->getFieldNames();

View file

@ -0,0 +1,247 @@
<?php
namespace Doctrine\Tests\Common\Persistence;
use Doctrine\Common\Persistence\PersistentObject;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\Mapping\ReflectionService;
/**
* @group DDC-1448
*/
class PersistentObjectTest extends \Doctrine\Tests\DoctrineTestCase
{
private $cm;
private $om;
private $object;
public function setUp()
{
$this->cm = new TestObjectMetadata;
$this->om = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
$this->om->expects($this->any())->method('getClassMetadata')
->will($this->returnValue($this->cm));
$this->object = new TestObject;
PersistentObject::setObjectManager($this->om);
$this->object->injectObjectManager($this->om, $this->cm);
}
public function testGetObjectManager()
{
$this->assertSame($this->om, PersistentObject::getObjectManager());
}
public function testNonMatchingObjectManager()
{
$this->setExpectedException('RuntimeException');
$om = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
$this->object->injectObjectManager($om, $this->cm);
}
public function testGetField()
{
$this->assertEquals('beberlei', $this->object->getName());
}
public function testSetField()
{
$this->object->setName("test");
$this->assertEquals("test", $this->object->getName());
}
public function testGetIdentifier()
{
$this->assertEquals(1, $this->object->getId());
}
public function testSetIdentifier()
{
$this->setExpectedException('BadMethodCallException');
$this->object->setId(2);
}
public function testSetUnknownField()
{
$this->setExpectedException('BadMethodCallException');
$this->object->setUnknown("test");
}
public function testGetUnknownField()
{
$this->setExpectedException('BadMethodCallException');
$this->object->getUnknown();
}
public function testGetToOneAssociation()
{
$this->assertNull($this->object->getParent());
}
public function testSetToOneAssociation()
{
$parent = new TestObject();
$this->object->setParent($parent);
$this->assertSame($parent, $this->object->getParent($parent));
}
public function testSetInvalidToOneAssocation()
{
$parent = new \stdClass();
$this->setExpectedException('InvalidArgumentException');
$this->object->setParent($parent);
}
public function testSetToOneAssociationNull()
{
$parent = new TestObject();
$this->object->setParent($parent);
$this->object->setParent(null);
$this->assertNull($this->object->getParent());
}
public function testAddToManyAssocation()
{
$child = new TestObject();
$this->object->addChildren($child);
$this->assertSame($this->object, $child->getParent());
$this->assertEquals(1, count($this->object->getChildren()));
$child = new TestObject();
$this->object->addChildren($child);
$this->assertEquals(2, count($this->object->getChildren()));
}
public function testAddInvalidToManyAssocation()
{
$this->setExpectedException('InvalidArgumentException');
$this->object->addChildren(new \stdClass());
}
public function testNoObjectManagerSet()
{
PersistentObject::setObjectManager(null);
$child = new TestObject();
$this->setExpectedException('RuntimeException');
$child->setName("test");
}
public function testInvalidMethod()
{
$this->setExpectedException('BadMethodCallException');
$this->object->asdf();
}
public function testAddInvalidCollection()
{
$this->setExpectedException('BadMethodCallException');
$this->object->addAsdf(new \stdClass());
}
}
class TestObject extends PersistentObject
{
protected $id = 1;
protected $name = 'beberlei';
protected $parent;
protected $children;
}
class TestObjectMetadata implements ClassMetadata
{
public function getAssociationMappedByTargetField($assocName)
{
$assoc = array('children' => 'parent');
return $assoc[$assocName];
}
public function getAssociationNames()
{
return array('parent', 'children');
}
public function getAssociationTargetClass($assocName)
{
return __NAMESPACE__ . '\TestObject';
}
public function getFieldNames()
{
return array('id', 'name');
}
public function getIdentifier()
{
return array('id');
}
public function getName()
{
return __NAMESPACE__ . '\TestObject';
}
public function getReflectionClass()
{
return new \ReflectionClass($this->getName());
}
public function getTypeOfField($fieldName)
{
$types = array('id' => 'integer', 'name' => 'string');
return $types[$fieldName];
}
public function hasAssociation($fieldName)
{
return in_array($fieldName, array('parent', 'children'));
}
public function hasField($fieldName)
{
return in_array($fieldName, array('id', 'name'));
}
public function isAssociationInverseSide($assocName)
{
return ($assocName === 'children');
}
public function isCollectionValuedAssociation($fieldName)
{
return ($fieldName === 'children');
}
public function isIdentifier($fieldName)
{
return $fieldName === 'id';
}
public function isSingleValuedAssociation($fieldName)
{
return $fieldName === 'parent';
}
public function getIdentifierValues($entity)
{
}
public function getIdentifierFieldNames()
{
}
public function initializeReflection(ReflectionService $reflService)
{
}
public function wakeupReflection(ReflectionService $reflService)
{
}
}

View file

@ -0,0 +1,7 @@
<?php
namespace Doctrine\Tests\Common\Reflection;
class SameNamespaceParent extends Dummies\NoParent
{
}

View file

@ -0,0 +1,8 @@
<?php
namespace Doctrine\Tests\Common\Reflection\Dummies;
class NoParent
{
public $test;
}

View file

@ -0,0 +1,7 @@
<?php
namespace Doctrine\Tests\Common\Reflection;
class FullyClassifiedParent extends \Doctrine\Tests\Common\Reflection\NoParent
{
}

View file

@ -0,0 +1,8 @@
<?php
namespace Doctrine\Tests\Common\Reflection;
class NoParent
{
public $test;
}

View file

@ -0,0 +1,7 @@
<?php
namespace Doctrine\Tests\Common\Reflection;
class SameNamespaceParent extends NoParent
{
}

Some files were not shown because too many files have changed in this diff Show more