Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Avoid a critical error when parsed class is not found #197

Merged
merged 3 commits into from

6 participants

@alphalemon

Found a bug that returns a critical error when parsed class is not found. The new test explains exactly the situation found.

This issue was found running this test suite: https://github.com/alphalemon/AlphaLemonCmsBundle, running the following test; phpunit Tests/Functional/Controller/SecuryControllerTest.php

@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DCOM-120

lib/Doctrine/Common/Annotations/PhpParser.php
@@ -64,6 +68,8 @@ public function parseClass(\ReflectionClass $class)
*/
private function getFileContent($filename, $lineNumber)
{
+ if (!file_exists($filename)) return null;
@stof Collaborator
stof added a note

Please fix the coding standards. You should always use curly braces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@alphalemon

Ok, did it! :)

@guilhermeblanco guilhermeblanco commented on the diff
lib/Doctrine/Common/Annotations/PhpParser.php
@@ -46,6 +46,10 @@ public function parseClass(\ReflectionClass $class)
}
$content = $this->getFileContent($filename, $class->getStartLine());
@guilhermeblanco Owner

Missing line break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/Common/Annotations/PhpParser.php
@@ -64,6 +68,10 @@ public function parseClass(\ReflectionClass $class)
*/
private function getFileContent($filename, $lineNumber)
{
+ if (!file_exists($filename)) {
@guilhermeblanco Owner

Missing spaces around !.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@alphalemon

Hi,
is now good to merge?

@schmittjoh schmittjoh merged commit 150cb23 into doctrine:master

1 check passed

Details default The Travis build passed
@schmittjoh
Collaborator

Yes, thanks :)

@alphalemon

Thank you guys! :)

@alphalemon alphalemon referenced this pull request in alphalemon/AlphaLemonCmsBundle
Closed

doctrine/common "dev-bugfix as 2.3.0" doesn't work for me #26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
9 lib/Doctrine/Common/Annotations/PhpParser.php
@@ -46,6 +46,11 @@ public function parseClass(\ReflectionClass $class)
}
$content = $this->getFileContent($filename, $class->getStartLine());
@guilhermeblanco Owner

Missing line break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ if (null === $content) {
+ return array();
+ }
+
$namespace = str_replace('\\', '\\\\', $class->getNamespaceName());
$content = preg_replace('/^.*?(\bnamespace\s+' . $namespace . '\s*[;{].*)$/s', '\\1', $content);
$tokenizer = new TokenParser('<?php ' . $content);
@@ -64,6 +69,10 @@ public function parseClass(\ReflectionClass $class)
*/
private function getFileContent($filename, $lineNumber)
{
+ if ( ! file_exists($filename)) {
+ return null;
+ }
+
$content = '';
$lineCnt = 0;
$file = new SplFileObject($filename);
View
13 tests/Doctrine/Tests/Common/Annotations/PhpParserTest.php
@@ -39,6 +39,19 @@ public function testParseClassWhenNotUserDefined()
$this->assertEquals(array(), $parser->parseClass(new \ReflectionClass('\stdClass')));
}
+ public function testClassFileDoesNotExist()
+ {
+ $class = $this->getMockBuilder('\ReflectionClass')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $class->expects($this->once())
+ ->method('getFilename')
+ ->will($this->returnValue('/valid/class/Fake.php(35) : eval()d code'));
+
+ $parser = new PhpParser();
+ $this->assertEquals(array(), $parser->parseClass($class));
+ }
+
public function testParseClassWhenClassIsNotNamespaced()
{
$parser = new PhpParser();
Something went wrong with that request. Please try again.