8000 bug #28913 Fix debug:container which crash when the service class has… · symfony/symfony@efa4f16 · GitHub
[go: up one dir, main page]

Skip to content

Commit efa4f16

Browse files
committed
bug #28913 Fix debug:container which crash when the service class has no doc comment (l-vo)
This PR was merged into the 4.2-dev branch. Discussion ---------- Fix debug:container which crash when the service class has no doc comment | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | The console command container:debug have now the ability to display service description, based on phpdoc comments of the service class. But the command currently crash when selecting a service with a class without phpdoc description. This PR fixes this issue. Commits ------- aed0a5a [FrameworkBundle] Fix debug:container which crash when the service class has no doc comment
2 parents c620a3b + aed0a5a commit efa4f16

File tree

11 files changed

+119
-3
lines changed

11 files changed

+119
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,11 @@ protected function getClassDescription($class)
303303
try {
304304
$reflectionProperty = new \ReflectionClass($class);
305305

306-
return DocBlockFactory::createInstance()
307-
->create($reflectionProperty->getDocComment())
308-
->getSummary();
306+
if ($docComment = $reflectionProperty->getDocComment()) {
307+
return DocBlockFactory::createInstance()
308+
->create($docComment)
309+
->getSummary();
310+
}
309311
} catch (\ReflectionException $e) {
310312
}
311313

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ public function getDescribeContainerBuilderTestData()
6969
return $this->getContainerBuilderDescriptionTestData(ObjectsProvider::getContainerBuilders());
7070
}
7171

72+
/**
73+
* @dataProvider getDescribeContainerExistingClassDefinitionTestData
74+
*/
75+
public function testDescribeContainerExistingClassDefinition(Definition $definition, $expectedDescription)
76+
{
77+
$this->assertDescription($expectedDescription, $definition);
78+
}
79+
80+
public function getDescribeContainerExistingClassDefinitionTestData()
81+
{
82+
return $this->getDescriptionTestData(ObjectsProvider::getContainerDefinitionsWithExistingClasses());
83+
}
84+
7285
/** @dataProvider getDescribeContainerDefinitionTestData */
7386
public function testDescribeContainerDefinition(Definition $definition, $expectedDescription)
7487
{

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ public static function getContainerBuilders()
9696
return array('builder_1' => $builder1);
9797
}
9898

99+
public static function getContainerDefinitionsWithExistingClasses()
100+
{
101+
return array(
102+
'existing_class_def_1' => new Definition(ClassWithDocComment::class),
103+
'existing_class_def_2' => new Definition(ClassWithoutDocComment::class),
104+
);
105+
}
106+
99107
public static function getContainerDefinitions()
100108
{
101109
$definition1 = new Definition('Full\\Qualified\\Class1');
@@ -196,3 +204,14 @@ public function compile()
196204
return new CompiledRoute('', '#PATH_REGEX#', array(), array(), '#HOST_REGEX#');
197205
}
198206
}
207+
208+
class ClassWithoutDocComment
209+
{
210+
}
211+
212+
/**
213+
* This is a class with a doc comment.
214+
*/
215+
class ClassWithDocComment
216+
{
217+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"class": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\ClassWithDocComment",
3+
"public": false,
4+
"synthetic": false,
5+
"lazy": false,
6+
"shared": true,
7+
"abstract": false,
8+
"autowire": false,
9+
"autoconfigure": false,
10+
"description": "This is a class with a doc comment.",
11+
"file": null,
12+
"tags": []
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- Description: `This is a class with a doc comment.`
2+
- Class: `Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\ClassWithDocComment`
3+
- Public: no
4+
- Synthetic: no
5+
- Lazy: no
6+
- Shared: yes
7+
- Abstract: no
8+
- Autowired: no
9+
- Autoconfigured: no
10+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This is a class with a doc comment.
2+
3+
---------------- -----------------------------------------------------------------------------
4+
 Option   Value 
5+
---------------- -----------------------------------------------------------------------------
6+
Service ID -
7+
Class Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\ClassWithDocComment
8+
Tags -
9+
Public no
10+
Synthetic no
11+
Lazy no
12+
Shared yes
13+
Abstract no
14+
Autowired no
15+
Autoconfigured no
16+
---------------- -----------------------------------------------------------------------------
17+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definition class="Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\ClassWithDocComment" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file="">
3+
<description><![CDATA[This is a class with a doc comment.]]></description>
4+
</definition>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"class": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\ClassWithoutDocComment",
3+
"public": false,
4+
"synthetic": false,
5+
"lazy": false,
6+
"shared": true,
7+
"abstract": false,
8+
"autowire": false,
9+
"autoconfigure": false,
10+
"file": null,
11+
"tags": []
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- Class: `Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\ClassWithoutDocComment`
2+
- Public: no
3+
- Synthetic: no
4+
- Lazy: no
5+
- Shared: yes
6+
- Abstract: no
7+
- Autowired: no
8+
- Autoconfigured: no
9+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---------------- --------------------------------------------------------------------------------
2+
 Option   Value 
3+
---------------- --------------------------------------------------------------------------------
4+
Service ID -
5+
Class Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\ClassWithoutDocComment
6+
Tags -
7+
Public no
8+
Synthetic no
9+
Lazy no
10+
Shared yes
11+
Abstract no
12+
Autowired no
13+
Autoconfigured no
14+
---------------- --------------------------------------------------------------------------------
15+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definition class="Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\ClassWithoutDocComment" public="false" synthetic="false" lazy="false" shared="true" abstract="false" autowired="false" autoconfigured="false" file=""/>

0 commit comments

Comments
 (0)
0