Skip to content

Commit 1dd419e

Browse files
committed
fix Windows slashes
1 parent b331ee2 commit 1dd419e

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

src/Symfony/Component/Translation/Tests/Extractor/PhpAstExtractorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testExtractFiles(iterable|string $resource)
3131
$extractor->extract($resource, $catalogue);
3232

3333
$this->assertEquals(['messages' => ['example' => 'example']], $catalogue->all());
34-
$this->assertEquals(['sources' => [self::FIXTURES_FOLDER.'translation.html.php:1']], $catalogue->getMetadata('example'));
34+
$this->assertEquals(['sources' => [preg_replace('{[\\\\/]+}', '/', self::FIXTURES_FOLDER).'translation.html.php:1']], $catalogue->getMetadata('example'));
3535
}
3636

3737
public static function resourcesProvider(): \Generator
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
// @see https://github.com/php-translation/extractor/blob/master/tests/Resources/Php/Symfony/ExplicitLabelType.php
3+
4+
use Symfony\Component\Form\AbstractType;
5+
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
6+
use Symfony\Component\Form\FormBuilderInterface;
7+
8+
// Intentionally not included in FormTypeVisitor constructor argument in PhpAstExtractorTest.php
9+
// To test that the visitor can find FormType extending AbstractType.
10+
class FooType extends AbstractType
11+
{
12+
public function buildForm(FormBuilderInterface $builder, array $options)
13+
{
14+
$builder->add('foo1', null, [
15+
'label' => 'label.foo1'
16+
]);
17+
}
18+
}
19+
20+
class ExplicitLabelType extends AbstractType
21+
{
22+
public function buildForm(FormBuilderInterface $builder, array $options)
23+
{
24+
$var = "something";
25+
$builder->add('find1', null, [
26+
'label' => 'label.find1'
27+
]);
28+
$builder
29+
->add('find2', null, array(
30+
'label' => 'find2'
31+
))
32+
->add('field_longer_name3', null, [
33+
'label' => 'FOUND3'
34+
])
35+
->add('skip1', null, [
36+
'label' => $var, // shouldn't be picked up
37+
'somethingelse' => 'skipthis',
38+
])
39+
->add('skip2', null, [
40+
'label' => PHP_OS, // constant shouldn't work
41+
])
42+
->add('skip3', null, [
43+
'label' // value label, shouldn't be picked up
44+
])
45+
->add('skip4', null, [
46+
'label' => 'something '.$var // string+var concatenation, shouldn't be picked up
47+
])
48+
;
49+
50+
// add label in variable should be found
51+
$opts = ['label'=>'label.find4'];
52+
$builder->add('find4', null, $opts);
53+
54+
// empty label should be skipped
55+
$builder->add('skip5', null, ['label'=>'']);
56+
57+
// collection test
58+
$builder->add('find5', CollectionType::class, [
59+
'options' => [
60+
'label' => 'label.find5',
61+
],
62+
]);
63+
64+
// implicit labels should be found
65+
$builder->add('find6');
66+
$builder->add('bigger_find7');
67+
$builder->add('camelFind8');
68+
$builder->add('skip6'.$var);
69+
$builder->add('skip7', null, ['label'=>'label.find9']);
70+
}
71+
}

0 commit comments

Comments
 (0)