Skip to content

Commit

Permalink
[2.0] Cleanups, build fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
romanb committed Jun 15, 2009
1 parent e21d8ff commit f281276
Show file tree
Hide file tree
Showing 30 changed files with 251 additions and 307 deletions.
26 changes: 20 additions & 6 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,40 @@
</copy>
</target>

<target name="test">
<mkdir dir="${build.dir}/logs"/>
<mkdir dir="reports/tests"/>
<phpunit printsummary="true" haltonfailure="true">
<formatter todir="${build.dir}/logs" type="xml"/>
<batchtest classpath="tests">
<fileset dir="tests">
<include name="**/*Test.php"/>
</fileset>
</batchtest>
</phpunit>
<!-- <phpunitreport infile="build/logs/testsuites.xml" format="frames" todir="reports/tests" />-->
</target>

<target name="dist-common">
<tar destfile="./dist/Doctrine2-common.tar.gz" compression="gzip">
<fileset dir="./build/common">
<fileset dir="${build.dir}/common">
<include name="**" />
</fileset>
</tar>
</target>

<target name="dist-dbal">
<tar destfile="./dist/Doctrine2-dbal.tar.gz" compression="gzip">
<fileset dir="./build/dbal">
<tar destfile="${dist.dir}/Doctrine2-dbal.tar.gz" compression="gzip">
<fileset dir="${build.dir}/dbal">
<include name="**" />
</fileset>
</tar>
</target>

<target name="dist-all" depends="build-all, dist-common, dist-dbal">
<target name="dist-all" depends="test, build-all, dist-common, dist-dbal">

<tar destfile="./dist/Doctrine2-all.tar.gz" compression="gzip">
<fileset dir="./build/all">
<tar destfile="${dist.dir}/Doctrine2-all.tar.gz" compression="gzip">
<fileset dir="${build.dir}/all">
<include name="**" />
</fileset>
</tar>
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SqlWalker implements TreeWalker
private $_aliasCounter = 0;
/** Counter for generating unique table aliases. */
private $_tableAliasCounter = 0;
private $_scalarResultCounter = 0;
private $_scalarResultCounter = 1;
/** Counter for SQL parameter positions. */
private $_sqlParamIndex = 1;
/** The ParserResult. */
Expand Down
17 changes: 12 additions & 5 deletions lib/vendor/addendum/annotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,30 @@

class Annotation {
public $value;
private static $creationStack = array();

public final function __construct($data, $target) {
$reflection = new ReflectionClass($this);
$class = $reflection->getName();
if(isset(self::$creationStack[$class])) {
trigger_error("Circular annotation reference on '$class'", E_USER_ERROR);
return;
}
self::$creationStack[$class] = true;
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);
unset(self::$creationStack[$class]);
}

