Skip to content

Commit

Permalink
DCOM-11 Testcase and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
merk committed Jul 15, 2010
1 parent 3b42776 commit 95388a5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
5 changes: 1 addition & 4 deletions lib/Doctrine/Common/Annotations/Parser.php
Expand Up @@ -275,10 +275,7 @@ public function Annotation()

// Is it really an annotation?
// If the lookahead is "(" it surely is, otherwise class_exists decides.
if (
($this->lexer->lookahead == null || ! $this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) &&
! class_exists($name, $this->autoloadAnnotations)
) {
if (! class_exists($name, $this->autoloadAnnotations)) {
$this->lexer->skipUntil(Lexer::T_AT);
return false;
}
Expand Down
50 changes: 34 additions & 16 deletions tests/Doctrine/Tests/Common/Annotations/ParserTest.php
Expand Up @@ -11,16 +11,16 @@ class ParserTest extends \Doctrine\Tests\DoctrineTestCase
public function testBasicAnnotations()
{
$parser = $this->createTestParser();

$this->assertFalse($parser->getAutoloadAnnotations());

// Marker annotation
$result = $parser->parse("@Name");
$annot = $result['Doctrine\Tests\Common\Annotations\Name'];
$this->assertTrue($annot instanceof Name);
$this->assertNull($annot->value);
$this->assertNull($annot->foo);

// Associative arrays
$result = $parser->parse('@Name(foo={"key1" = "value1"})');
$annot = $result['Doctrine\Tests\Common\Annotations\Name'];
Expand All @@ -37,7 +37,7 @@ public function testBasicAnnotations()
$this->assertFalse(isset($annot->value[0]));
$this->assertFalse(isset($annot->value[1]));
$this->assertFalse(isset($annot->value[3]));

// Nested arrays with nested annotations
$result = $parser->parse('@Name(foo={1,2, {"key"=@Name}})');
$annot = $result['Doctrine\Tests\Common\Annotations\Name'];
Expand All @@ -48,16 +48,16 @@ public function testBasicAnnotations()
$this->assertEquals(1, $annot->foo[0]);
$this->assertEquals(2, $annot->foo[1]);
$this->assertTrue(is_array($annot->foo[2]));

$nestedArray = $annot->foo[2];
$this->assertTrue(isset($nestedArray['key']));
$this->assertTrue($nestedArray['key'] instanceof Name);

// Complete docblock
$docblock = <<<DOCBLOCK
/**
* Some nifty class.
*
*
* @author Mr.X
* @Name(foo="bar")
*/
Expand All @@ -70,15 +70,15 @@ public function testBasicAnnotations()
$this->assertEquals("bar", $annot->foo);
$this->assertNull($annot->value);
}

public function testNamespacedAnnotations()
{
$parser = new Parser;

$docblock = <<<DOCBLOCK
/**
* Some nifty class.
*
*
* @package foo
* @subpackage bar
* @author Mr.X <mr@x.com>
Expand Down Expand Up @@ -159,6 +159,24 @@ public function testRegressionDDC575()
$this->assertArrayHasKey("Doctrine\Tests\Common\Annotations\Name", $result);
}

public function testNestedNonexistantAnnotations()
{
$parser = $this->createTestParser();

$docblock = <<<DOCBLOCK
/**
* @Name
* @NonExistant(
* @InnerNonexistant(32)
* )
*/
DOCBLOCK;

$result = $parser->parse($docblock);
$this->assertEquals(1, count($result));
$this->assertArrayHasKey('Doctrine\Tests\Common\Annotations\Name', $result);
}

public function testNamespaceAliasedAnnotations()
{
$parser = new Parser;
Expand Down Expand Up @@ -207,7 +225,7 @@ public function testAnnotationDontAcceptSingleQuotes()
$parser = $this->createTestParser();
$parser->parse("@Name(foo='bar')");
}

/**
* @group parse
*/
Expand All @@ -218,12 +236,12 @@ public function testAnnotationNamespaceAlias()
$docblock = <<<DOCBLOCK
/**
* Some nifty class.
*
*
* @author Mr.X
* @alias:Name(foo="stuff")
*/
DOCBLOCK;

$result = $parser->parse($docblock);
$this->assertEquals(1, count($result));
$annot = $result['Doctrine\Tests\Common\Annotations\Name'];
Expand Down Expand Up @@ -252,7 +270,7 @@ public function testSyntaxErrorWithContextDescription()
$parser = $this->createTestParser();
$parser->parse("@Name(foo='bar')", "class \Doctrine\Tests\Common\Annotations\Name");
}

/**
* @group DDC-183
*/
Expand All @@ -265,11 +283,11 @@ public function testSyntaxErrorWithUnknownCharacters()
class A {
}
DOCBLOCK;

//$lexer = new \Doctrine\Common\Annotations\Lexer();
//$lexer->setInput(trim($docblock, '/ *'));
//var_dump($lexer);

try {
$parser = $this->createTestParser();
$result = $parser->parse($docblock);
Expand Down

0 comments on commit 95388a5

Please sign in to comment.