Skip to content

Commit ca84274

Browse files
authored
Added test for issue 68 (#69)
* Added test for issue 68 * Check for no errors * Allow to ignore "false" * style fix
1 parent f05f71c commit ca84274

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/Visitor/Php/Symfony/FormTypeLabelExplicit.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public function enterNode(Node $node)
4848
continue;
4949
}
5050

51+
if ($item->value instanceof Node\Expr\ConstFetch) {
52+
// This might be boolean "false"
53+
if ('false' === $item->value->name->toString()) {
54+
continue;
55+
}
56+
}
57+
5158
if (!$item->value instanceof Node\Scalar\String_) {
5259
$this->addError($item, 'Form label is not a scalar string');
5360

tests/Functional/Visitor/Php/Symfony/FormTypeLabelExplicitTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,11 @@ public function testWillNotExtractTypeless()
4040
$collection = $this->getSourceLocations(new FormTypeLabelExplicit(), Resources\Php\Symfony\ExplicitLabelTypeless::class);
4141
$this->assertCount(0, $collection);
4242
}
43+
44+
public function testWithLabelFalse()
45+
{
46+
$collection = $this->getSourceLocations(new FormTypeLabelExplicit(), Resources\Php\Symfony\ExplicitLabelFalseType::class);
47+
$this->assertEmpty($collection);
48+
$this->assertEmpty($collection->getErrors(), 'Using label=>false should not render an error');
49+
}
4350
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
use Symfony\Component\Form\AbstractType;
4+
use Translation\Extractor\Annotation\Ignore;
5+
6+
class ExplicitLabelFalseType extends AbstractType
7+
{
8+
public function buildForm(FormBuilderInterface $builder, array $options)
9+
{
10+
$builder
11+
->add('trans.issue_68', null, array(
12+
'label' => false
13+
));
14+
}
15+
}

0 commit comments

Comments
 (0)