private function checkTargetConstraints($target) {
$reflection = new ReflectionAnnotatedClass($this);
/*$reflection = new ReflectionAnnotatedClass($this);
if($reflection->hasAnnotation('Target')) {
$value = $reflection->getAnnotation('Target')->value;
$values = is_array($value) ? $value : array($value);
Expand All @@ -50,7 +57,7 @@ private function checkTargetConstraints($target) {
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) {
Expand All @@ -66,7 +73,7 @@ private function createName($target) {
protected function checkConstraints($target) {}
}

class Target extends Annotation {}
//class Target extends Annotation {}

class AnnotationsBuilder {
private static $cache = array();
Expand All @@ -75,7 +82,7 @@ public function build($targetReflection) {
$data = $this->parse($targetReflection);
$annotations = array();
foreach($data as $class => $parameters) {
if(!Addendum::ignores($class)) {
if(is_subclass_of($class, 'Annotation') && !Addendum::ignores($class)) {
foreach($parameters as $params) {
$annotationReflection = new ReflectionClass($class);
$annotations[$class][] = $annotationReflection->newInstance($params, $targetReflection);
Expand Down
17 changes: 17 additions & 0 deletions lib/vendor/addendum/annotations/annotation_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ protected function build() {
$this->add(new AnnotationStringMatcher);
$this->add(new AnnotationNumberMatcher);
$this->add(new AnnotationArrayMatcher);
$this->add(new AnnotationStaticConstantMatcher);
}
}

Expand Down Expand Up @@ -332,4 +333,20 @@ protected function process($matches) {
return $matches[1];
}
}

class AnnotationStaticConstantMatcher extends RegexMatcher {
public function __construct() {
parent::__construct('(\w+::\w+)');
}

protected function process($matches) {
$name = $matches[1];
if(!defined($name)) {
trigger_error("Constant '$name' used in annotation was not defined.");
return false;
}
return constant($name);
}

}
?>
56 changes: 56 additions & 0 deletions lib/vendor/addendum/annotations/tests/acceptance_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ public function aMethod() {}

class FirstAnnotation extends Annotation {}
class SecondAnnotation extends Annotation {}

class NoAnnotation {}

/** @NoAnnotation @FirstAnnotation */
class ExampleWithInvalidAnnotation {}

/** @SelfReferencingAnnotation */
class SelfReferencingAnnotation extends Annotation {}

/** @IndirectReferenceLoopAnnotationHelper */
class IndirectReferenceLoopAnnotation extends Annotation {}

/** @IndirectReferenceLoopAnnotation */
class IndirectReferenceLoopAnnotationHelper extends Annotation {}


class Statics {
const A_CONSTANT = 'constant';
static public $static = 'static';
}

/** @FirstAnnotation(Statics::A_CONSTANT) */
class ClassAnnotatedWithStaticConstant {}

/** @FirstAnnotation(Statics::UNKNOWN_CONSTANT) */
class ClassAnnotatedWithNonExistingConstant {}

class TestOfAnnotations extends UnitTestCase {
public function testReflectionAnnotatedClass() {
Expand Down Expand Up @@ -192,6 +218,36 @@ public function testMultipleAnnotationsOnMethodWithRestriction() {
$this->assertIsA($annotations[0], 'FirstAnnotation');
$this->assertIsA($annotations[1], 'FirstAnnotation');
}

public function testClassWithNoAnnotationParentShouldNotBeParsed() {
$reflection = new ReflectionAnnotatedClass('ExampleWithInvalidAnnotation');
$annotations = $reflection = $reflection->getAnnotations();
$this->assertEqual(count($annotations), 1);
$this->assertIsA($annotations[0], 'FirstAnnotation');
}

public function testCircularReferenceShouldThrowError() {
$this->expectError("Circular annotation reference on 'SelfReferencingAnnotation'");
$reflection = new ReflectionAnnotatedClass('SelfReferencingAnnotation');
$reflection->getAnnotations();

$this->expectError("Circular annotation reference on 'IndirectReferenceLoopAnnotationHelper'");
$reflection = new ReflectionAnnotatedClass('IndirectReferenceLoopAnnotation');
$reflection->getAnnotations();
}

public function testConstInAnnotationShouldReturnCorrectValue() {
$reflection = new ReflectionAnnotatedClass('ClassAnnotatedWithStaticConstant');
$annotation = $reflection->getAnnotation('FirstAnnotation');
$this->assertEqual($annotation->value, Statics::A_CONSTANT);
}

public function testBadConstInAnnotationShouldCauseError() {
$this->expectError("Constant 'Statics::UNKNOWN_CONSTANT' used in annotation was not defined.");
$reflection = new ReflectionAnnotatedClass('ClassAnnotatedWithNonExistingConstant');
$annotation = $reflection->getAnnotation('FirstAnnotation');
}

}

Mock::generatePartial('AnnotationsBuilder', 'MockedAnnotationsBuilder', array('getDocComment'));
Expand Down
33 changes: 14 additions & 19 deletions lib/vendor/addendum/annotations/tests/all_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,21 @@
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');

}
}

$suite = new TestSuite('All tests');
$suite->add(new TestOfAnnotations);
$suite->add(new TestOfPerformanceFeatures);
$suite->add(new TestOfSupportingFeatures);
$suite->add(new TestOfAnnotation);
$suite->add(new TestOfConstrainedAnnotation);
$suite->add(new TestOfMatchers);
$suite->add(new TestOfAnnotationMatchers);
$suite->add(new TestOfDocComment);

$reporter = TextReporter::inCli() ? new TextReporter() : new HtmlReporter();

Addendum::setRawMode(false);
$test = new AllTests('All tests in reflection mode');
$test->run(new HtmlReporter());
$suite->run($reporter);

Addendum::setRawMode(true);
$test = new AllTests('All tests in raw mode');
$test->run(new HtmlReporter());
$suite->run($reporter);
?>
24 changes: 23 additions & 1 deletion lib/vendor/addendum/annotations/tests/annotation_parser_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public function testSimpleSerialMatcherShouldReturnRequestedPartOnMatch() {
$this->assertEqual($value, '1234');
}
}

class StaticClass {
const A_CONSTANT = 'constant';
}


class TestOfAnnotationMatchers extends UnitTestCase {
public function testAnnotationsMatcherShouldMatchAnnotationWithGarbage() {
Expand Down Expand Up @@ -185,6 +190,11 @@ public function testValueMatcherShouldMatchArray() {
$matcher = new AnnotationValueMatcher;
$this->assertMatcherResult($matcher, '{1}', array(1));
}

public function testValueMatcherShouldMatchStaticConstant() {
$matcher = new AnnotationValueMatcher;
$this->assertMatcherResult($matcher, 'StaticClass::A_CONSTANT', StaticClass::A_CONSTANT);
}

public function testArrayMatcherShouldMatchEmptyArray() {
$matcher = new AnnotationArrayMatcher;
Expand Down Expand Up @@ -299,6 +309,18 @@ public function TODO_testStringMatcherShouldMatchEscapedStringsCorrectly() {
$this->assertMatcherResult($matcher, '"string\"string"', 'string"string');
$this->assertMatcherResult($matcher, "'string\'string'", "string'string");
}

public function testStaticConstantMatcherShouldMatchConstants() {
$matcher = new AnnotationStaticConstantMatcher;
$this->assertMatcherResult($matcher, 'StaticClass::A_CONSTANT', StaticClass::A_CONSTANT);
}

public function testStaticConstantMatcherShouldThrowErrorOnBadConstant() {
$this->expectError("Constant 'StaticClass::NO_CONSTANT' used in annotation was not defined.");
$matcher = new AnnotationStaticConstantMatcher;
$matcher->matches('StaticClass::NO_CONSTANT', $value);
}


private function assertNotFalse($value) {
$this->assertNotIdentical($value, false);
Expand All @@ -309,4 +331,4 @@ private function assertMatcherResult($matcher, $string, $expected) {
$this->assertIdentical($value, $expected);
}
}
?>
?>
4 changes: 2 additions & 2 deletions lib/vendor/addendum/annotations/tests/annotation_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public function testConstructorsFillsParameters() {
}

public function testConstructorThrowsErrorOnInvalidParameter() {
$this->expectError("Property 'unknown' not defined for annotation 'TestingAnnotation'");
$annotation = new TestingAnnotation(array('unknown' => 1), $this);
$this->assertError("Property 'unknown' not defined for annotation 'TestingAnnotation'");
}

public function TODO_testConstructorThrowsErrorWithoutSpecifingRequiredParameters() {
$this->expectError("Property 'required' in annotation 'TestingAnnotation' is required");
$annotation = new TestingAnnotation();
$this->assertError("Property 'required' in annotation 'TestingAnnotation' is required");
}
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function testSingleTargetAnnotationThrowsNoErrorWhenOnRightPlace() {
$reflection = new ReflectionAnnotatedClass('SuccesfullyAnnotatedClass');
$method = $reflection->getMethod('method');
$property = $reflection->getProperty('property');
$this->assertNoErrors();
}

public function testMultiTargetAnnotationThrowsErrorWhenOnWrongPlace() {
Expand All @@ -67,7 +66,6 @@ public function testMultiTargetAnnotationThrowsErrorWhenOnWrongPlace() {
public function testMultiTargetAnnotationThrowsNoErrorWhenOnRightPlace() {
$reflection = new ReflectionAnnotatedClass('SuccesfullyAnnotatedClass');
$method = $reflection->getProperty('property2');
$this->assertNoErrors();
}
}
?>
?>
2 changes: 2 additions & 0 deletions tests/Doctrine/Tests/Common/ClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Doctrine\Common\ClassLoader;

require_once __DIR__ . '/../TestInit.php';

class ClassLoaderTest extends \Doctrine\Tests\DoctrineTestCase
{
public function testCustomFileExtensionAndNamespaceSeparator()
Expand Down
2 changes: 2 additions & 0 deletions tests/Doctrine/Tests/Common/DoctrineExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Doctrine\Tests\Common;

require_once __DIR__ . '/../TestInit.php';

class DoctrineExceptionTest extends \Doctrine\Tests\DoctrineTestCase
{
public function testStaticCall()
Expand Down
2 changes: 2 additions & 0 deletions tests/Doctrine/Tests/Common/EventManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Doctrine\Common\EventManager;
use Doctrine\Common\EventArgs;

require_once __DIR__ . '/../TestInit.php';

class EventManagerTest extends \Doctrine\Tests\DoctrineTestCase
{
/* Some pseudo events */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

require_once __DIR__ . '/../../../TestInit.php';

class MySqlSchemaManagerTest extends SchemaManagerFunctionalTest
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
public function testListDatabases()
{
Expand All @@ -15,14 +15,20 @@ public function testListDatabases()
$this->assertEquals(true, in_array('test_create_database', $databases));
}

/**
* @expectedException \Exception
*/
public function testListFunctions()
{
return $this->assertUnsupportedMethod('listFunctions');
$this->_sm->listFunctions();
}

/**
* @expectedException \Exception
*/
public function testListTriggers()
{
return $this->assertUnsupportedMethod('listTriggers');
$this->_sm->listTriggers();
}

public function testListSequences()
Expand Down
Loading

0 comments on commit f281276

Please sign in to comment.