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; ...@@ -28,7 +28,6 @@ namespace Doctrine\Common;
* information to an event handler when an event is raised. The single empty EventArgs * information to an event handler when an event is raised. The single empty EventArgs
* instance can be obtained through {@link getEmptyInstance()}. * instance can be obtained through {@link getEmptyInstance()}.
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel * @author Roman Borschel
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org * @link www.doctrine-project.org
......
...@@ -26,8 +26,8 @@ use Doctrine\ORM\Mapping\ClassMetadata; ...@@ -26,8 +26,8 @@ use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\MappingException; use Doctrine\ORM\Mapping\MappingException;
/* Addendum annotation reflection extensions */ /* Addendum annotation reflection extensions */
if ( ! class_exists('\Addendum', false)) { if ( ! class_exists('Addendum', false)) {
require __DIR__ . '/addendum/annotations.php'; require __DIR__ . '/../../../../vendor/addendum/annotations.php';
} }
require __DIR__ . '/DoctrineAnnotations.php'; require __DIR__ . '/DoctrineAnnotations.php';
...@@ -45,7 +45,7 @@ class AnnotationDriver ...@@ -45,7 +45,7 @@ class AnnotationDriver
*/ */
public function loadMetadataForClass($className, ClassMetadata $metadata) public function loadMetadataForClass($className, ClassMetadata $metadata)
{ {
$annotClass = new \Addendum\ReflectionAnnotatedClass($className); $annotClass = new \ReflectionAnnotatedClass($className);
// Evaluate DoctrineEntity annotation // Evaluate DoctrineEntity annotation
if (($entityAnnot = $annotClass->getAnnotation('DoctrineEntity')) === false) { if (($entityAnnot = $annotClass->getAnnotation('DoctrineEntity')) === false) {
......
...@@ -21,25 +21,25 @@ ...@@ -21,25 +21,25 @@
/* Annotations */ /* Annotations */
final class DoctrineEntity extends \Addendum\Annotation { final class DoctrineEntity extends \Annotation {
public $repositoryClass; public $repositoryClass;
} }
final class DoctrineInheritanceType extends \Addendum\Annotation {} final class DoctrineInheritanceType extends \Annotation {}
final class DoctrineDiscriminatorColumn extends \Addendum\Annotation { final class DoctrineDiscriminatorColumn extends \Annotation {
public $name; public $name;
public $type; public $type;
public $length; public $length;
} }
final class DoctrineDiscriminatorMap extends \Addendum\Annotation {} final class DoctrineDiscriminatorMap extends \Annotation {}
final class DoctrineDiscriminatorValue extends \Addendum\Annotation {} final class DoctrineDiscriminatorValue extends \Annotation {}
final class DoctrineSubClasses extends \Addendum\Annotation {} final class DoctrineSubClasses extends \Annotation {}
final class DoctrineId extends \Addendum\Annotation {} final class DoctrineId extends \Annotation {}
final class DoctrineGeneratedValue extends \Addendum\Annotation { final class DoctrineGeneratedValue extends \Annotation {
public $strategy; public $strategy;
//public $generator; //public $generator;
} }
final class DoctrineVersion extends \Addendum\Annotation {} final class DoctrineVersion extends \Annotation {}
final class DoctrineJoinColumn extends \Addendum\Annotation { final class DoctrineJoinColumn extends \Annotation {
public $name; public $name;
public $referencedColumnName; public $referencedColumnName;
public $unique = false; public $unique = false;
...@@ -47,55 +47,55 @@ final class DoctrineJoinColumn extends \Addendum\Annotation { ...@@ -47,55 +47,55 @@ final class DoctrineJoinColumn extends \Addendum\Annotation {
public $onDelete; public $onDelete;
public $onUpdate; public $onUpdate;
} }
final class DoctrineJoinColumns extends \Addendum\Annotation {} final class DoctrineJoinColumns extends \Annotation {}
final class DoctrineColumn extends \Addendum\Annotation { final class DoctrineColumn extends \Annotation {
public $type; public $type;
public $length; public $length;
public $unique = false; public $unique = false;
public $nullable = false; public $nullable = false;
public $quote = false; public $quote = false;
} }
final class DoctrineOneToOne extends \Addendum\Annotation { final class DoctrineOneToOne extends \Annotation {
public $targetEntity; public $targetEntity;
public $mappedBy; public $mappedBy;
public $cascade; public $cascade;
public $fetch; public $fetch;
public $optional; public $optional;
} }
final class DoctrineOneToMany extends \Addendum\Annotation { final class DoctrineOneToMany extends \Annotation {
public $mappedBy; public $mappedBy;
public $targetEntity; public $targetEntity;
public $cascade; public $cascade;
public $fetch; public $fetch;
} }
final class DoctrineManyToOne extends \Addendum\Annotation { final class DoctrineManyToOne extends \Annotation {
public $targetEntity; public $targetEntity;
public $cascade; public $cascade;
public $fetch; public $fetch;
public $optional; public $optional;
} }
final class DoctrineManyToMany extends \Addendum\Annotation { final class DoctrineManyToMany extends \Annotation {
public $targetEntity; public $targetEntity;
public $mappedBy; public $mappedBy;
public $cascade; public $cascade;
public $fetch; public $fetch;
} }
final class DoctrineElementCollection extends \Addendum\Annotation { final class DoctrineElementCollection extends \Annotation {
public $tableName; public $tableName;
} }
final class DoctrineTable extends \Addendum\Annotation { final class DoctrineTable extends \Annotation {
public $name; public $name;
public $catalog; public $catalog;
public $schema; public $schema;
} }
final class DoctrineJoinTable extends \Addendum\Annotation { final class DoctrineJoinTable extends \Annotation {
public $name; public $name;
public $catalog; public $catalog;
public $schema; public $schema;
public $joinColumns; public $joinColumns;
public $inverseJoinColumns; public $inverseJoinColumns;
} }
final class DoctrineSequenceGenerator extends \Addendum\Annotation { final class DoctrineSequenceGenerator extends \Annotation {
//public $name; //public $name;
public $sequenceName; public $sequenceName;
public $allocationSize = 20; public $allocationSize = 20;
...@@ -103,4 +103,4 @@ final class DoctrineSequenceGenerator extends \Addendum\Annotation { ...@@ -103,4 +103,4 @@ final class DoctrineSequenceGenerator extends \Addendum\Annotation {
/** The name of the class that defines the generator. */ /** The name of the class that defines the generator. */
//public $definingClass; //public $definingClass;
} }
final class DoctrineChangeTrackingPolicy {} final class DoctrineChangeTrackingPolicy extends \Annotation {}
<?php
/**
* Addendum PHP Reflection Annotations
* http://code.google.com/p/addendum/
*
* Copyright (C) 2006 Jan "johno Suchal <johno@jsmf.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* 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;
use \ReflectionClass;
use \ReflectionMethod;
use \ReflectionProperty;
require_once(dirname(__FILE__).'/annotations/annotation_parser.php');
class Annotation {
public $value;
public final function __construct($data, $target) {
$reflection = new ReflectionClass($this);
foreach($data as $key => $value) {
if($reflection->hasProperty($key)) {
$this->$key = $value;
} else {
$class = $reflection->getName();
trigger_error("Property '$key' not defined for annotation '$class'");
}
}
$this->checkTargetConstraints($target);
$this->checkConstraints($target);
}
private function checkTargetConstraints($target) {
$reflection = new ReflectionAnnotatedClass($this);
if($reflection->hasAnnotation('Target')) {
$value = $reflection->getAnnotation('Target')->value;
$values = is_array($value) ? $value : array($value);
foreach($values as $value) {
if($value == 'class' && $target instanceof ReflectionClass) return;
if($value == 'method' && $target instanceof ReflectionMethod) return;
if($value == 'property' && $target instanceof ReflectionProperty) return;
}
trigger_error("Annotation '".get_class($this)."' not allowed on ".$this->createName($target), E_USER_ERROR);
}
}
private function createName($target) {
if($target instanceof ReflectionMethod) {
return $target->getDeclaringClass()->getName().'::'.$target->getName();
} elseif($target instanceof ReflectionProperty) {
return $target->getDeclaringClass()->getName().'::$'.$target->getName();
} else {
return $target->getName();
}
}
protected function checkConstraints($target) {}
}
class Target extends Annotation {}
class AnnotationsBuilder {
private static $cache = array();
public function build($targetReflection) {
$data = $this->parse($targetReflection);
$annotations = array();
foreach($data as $class => $parameters) {
if(is_subclass_of($class, '\Addendum\Annotation')) {
foreach($parameters as $params) {
$annotationReflection = new ReflectionClass($class);
$annotations[$class][] = $annotationReflection->newInstance($params, $targetReflection);
}
}
}
return $annotations;
}
private function parse($reflection) {
$key = $this->createName($reflection);
if(!isset(self::$cache[$key])) {
$parser = new AnnotationsMatcher;
$parser->matches($this->getDocComment($reflection), $data);
self::$cache[$key] = $data;
}
return self::$cache[$key];
}
private function createName($target) {
if($target instanceof ReflectionMethod) {
return $target->getDeclaringClass()->getName().'::'.$target->getName();
} elseif($target instanceof ReflectionProperty) {
return $target->getDeclaringClass()->getName().'::$'.$target->getName();
} else {
return $target->getName();
}
}
protected function getDocComment($reflection) {
return Addendum::getDocComment($reflection);
}
public static function clearCache() {
self::$cache = array();
}
}
class ReflectionAnnotatedClass extends ReflectionClass {
private $annotations;
public function __construct($class) {
parent::__construct($class);
$this->annotations = $this->createAnnotationBuilder()->build($this);
}
public function hasAnnotation($annotation) {
return isset($this->annotations[$annotation]);
}
public function getAnnotation($annotation) {
return $this->hasAnnotation($annotation) ? end($this->annotations[$annotation]) : false;
}
public function getAnnotations() {
$result = array();
foreach($this->annotations as $instances) {
$result[] = end($instances);
}
return $result;
}
public function getAllAnnotations($restriction = false) {
$result = array();
foreach($this->annotations as $class => $instances) {
if(!$restriction || $restriction == $class) {
$result = array_merge($result, $instances);
}
}
return $result;
}
public function getConstructor() {
return $this->createReflectionAnnotatedMethod(parent::getConstructor());
}
public function getMethod($name) {
return $this->createReflectionAnnotatedMethod(parent::getMethod($name));
}
public function getMethods($filter = -1) {
$result = array();
foreach(parent::getMethods($filter) as $method) {
$result[] = $this->createReflectionAnnotatedMethod($method);
}
return $result;
}
public function getProperty($name) {
return $this->createReflectionAnnotatedProperty(parent::getProperty($name));
}
public function getProperties($filter = -1) {
$result = array();
foreach(parent::getProperties($filter) as $property) {
$result[] = $this->createReflectionAnnotatedProperty($property);
}
return $result;
}
public function getInterfaces() {
$result = array();
foreach(parent::getInterfaces() as $interface) {
$result[] = $this->createReflectionAnnotatedClass($interface);
}
return $result;
}
public function getParentClass() {
$class = parent::getParentClass();
return $this->createReflectionAnnotatedClass($class);
}
protected function createAnnotationBuilder() {
return new AnnotationsBuilder();
}
private function createReflectionAnnotatedClass($class) {
return ($class !== false) ? new ReflectionAnnotatedClass($class->getName()) : false;
}
private function createReflectionAnnotatedMethod($method) {
return ($method !== null) ? new ReflectionAnnotatedMethod($this->getName(), $method->getName()) : null;
}
private function createReflectionAnnotatedProperty($property) {
return ($property !== null) ? new ReflectionAnnotatedProperty($this->getName(), $property->getName()) : null;
}
}
class ReflectionAnnotatedMethod extends ReflectionMethod {
private $annotations;
public function __construct($class, $name) {
parent::__construct($class, $name);
$this->annotations = $this->createAnnotationBuilder()->build($this);
}
public function hasAnnotation($annotation) {
return isset($this->annotations[$annotation]);
}
public function getAnnotation($annotation) {
return ($this->hasAnnotation($annotation)) ? end($this->annotations[$annotation]) : false;
}
public function getAnnotations() {
$result = array();
foreach($this->annotations as $instances) {
$result[] = end($instances);
}
return $result;
}
public function getAllAnnotations($restriction = false) {
$result = array();
foreach($this->annotations as $class => $instances) {
if(!$restriction || $restriction == $class) {
$result = array_merge($result, $instances);
}
}
return $result;
}
public function getDeclaringClass() {
$class = parent::getDeclaringClass();
return new ReflectionAnnotatedClass($class->getName());
}
protected function createAnnotationBuilder() {
return new AnnotationsBuilder();
}
}
class ReflectionAnnotatedProperty extends ReflectionProperty {
private $annotations;
public function __construct($class, $name) {
parent::__construct($class, $name);
$this->annotations = $this->createAnnotationBuilder()->build($this);
}
public function hasAnnotation($annotation) {
return isset($this->annotations[$annotation]);
}
public function getAnnotation($annotation) {
return ($this->hasAnnotation($annotation)) ? end($this->annotations[$annotation]) : false;
}
public function getAnnotations() {
$result = array();
foreach($this->annotations as $instances) {
$result[] = end($instances);
}
return $result;
}
public function getAllAnnotations($restriction = false) {
$result = array();
foreach($this->annotations as $class => $instances) {
if(!$restriction || $restriction == $class) {
$result = array_merge($result, $instances);
}
}
return $result;
}
public function getDeclaringClass() {
$class = parent::getDeclaringClass();
return new ReflectionAnnotatedClass($class->getName());
}
protected function createAnnotationBuilder() {
return new AnnotationsBuilder();
}
}
class Addendum {
private static $rawMode;
private static $ignored;
public static function getDocComment($reflection) {
if(self::checkRawDocCommentParsingNeeded()) {
$docComment = new DocComment();
return $docComment->get($reflection);
} else {
return $reflection->getDocComment();
}
}
/** Raw mode test */
private static function checkRawDocCommentParsingNeeded() {
if(self::$rawMode === null) {
$reflection = new ReflectionClass('\Addendum\Addendum');
$method = $reflection->getMethod('checkRawDocCommentParsingNeeded');
self::setRawMode($method->getDocComment() === false);
}
return self::$rawMode;
}
public static function setRawMode($enabled = true) {
if($enabled) {
require_once(dirname(__FILE__).'/annotations/doc_comment.php');
}
self::$rawMode = $enabled;
}
public static function ignore(array $annotations) {
self::$ignored = array_combine($annotations, array_fill(0, count($annotations), true));
}
public static function ignores($annotation) {
return isset(self::$ignored[$annotation]);
}
}
<?php
/**
* Addendum PHP Reflection Annotations
* http://code.google.com/p/addendum/
*
* Copyright (C) 2006 Jan "johno Suchal <johno@jsmf.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**/
require_once(dirname(__FILE__).'/annotations/annotation_parser.php');
class Annotation {
public $value;
public final function __construct($data, $target) {
$reflection = new ReflectionClass($this);
foreach($data as $key => $value) {
if($reflection->hasProperty($key)) {
$this->$key = $value;
} else {
$class = $reflection->getName();
trigger_error("Property '$key' not defined for annotation '$class'");
}
}
$this->checkTargetConstraints($target);
$this->checkConstraints($target);
}
private function checkTargetConstraints($target) {
$reflection = new ReflectionAnnotatedClass($this);
if($reflection->hasAnnotation('Target')) {
$value = $reflection->getAnnotation('Target')->value;
$values = is_array($value) ? $value : array($value);
foreach($values as $value) {
if($value == 'class' && $target instanceof ReflectionClass) return;
if($value == 'method' && $target instanceof ReflectionMethod) return;
if($value == 'property' && $target instanceof ReflectionProperty) return;
}
trigger_error("Annotation '".get_class($this)."' not allowed on ".$this->createName($target), E_USER_ERROR);
}
}
private function createName($target) {
if($target instanceof ReflectionMethod) {
return $target->getDeclaringClass()->getName().'::'.$target->getName();
} elseif($target instanceof ReflectionProperty) {
return $target->getDeclaringClass()->getName().'::$'.$target->getName();
} else {
return $target->getName();
}
}
protected function checkConstraints($target) {}
}
class Target extends Annotation {}
class AnnotationsBuilder {
private static $cache = array();
public function build($targetReflection) {
$data = $this->parse($targetReflection);
$annotations = array();
foreach($data as $class => $parameters) {
if(!Addendum::ignores($class)) {
foreach($parameters as $params) {
$annotationReflection = new ReflectionClass($class);
$annotations[$class][] = $annotationReflection->newInstance($params, $targetReflection);
}
}
}
return $annotations;
}
private function parse($reflection) {
$key = $this->createName($reflection);
if(!isset(self::$cache[$key])) {
$parser = new AnnotationsMatcher;
$parser->matches($this->getDocComment($reflection), $data);
self::$cache[$key] = $data;
}
return self::$cache[$key];
}
private function createName($target) {
if($target instanceof ReflectionMethod) {
return $target->getDeclaringClass()->getName().'::'.$target->getName();
} elseif($target instanceof ReflectionProperty) {
return $target->getDeclaringClass()->getName().'::$'.$target->getName();
} else {
return $target->getName();
}
}
protected function getDocComment($reflection) {
return Addendum::getDocComment($reflection);
}
public static function clearCache() {
self::$cache = array();
}
}
class ReflectionAnnotatedClass extends ReflectionClass {
private $annotations;
public function __construct($class) {
parent::__construct($class);
$this->annotations = $this->createAnnotationBuilder()->build($this);
}
public function hasAnnotation($annotation) {
return isset($this->annotations[$annotation]);
}
public function getAnnotation($annotation) {
return $this->hasAnnotation($annotation) ? end($this->annotations[$annotation]) : false;
}
public function getAnnotations() {
$result = array();
foreach($this->annotations as $instances) {
$result[] = end($instances);
}
return $result;
}
public function getAllAnnotations($restriction = false) {
$result = array();
foreach($this->annotations as $class => $instances) {
if(!$restriction || $restriction == $class) {
$result = array_merge($result, $instances);
}
}
return $result;
}
public function getConstructor() {
return $this->createReflectionAnnotatedMethod(parent::getConstructor());
}
public function getMethod($name) {
return $this->createReflectionAnnotatedMethod(parent::getMethod($name));
}
public function getMethods($filter = -1) {
$result = array();
foreach(parent::getMethods($filter) as $method) {
$result[] = $this->createReflectionAnnotatedMethod($method);
}
return $result;
}
public function getProperty($name) {
return $this->createReflectionAnnotatedProperty(parent::getProperty($name));
}
public function getProperties($filter = -1) {
$result = array();
foreach(parent::getProperties($filter) as $property) {
$result[] = $this->createReflectionAnnotatedProperty($property);
}
return $result;
}
public function getInterfaces() {
$result = array();
foreach(parent::getInterfaces() as $interface) {
$result[] = $this->createReflectionAnnotatedClass($interface);
}
return $result;
}
public function getParentClass() {
$class = parent::getParentClass();
return $this->createReflectionAnnotatedClass($class);
}
protected function createAnnotationBuilder() {
return new AnnotationsBuilder();
}
private function createReflectionAnnotatedClass($class) {
return ($class !== false) ? new ReflectionAnnotatedClass($class->getName()) : false;
}
private function createReflectionAnnotatedMethod($method) {
return ($method !== null) ? new ReflectionAnnotatedMethod($this->getName(), $method->getName()) : null;
}
private function createReflectionAnnotatedProperty($property) {
return ($property !== null) ? new ReflectionAnnotatedProperty($this->getName(), $property->getName()) : null;
}
}
class ReflectionAnnotatedMethod extends ReflectionMethod {
private $annotations;
public function __construct($class, $name) {
parent::__construct($class, $name);
$this->annotations = $this->createAnnotationBuilder()->build($this);
}
public function hasAnnotation($annotation) {
return isset($this->annotations[$annotation]);
}
public function getAnnotation($annotation) {
return ($this->hasAnnotation($annotation)) ? end($this->annotations[$annotation]) : false;
}
public function getAnnotations() {
$result = array();
foreach($this->annotations as $instances) {
$result[] = end($instances);
}
return $result;
}
public function getAllAnnotations($restriction = false) {
$result = array();
foreach($this->annotations as $class => $instances) {
if(!$restriction || $restriction == $class) {
$result = array_merge($result, $instances);
}
}
return $result;
}
public function getDeclaringClass() {
$class = parent::getDeclaringClass();
return new ReflectionAnnotatedClass($class->getName());
}
protected function createAnnotationBuilder() {
return new AnnotationsBuilder();
}
}
class ReflectionAnnotatedProperty extends ReflectionProperty {
private $annotations;
public function __construct($class, $name) {
parent::__construct($class, $name);
$this->annotations = $this->createAnnotationBuilder()->build($this);
}
public function hasAnnotation($annotation) {
return isset($this->annotations[$annotation]);
}
public function getAnnotation($annotation) {
return ($this->hasAnnotation($annotation)) ? end($this->annotations[$annotation]) : false;
}
public function getAnnotations() {
$result = array();
foreach($this->annotations as $instances) {
$result[] = end($instances);
}
return $result;
}
public function getAllAnnotations($restriction = false) {
$result = array();
foreach($this->annotations as $class => $instances) {
if(!$restriction || $restriction == $class) {
$result = array_merge($result, $instances);
}
}
return $result;
}
public function getDeclaringClass() {
$class = parent::getDeclaringClass();
return new ReflectionAnnotatedClass($class->getName());
}
protected function createAnnotationBuilder() {
return new AnnotationsBuilder();
}
}
class Addendum {
private static $rawMode;
private static $ignore;
public static function getDocComment($reflection) {
if(self::checkRawDocCommentParsingNeeded()) {
$docComment = new DocComment();
return $docComment->get($reflection);
} else {
return $reflection->getDocComment();
}
}
/** Raw mode test */
private static function checkRawDocCommentParsingNeeded() {
if(self::$rawMode === null) {
$reflection = new ReflectionClass('Addendum');
$method = $reflection->getMethod('checkRawDocCommentParsingNeeded');
self::setRawMode($method->getDocComment() === false);
}
return self::$rawMode;
}
public static function setRawMode($enabled = true) {
if($enabled) {
require_once(dirname(__FILE__).'/annotations/doc_comment.php');
}
self::$rawMode = $enabled;
}
public static function resetIgnoredAnnotations() {
self::$ignore = array();
}
public static function ignores($class) {
return isset(self::$ignore[$class]);
}
public static function ignore() {
foreach(func_get_args() as $class) {
self::$ignore[$class] = true;
}
}
}
?>
...@@ -19,9 +19,7 @@ ...@@ -19,9 +19,7 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**/ **/
namespace Addendum;
class CompositeMatcher { class CompositeMatcher {
protected $matchers = array(); protected $matchers = array();
private $wasConstructed = false; private $wasConstructed = false;
...@@ -334,4 +332,4 @@ namespace Addendum; ...@@ -334,4 +332,4 @@ namespace Addendum;
return $matches[1]; 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__).'/../annotation_parser.php');
class TestOfMatchers extends UnitTestCase {
public function testRegexMatcherShouldMatchPatternAndReturnLengthOfMatch() {
$matcher = new RegexMatcher('[0-9]+');
$this->assertIdentical($matcher->matches('1234a', $value), 4);
$this->assertIdentical($value, '1234');
}
public function testRegexMatcherShouldReturnFalseOnNoMatch() {
$matcher = new RegexMatcher('[0-9]+');
$this->assertFalse($matcher->matches('abc123', $value));
}
public function testParallelMatcherShouldMatchLongerStringOnColision() {
$matcher = new ParallelMatcher;
$matcher->add(new RegexMatcher('true'));
$matcher->add(new RegexMatcher('.+'));
$this->assertEqual($matcher->matches('truestring', $value), 10);
$this->assertEqual($value, 'truestring');
}
public function testSerialMatcherShouldMatchAllParts() {
$matcher = new SerialMatcher;
$matcher->add(new RegexMatcher('[a-zA-Z0-9_]+'));
$matcher->add(new RegexMatcher('='));
$matcher->add(new RegexMatcher('[0-9]+'));
$this->assertEqual($matcher->matches('key=20', $value), 6);
$this->assertEqual($value, 'key=20');
}
public function testSerialMatcherShouldFailIfAnyPartDoesNotMatch() {
$matcher = new SerialMatcher;
$matcher->add(new RegexMatcher('[a-zA-Z0-9_]+'));
$matcher->add(new RegexMatcher('='));
$matcher->add(new RegexMatcher('[0-9]+'));
$this->assertFalse($matcher->matches('key=a20', $value));
}
public function testSimpleSerialMatcherShouldReturnRequestedPartOnMatch() {
$matcher = new SimpleSerialMatcher(1);
$matcher->add(new RegexMatcher('\('));
$matcher->add(new RegexMatcher('[0-9]+'));
$matcher->add(new RegexMatcher('\)'));
$this->assertEqual($matcher->matches('(1234)', $value), 6);
$this->assertEqual($value, '1234');
}
}
class TestOfAnnotationMatchers extends UnitTestCase {
public function testAnnotationsMatcherShouldMatchAnnotationWithGarbage() {
$expected = array('Annotation' => array(
array('value' => true),
));
$matcher = new AnnotationsMatcher;
$this->assertMatcherResult($matcher, '/** asd bla bla @Annotation(true) */@', $expected);
}
public function testAnnotationsMatcherShouldNotMatchEmail() {
$matcher = new AnnotationsMatcher;
$this->assertMatcherResult($matcher, 'johno@example.com', array());
}
public function testAnnotationsMatcherShouldMatchMultipleAnnotations() {
$expected = array('Annotation' => array(
array('value' => true),
array('value' => false)
));
$matcher = new AnnotationsMatcher;
$this->assertMatcherResult($matcher, ' ss @Annotation(true) @Annotation(false)', $expected);
}
public function testAnnotationsMatcherShouldMatchMultipleAnnotationsOnManyLines() {
$expected = array('Annotation' => array(
array('value' => true),
array('value' => false)
));
$block = "/**
@Annotation(true)
@Annotation(false)
**/";
$matcher = new AnnotationsMatcher;
$this->assertMatcherResult($matcher, $block, $expected);
}
public function testAnnotationMatcherShouldMatchMultilineAnnotations() {
$block= '/**
* @Annotation(
paramOne="value1",
paramTwo={
"value2" ,
{"one", "two"}
},
paramThree="three"
)
*/';
$expected = array('Annotation' => array(
array(
'paramOne' => 'value1',
'paramTwo' => array('value2', array('one', 'two')),
'paramThree' => 'three',
)
));
$matcher = new AnnotationsMatcher;
$this->assertMatcherResult($matcher, $block, $expected);
}
public function testAnnotationMatcherShouldMatchSimpleAnnotation() {
$matcher = new AnnotationMatcher;
$this->assertNotFalse($matcher->matches('@Namespace_Annotation', $value));
$this->assertEqual($value, array('Namespace_Annotation', array()));
}
public function testAnnotationMatcherShouldNotMatchAnnotationWithSmallStartingLetter() {
$matcher = new AnnotationMatcher;
$this->assertFalse($matcher->matches('@annotation', $value));
}
public function testAnnotationMatcherShouldMatchAlsoBrackets() {
$matcher = new AnnotationMatcher;
$this->assertEqual($matcher->matches('@Annotation()', $value), 13);
$this->assertEqual($value, array('Annotation', array()));
}
public function testAnnotationMatcherShouldMatchValuedAnnotation() {
$matcher = new AnnotationMatcher;
$this->assertMatcherResult($matcher, '@Annotation(true)', array('Annotation', array('value' => true)));
}
public function testAnnotationMatcherShouldMatchMultiValuedAnnotation() {
$matcher = new AnnotationMatcher;
$this->assertMatcherResult($matcher, '@Annotation(key=true, key2=3.14)', array('Annotation', array('key' => true, 'key2' => 3.14)));
}
public function testParametersMatcherShouldMatchEmptyStringAndReturnEmptyArray() {
$matcher = new AnnotationParametersMatcher;
$this->assertIdentical($matcher->matches('', $value), 0);
$this->assertEqual($value, array());
}
public function testParametersMatcherShouldMatchEmptyBracketsAndReturnEmptyArray() {
$matcher = new AnnotationParametersMatcher;
$this->assertIdentical($matcher->matches('()', $value), 2);
$this->assertEqual($value, array());
}
public function testParametersMatcherShouldMatchMultilinedParameters() {
$matcher = new AnnotationParametersMatcher;
$block = "(
key = true,
key2 = false
)";
$this->assertMatcherResult($matcher, $block, array('key' => true, 'key2' => false));
}
public function testValuesMatcherShouldMatchSimpleValueOrHash() {
$matcher = new AnnotationValuesMatcher;
$this->assertNotFalse($matcher->matches('true', $value));
$this->assertNotFalse($matcher->matches('key=true', $value));
}
public function testValueMatcherShouldMatchConstants() {
$matcher = new AnnotationValueMatcher;
$this->assertMatcherResult($matcher, 'true', true);
$this->assertMatcherResult($matcher, 'false', false);
$this->assertMatcherResult($matcher, 'TRUE', true);
$this->assertMatcherResult($matcher, 'FALSE', false);
}
public function testValueMatcherShouldMatchStrings() {
$matcher = new AnnotationValueMatcher;
$this->assertMatcherResult($matcher, '"string"', 'string');
$this->assertMatcherResult($matcher, "'string'", 'string');
}
public function testValueMatcherShouldMatchNumbers() {
$matcher = new AnnotationValueMatcher;
$this->assertMatcherResult($matcher, '-3.14', -3.14);
$this->assertMatcherResult($matcher, '100', 100);
}
public function testValueMatcherShouldMatchArray() {
$matcher = new AnnotationValueMatcher;
$this->assertMatcherResult($matcher, '{1}', array(1));
}
public function testArrayMatcherShouldMatchEmptyArray() {
$matcher = new AnnotationArrayMatcher;
$this->assertMatcherResult($matcher, '{}', array());
}
public function testValueInArrayMatcherReturnsAValueInArray() {
$matcher = new AnnotationValueInArrayMatcher;
$this->assertMatcherResult($matcher, '1', array(1));
}
public function testArrayMatcherShouldMatchSimpleValueInArray() {
$matcher = new AnnotationArrayMatcher;
$this->assertMatcherResult($matcher, '{1}', array(1));
}
public function testArrayMatcherShouldMatchSimplePair() {
$matcher = new AnnotationArrayMatcher;
$this->assertMatcherResult($matcher, '{key=5}', array('key' => 5));
}
public function TODO_testArrayMatcherShouldMatchPairWithNumericKeys() {
$matcher = new AnnotationArrayMatcher;
$this->assertMatcherResult($matcher, '{1="one", 2="two"}', array(1 => 'one', 2 => 'two'));
}
public function testArrayMatcherShouldMatchMultiplePairs() {
$matcher = new AnnotationArrayMatcher;
$this->assertMatcherResult($matcher, '{key=5, "bla"=false}', array('key' => 5, 'bla' => false));
}
public function testArrayMatcherShouldMatchValuesMixedWithPairs() {
$matcher = new AnnotationArrayMatcher;
$this->assertMatcherResult($matcher, '{key=5, 1, 2, key2="ff"}', array('key' => 5, 1, 2, 'key2' => "ff"));
}
public function testArrayMatcherShouldMatchMoreValuesInArrayWithWhiteSpace() {
$matcher = new AnnotationArrayMatcher;
$this->assertMatcherResult($matcher, "{1 , 2}", array(1, 2));
}
public function testArrayMatcherShouldMatchNestedArray() {
$matcher = new AnnotationArrayMatcher;
$this->assertMatcherResult($matcher, "{1 , {2, 3}, 4}", array(1, array(2, 3), 4));
}
public function testArrayMatcherShouldMatchWithMoreWhiteSpace() {
$matcher = new AnnotationArrayMatcher;
$this->assertMatcherResult($matcher, "{ 1 , 2 , 3 }", array(1, 2, 3));
}
public function testArrayMatcherShouldMatchWithMultilineWhiteSpace() {
$matcher = new AnnotationArrayMatcher;
$this->assertMatcherResult($matcher, "\n{1, 2, 3\n}", array(1, 2, 3));
}
public function testNumberMatcherShouldMatchInteger() {
$matcher = new AnnotationNumberMatcher;
$this->assertMatcherResult($matcher, '-314', -314);
}
public function testNumberMatcherShouldMatchFloat() {
$matcher = new AnnotationNumberMatcher;
$this->assertMatcherResult($matcher, '-3.14', -3.14);
}
public function testHashMatcherShouldMatchSimpleHash() {
$matcher = new AnnotationHashMatcher;
$this->assertMatcherResult($matcher, 'key=true', array('key' => true));
}
public function testHashMatcherShouldMatchAlsoMultipleKeys() {
$matcher = new AnnotationHashMatcher;
$this->assertMatcherResult($matcher, 'key=true,key2=false', array('key' => true, 'key2' => false));
}
public function testHashMatcherShouldMatchAlsoMultipleKeysWithWhiteSpace() {
$matcher = new AnnotationHashMatcher;
$this->assertMatcherResult($matcher, "key=true\n\t\r ,\n\t\r key2=false", array('key' => true, 'key2' => false));
}
public function testPairMatcherShouldMatchNumericKey() {
$matcher = new AnnotationPairMatcher;
$this->assertMatcherResult($matcher, '2 = true', array(2 => true));
}
public function testPairMatcherShouldMatchAlsoWhitespace() {
$matcher = new AnnotationPairMatcher;
$this->assertMatcherResult($matcher, 'key = true', array('key' => true));
}
public function testKeyMatcherShouldMatchSimpleKeysOrStrings() {
$matcher = new AnnotationKeyMatcher;
$this->assertNotFalse($matcher->matches('key', $value));
$this->assertNotFalse($matcher->matches('"key"', $value));
$this->assertNotFalse($matcher->matches("'key'", $value));
}
public function testKeyMatcherShouldMatchIntegerKeys() {
$matcher = new AnnotationKeyMatcher;
$this->assertMatcherResult($matcher, '123', 123);
}
public function testStringMatcherShouldMatchDoubleAndSingleQuotedStringsAndHandleEscapes() {
$matcher = new AnnotationStringMatcher;
$this->assertMatcherResult($matcher, '"string string"', 'string string');
$this->assertMatcherResult($matcher, "'string string'", "string string");
}
public function TODO_testStringMatcherShouldMatchEscapedStringsCorrectly() {
$matcher = new AnnotationStringMatcher;
$this->assertMatcherResult($matcher, '"string\"string"', 'string"string');
$this->assertMatcherResult($matcher, "'string\'string'", "string'string");
}
private function assertNotFalse($value) {
$this->assertNotIdentical($value, false);
}
private function assertMatcherResult($matcher, $string, $expected) {
$this->assertNotIdentical($matcher->matches($string, $value), false);
$this->assertIdentical($value, $expected);
}
}
?>
\ No newline at end of file
<?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 ...@@ -13,11 +13,17 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
{ {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->_schemaTool->createSchema(array( try {
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ParentEntity'), $this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ChildEntity'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ParentEntity'),
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\RelatedEntity') $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() public function testCRUD()
...@@ -38,7 +44,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -38,7 +44,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$relatedEntity->setOwner($child); $relatedEntity->setOwner($child);
$this->_em->save($relatedEntity); $this->_em->save($relatedEntity);
$this->_em->flush(); $this->_em->flush();
$this->_em->clear(); $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