Commit a4e928e1 authored by romanb's avatar romanb

[2.0] Moved addendum library to vendor dir.

parent 292e93de
......@@ -28,7 +28,6 @@ namespace Doctrine\Common;
* information to an event handler when an event is raised. The single empty EventArgs
* instance can be obtained through {@link getEmptyInstance()}.
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
......
......@@ -26,8 +26,8 @@ use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\MappingException;
/* Addendum annotation reflection extensions */
if ( ! class_exists('\Addendum', false)) {
require __DIR__ . '/addendum/annotations.php';
if ( ! class_exists('Addendum', false)) {
require __DIR__ . '/../../../../vendor/addendum/annotations.php';
}
require __DIR__ . '/DoctrineAnnotations.php';
......@@ -45,7 +45,7 @@ class AnnotationDriver
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$annotClass = new \Addendum\ReflectionAnnotatedClass($className);
$annotClass = new \ReflectionAnnotatedClass($className);
// Evaluate DoctrineEntity annotation
if (($entityAnnot = $annotClass->getAnnotation('DoctrineEntity')) === false) {
......
......@@ -21,25 +21,25 @@
/* Annotations */
final class DoctrineEntity extends \Addendum\Annotation {
final class DoctrineEntity extends \Annotation {
public $repositoryClass;
}
final class DoctrineInheritanceType extends \Addendum\Annotation {}
final class DoctrineDiscriminatorColumn extends \Addendum\Annotation {
final class DoctrineInheritanceType extends \Annotation {}
final class DoctrineDiscriminatorColumn extends \Annotation {
public $name;
public $type;
public $length;
}
final class DoctrineDiscriminatorMap extends \Addendum\Annotation {}
final class DoctrineDiscriminatorValue extends \Addendum\Annotation {}
final class DoctrineSubClasses extends \Addendum\Annotation {}
final class DoctrineId extends \Addendum\Annotation {}
final class DoctrineGeneratedValue extends \Addendum\Annotation {
final class DoctrineDiscriminatorMap extends \Annotation {}
final class DoctrineDiscriminatorValue extends \Annotation {}
final class DoctrineSubClasses extends \Annotation {}
final class DoctrineId extends \Annotation {}
final class DoctrineGeneratedValue extends \Annotation {
public $strategy;
//public $generator;
}
final class DoctrineVersion extends \Addendum\Annotation {}
final class DoctrineJoinColumn extends \Addendum\Annotation {
final class DoctrineVersion extends \Annotation {}
final class DoctrineJoinColumn extends \Annotation {
public $name;
public $referencedColumnName;
public $unique = false;
......@@ -47,55 +47,55 @@ final class DoctrineJoinColumn extends \Addendum\Annotation {
public $onDelete;
public $onUpdate;
}
final class DoctrineJoinColumns extends \Addendum\Annotation {}
final class DoctrineColumn extends \Addendum\Annotation {
final class DoctrineJoinColumns extends \Annotation {}
final class DoctrineColumn extends \Annotation {
public $type;
public $length;
public $unique = false;
public $nullable = false;
public $quote = false;
}
final class DoctrineOneToOne extends \Addendum\Annotation {
final class DoctrineOneToOne extends \Annotation {
public $targetEntity;
public $mappedBy;
public $cascade;
public $fetch;
public $optional;
}
final class DoctrineOneToMany extends \Addendum\Annotation {
final class DoctrineOneToMany extends \Annotation {
public $mappedBy;
public $targetEntity;
public $cascade;
public $fetch;
}
final class DoctrineManyToOne extends \Addendum\Annotation {
final class DoctrineManyToOne extends \Annotation {
public $targetEntity;
public $cascade;
public $fetch;
public $optional;
}
final class DoctrineManyToMany extends \Addendum\Annotation {
final class DoctrineManyToMany extends \Annotation {
public $targetEntity;
public $mappedBy;
public $cascade;
public $fetch;
}
final class DoctrineElementCollection extends \Addendum\Annotation {
final class DoctrineElementCollection extends \Annotation {
public $tableName;
}
final class DoctrineTable extends \Addendum\Annotation {
final class DoctrineTable extends \Annotation {
public $name;
public $catalog;
public $schema;
}
final class DoctrineJoinTable extends \Addendum\Annotation {
final class DoctrineJoinTable extends \Annotation {
public $name;
public $catalog;
public $schema;
public $joinColumns;
public $inverseJoinColumns;
}
final class DoctrineSequenceGenerator extends \Addendum\Annotation {
final class DoctrineSequenceGenerator extends \Annotation {
//public $name;
public $sequenceName;
public $allocationSize = 20;
......@@ -103,4 +103,4 @@ final class DoctrineSequenceGenerator extends \Addendum\Annotation {
/** The name of the class that defines the generator. */
//public $definingClass;
}
final class DoctrineChangeTrackingPolicy {}
final class DoctrineChangeTrackingPolicy extends \Annotation {}
This diff is collapsed.
......@@ -19,9 +19,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**/
namespace Addendum;
class CompositeMatcher {
protected $matchers = array();
private $wasConstructed = false;
......@@ -334,4 +332,4 @@ namespace Addendum;
return $matches[1];
}
}
?>
<?php
require_once('simpletest/autorun.php');
require_once('simpletest/mock_objects.php');
require_once(dirname(__FILE__).'/../../annotations.php');
interface DummyInterface {}
class ParentExample {}
/** @FirstAnnotation @SecondAnnotation */
class Example extends ParentExample implements DummyInterface {
/** @SecondAnnotation */
private $exampleProperty;
public $publicOne;
public function __construct() {}
/** @FirstAnnotation */
public function exampleMethod() {
}
private function justPrivate() {}
}
/** @FirstAnnotation(1) @FirstAnnotation(2) @SecondAnnotation(3) */
class MultiExample {
/** @FirstAnnotation(1) @FirstAnnotation(2) @SecondAnnotation(3) */
public $property;
/** @FirstAnnotation(1) @FirstAnnotation(2) @SecondAnnotation(3) */
public function aMethod() {}
}
class FirstAnnotation extends Annotation {}
class SecondAnnotation extends Annotation {}
class TestOfAnnotations extends UnitTestCase {
public function testReflectionAnnotatedClass() {
$reflection = new ReflectionAnnotatedClass('Example');
$this->assertTrue($reflection->hasAnnotation('FirstAnnotation'));
$this->assertTrue($reflection->hasAnnotation('SecondAnnotation'));
$this->assertFalse($reflection->hasAnnotation('NonExistentAnnotation'));
$this->assertIsA($reflection->getAnnotation('FirstAnnotation'), 'FirstAnnotation');
$this->assertIsA($reflection->getAnnotation('SecondAnnotation'), 'SecondAnnotation');
$annotations = $reflection->getAnnotations();
$this->assertEqual(count($annotations), 2);
$this->assertIsA($annotations[0], 'FirstAnnotation');
$this->assertIsA($annotations[1], 'SecondAnnotation');
$this->assertFalse($reflection->getAnnotation('NonExistentAnnotation'));
$this->assertIsA($reflection->getConstructor(), 'ReflectionAnnotatedMethod');
$this->assertIsA($reflection->getMethod('exampleMethod'), 'ReflectionAnnotatedMethod');
foreach($reflection->getMethods() as $method) {
$this->assertIsA($method, 'ReflectionAnnotatedMethod');
}
$this->assertIsA($reflection->getProperty('exampleProperty'), 'ReflectionAnnotatedProperty');
foreach($reflection->getProperties() as $property) {
$this->assertIsA($property, 'ReflectionAnnotatedProperty');
}
foreach($reflection->getInterfaces() as $interface) {
$this->assertIsA($interface, 'ReflectionAnnotatedClass');
}
$this->assertIsA($reflection->getParentClass(), 'ReflectionAnnotatedClass');
}
public function testReflectionAnnotatedMethod() {
$reflection = new ReflectionAnnotatedMethod('Example', 'exampleMethod');
$this->assertTrue($reflection->hasAnnotation('FirstAnnotation'));
$this->assertFalse($reflection->hasAnnotation('NonExistentAnnotation'));
$this->assertIsA($reflection->getAnnotation('FirstAnnotation'), 'FirstAnnotation');
$this->assertFalse($reflection->getAnnotation('NonExistentAnnotation'));
$annotations = $reflection->getAnnotations();
$this->assertEqual(count($annotations), 1);
$this->assertIsA($annotations[0], 'FirstAnnotation');
$this->assertIsA($reflection->getDeclaringClass(), 'ReflectionAnnotatedClass');
}
public function testReflectionAnnotatedProperty() {
$reflection = new ReflectionAnnotatedProperty('Example', 'exampleProperty');
$this->assertTrue($reflection->hasAnnotation('SecondAnnotation'));
$this->assertFalse($reflection->hasAnnotation('FirstAnnotation'));
$this->assertIsA($reflection->getAnnotation('SecondAnnotation'), 'SecondAnnotation');
$this->assertFalse($reflection->getAnnotation('NonExistentAnnotation'));
$annotations = $reflection->getAnnotations();
$this->assertEqual(count($annotations), 1);
$this->assertIsA($annotations[0], 'SecondAnnotation');
$this->assertIsA($reflection->getDeclaringClass(), 'ReflectionAnnotatedClass');
}
public function testReflectionClassCanFilterMethodsByAccess() {
$reflection = new ReflectionAnnotatedClass('Example');
$privateMethods = $reflection->getMethods(ReflectionMethod::IS_PRIVATE);
$this->assertEqual(count($privateMethods), 1);
$this->assertEqual($privateMethods[0]->getName(), 'justPrivate');
}
public function testReflectionClassCanFilterPropertiesByAccess() {
$reflection = new ReflectionAnnotatedClass('Example');
$privateProperties = $reflection->getProperties(ReflectionProperty::IS_PUBLIC);
$this->assertEqual(count($privateProperties), 1);
$this->assertEqual($privateProperties[0]->getName(), 'publicOne');
}
public function testReflectionClassShouldReturnAllMethodsWithNoFilter() {
$reflection = new ReflectionAnnotatedClass('Example');
$methods = $reflection->getMethods();
$this->assertEqual(count($methods), 3);
}
public function testReflectionClassShouldReturnAllPropertiesWithNoFilter() {
$reflection = new ReflectionAnnotatedClass('Example');
$properties = $reflection->getProperties();
$this->assertEqual(count($properties), 2);
}
public function testMultipleAnnotationsOnClass() {
$reflection = new ReflectionAnnotatedClass('MultiExample');
$annotations = $reflection->getAllAnnotations();
$this->assertEqual(count($annotations), 3);
$this->assertEqual($annotations[0]->value, 1);
$this->assertEqual($annotations[1]->value, 2);
$this->assertEqual($annotations[2]->value, 3);
$this->assertIsA($annotations[0], 'FirstAnnotation');
$this->assertIsA($annotations[1], 'FirstAnnotation');
$this->assertIsA($annotations[2], 'SecondAnnotation');
}
public function testMultipleAnnotationsOnClassWithRestriction() {
$reflection = new ReflectionAnnotatedClass('MultiExample');
$annotations = $reflection->getAllAnnotations('FirstAnnotation');
$this->assertEqual(count($annotations), 2);
$this->assertEqual($annotations[0]->value, 1);
$this->assertEqual($annotations[1]->value, 2);
$this->assertIsA($annotations[0], 'FirstAnnotation');
$this->assertIsA($annotations[1], 'FirstAnnotation');
}
public function testMultipleAnnotationsOnProperty() {
$reflection = new ReflectionAnnotatedClass('MultiExample');
$reflection = $reflection->getProperty('property');
$annotations = $reflection->getAllAnnotations();
$this->assertEqual(count($annotations), 3);
$this->assertEqual($annotations[0]->value, 1);
$this->assertEqual($annotations[1]->value, 2);
$this->assertEqual($annotations[2]->value, 3);
$this->assertIsA($annotations[0], 'FirstAnnotation');
$this->assertIsA($annotations[1], 'FirstAnnotation');
$this->assertIsA($annotations[2], 'SecondAnnotation');
}
public function testMultipleAnnotationsOnPropertyWithRestriction() {
$reflection = new ReflectionAnnotatedClass('MultiExample');
$reflection = $reflection->getProperty('property');
$annotations = $reflection->getAllAnnotations('FirstAnnotation');
$this->assertEqual(count($annotations), 2);
$this->assertEqual($annotations[0]->value, 1);
$this->assertEqual($annotations[1]->value, 2);
$this->assertIsA($annotations[0], 'FirstAnnotation');
$this->assertIsA($annotations[1], 'FirstAnnotation');
}
public function testMultipleAnnotationsOnMethod() {
$reflection = new ReflectionAnnotatedClass('MultiExample');
$reflection = $reflection->getMethod('aMethod');
$annotations = $reflection->getAllAnnotations();
$this->assertEqual(count($annotations), 3);
$this->assertEqual($annotations[0]->value, 1);
$this->assertEqual($annotations[1]->value, 2);
$this->assertEqual($annotations[2]->value, 3);
$this->assertIsA($annotations[0], 'FirstAnnotation');
$this->assertIsA($annotations[1], 'FirstAnnotation');
$this->assertIsA($annotations[2], 'SecondAnnotation');
}
public function testMultipleAnnotationsOnMethodWithRestriction() {
$reflection = new ReflectionAnnotatedClass('MultiExample');
$reflection = $reflection->getMethod('aMethod');
$annotations = $reflection->getAllAnnotations('FirstAnnotation');
$this->assertEqual(count($annotations), 2);
$this->assertEqual($annotations[0]->value, 1);
$this->assertEqual($annotations[1]->value, 2);
$this->assertIsA($annotations[0], 'FirstAnnotation');
$this->assertIsA($annotations[1], 'FirstAnnotation');
}
}
Mock::generatePartial('AnnotationsBuilder', 'MockedAnnotationsBuilder', array('getDocComment'));
class TestOfPerformanceFeatures extends UnitTestCase {
public function setUp() {
AnnotationsBuilder::clearCache();
}
public function tearDown() {
AnnotationsBuilder::clearCache();
}
public function testBuilderShouldCacheResults() {
$builder = new MockedAnnotationsBuilder;
$reflection = new ReflectionClass('Example');
$builder->build($reflection);
$builder->build($reflection);
$builder->expectOnce('getDocComment');
}
}
class TestOfSupportingFeatures extends UnitTestCase {
public function setUp() {
Addendum::resetIgnoredAnnotations();
}
public function tearDown() {
Addendum::resetIgnoredAnnotations();
}
public function testIgnoredAnnotationsAreNotUsed() {
Addendum::ignore('FirstAnnotation', 'SecondAnnotation');
$reflection = new ReflectionAnnotatedClass('Example');
$this->assertFalse($reflection->hasAnnotation('FirstAnnotation'));
$this->assertFalse($reflection->hasAnnotation('SecondAnnotation'));
}
}
?>
<?php
require_once('simpletest/unit_tester.php');
require_once('simpletest/reporter.php');
require_once(dirname(__FILE__).'/acceptance_test.php');
require_once(dirname(__FILE__).'/annotation_test.php');
require_once(dirname(__FILE__).'/constrained_annotation_test.php');
require_once(dirname(__FILE__).'/annotation_parser_test.php');
require_once(dirname(__FILE__).'/doc_comment_test.php');
class AllTests extends GroupTest {
function __construct($title = false) {
parent::__construct($title);
$this->addTestClass('TestOfAnnotations');
$this->addTestClass('TestOfPerformanceFeatures');
$this->addTestClass('TestOfSupportingFeatures');
$this->addTestClass('TestOfAnnotation');
$this->addTestClass('TestOfConstrainedAnnotation');
$this->addTestClass('TestOfMatchers');
$this->addTestClass('TestOfAnnotationMatchers');
$this->addTestClass('TestOfDocComment');
}
}
Addendum::setRawMode(false);
$test = new AllTests('All tests in reflection mode');
$test->run(new HtmlReporter());
Addendum::setRawMode(true);
$test = new AllTests('All tests in raw mode');
$test->run(new HtmlReporter());
?>
<?php
require_once('simpletest/autorun.php');
require_once(dirname(__FILE__).'/../../annotations.php');
class TestingAnnotation extends Annotation {
public $optional = 'default';
public $required;
}
class TestOfAnnotation extends UnitTestCase {
public function testConstructorsFillsParameters() {
$annotation = new TestingAnnotation(array('optional' => 1, 'required' => 2), $this);
$this->assertEqual($annotation->optional, 1);
$this->assertEqual($annotation->required, 2);
}
public function testConstructorThrowsErrorOnInvalidParameter() {
$annotation = new TestingAnnotation(array('unknown' => 1), $this);
$this->assertError("Property 'unknown' not defined for annotation 'TestingAnnotation'");
}
public function TODO_testConstructorThrowsErrorWithoutSpecifingRequiredParameters() {
$annotation = new TestingAnnotation();
$this->assertError("Property 'required' in annotation 'TestingAnnotation' is required");
}
}
?>
<?php
require_once('simpletest/autorun.php');
require_once(dirname(__FILE__).'/../../annotations.php');
/** @Target("class") */
class ClassRestrictedAnnotation extends Annotation {}
/** @Target("method") */
class MethodRestrictedAnnotation extends Annotation {}
/** @Target("property") */
class PropertyRestrictedAnnotation extends Annotation {}
/** @Target({"class", "property"}) */
class ClassOrPropertyRestrictedAnnotation extends Annotation {}
class BadlyAnnotatedClass {
/** @ClassRestrictedAnnotation */
private $property;
/** @ClassRestrictedAnnotation */
public function method() {}
/** @ClassOrPropertyRestrictedAnnotation */
public function method2() {}
}
/** @ClassRestrictedAnnotation */
class SuccesfullyAnnotatedClass {
/** @PropertyRestrictedAnnotation */
private $property;
/** @ClassOrPropertyRestrictedAnnotation */
private $property2;
/** @MethodRestrictedAnnotation */
public function method() {}
}
class TestOfConstrainedAnnotation extends UnitTestCase {
public function testClassAnnotationThrowsErrorWhenOnMethod() {
$this->expectError("Annotation 'ClassRestrictedAnnotation' not allowed on BadlyAnnotatedClass::method");
$reflection = new ReflectionAnnotatedClass('BadlyAnnotatedClass');
$method = $reflection->getMethod('method');
}
public function testClassAnnotationThrowsErrorWhenOnProperty() {
$this->expectError("Annotation 'ClassRestrictedAnnotation' not allowed on BadlyAnnotatedClass::\$property");
$reflection = new ReflectionAnnotatedClass('BadlyAnnotatedClass');
$method = $reflection->getProperty('property');
}
public function testSingleTargetAnnotationThrowsNoErrorWhenOnRightPlace() {
$reflection = new ReflectionAnnotatedClass('SuccesfullyAnnotatedClass');
$method = $reflection->getMethod('method');
$property = $reflection->getProperty('property');
$this->assertNoErrors();
}
public function testMultiTargetAnnotationThrowsErrorWhenOnWrongPlace() {
$this->expectError("Annotation 'ClassOrPropertyRestrictedAnnotation' not allowed on BadlyAnnotatedClass::method2");
$reflection = new ReflectionAnnotatedClass('BadlyAnnotatedClass');
$method = $reflection->getMethod('method2');
}
public function testMultiTargetAnnotationThrowsNoErrorWhenOnRightPlace() {
$reflection = new ReflectionAnnotatedClass('SuccesfullyAnnotatedClass');
$method = $reflection->getProperty('property2');
$this->assertNoErrors();
}
}
?>
\ No newline at end of file
<?php
require_once('simpletest/autorun.php');
require_once('simpletest/mock_objects.php');
require_once(dirname(__FILE__).'/../doc_comment.php');
Mock::generatePartial('DocComment', 'MockDocComment', array('parse'));
/** class doccomment */
class SomeClass {
/** field doccomment */
private $field1;
private $field2;
/** method1 doccomment */
public function method1() {
}
public function method2() {}
/** bad one */
}
class SomeOtherClass {
/** field doccomment */
private $field1;
}
class TestOfDocComment extends UnitTestCase {
public function setUp() {
DocComment::clearCache();
}
public function testFinderFindsClassDocBlock() {
$reflection = new ReflectionClass('SomeClass');
$finder = new DocComment();
$this->assertEqual($finder->get($reflection), '/** class doccomment */');
}
public function testFinderFindsFieldDocBlock() {
$reflection = new ReflectionClass('SomeClass');
$property = $reflection->getProperty('field1');
$finder = new DocComment();
$this->assertEqual($finder->get($property), '/** field doccomment */');
$property = $reflection->getProperty('field2');
$finder = new DocComment();
$this->assertFalse($finder->get($property));
}
public function testFinderFindsMethodDocBlock() {
$reflection = new ReflectionClass('SomeClass');
$method = $reflection->getMethod('method1');
$finder = new DocComment();
$this->assertEqual($finder->get($method), '/** method1 doccomment */');
$method = $reflection->getMethod('method2');
$finder = new DocComment();
$this->assertFalse($finder->get($method));
}
public function testMisplacedDocCommentDoesNotCausesDisaster() {
$reflection = new ReflectionClass('SomeOtherClass');
$finder = new DocComment();
$this->assertEqual($finder->get($reflection), false);
}
public function testUnanotatedClassCanHaveAnotatedField() {
$reflection = new ReflectionClass('SomeOtherClass');
$property = $reflection->getProperty('field1');
$finder = new DocComment();
$this->assertEqual($finder->get($property), '/** field doccomment */');
}
public function testParserIsOnlyCalledOncePerFile() {
$reflection = new ReflectionClass('SomeClass');
$finder = new MockDocComment();
$finder->expectOnce('parse');
$this->assertEqual($finder->get($reflection), false);
$this->assertEqual($finder->get($reflection), false);
$reflection = new ReflectionClass('SomeClass');
$finder = new MockDocComment();
$finder->expectNever('parse');
$this->assertEqual($finder->get($reflection), false);
}
}
?>
......@@ -13,11 +13,17 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp() {
parent::setUp();
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ParentEntity'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ChildEntity'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\RelatedEntity')
));
try {
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ParentEntity'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ChildEntity'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\RelatedEntity')
));
} catch (\Exception $e) {
if (stripos($e->getMessage(), 'already exists') === false) {
throw $e;
}
}
}
public function testCRUD()
......@@ -38,7 +44,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$relatedEntity->setOwner($child);
$this->_em->save($relatedEntity);
$this->_em->flush();
$this->_em->clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment