Skip to content

Use translation mechanism to replace the form name in the error message #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Use translation mechanism to replace the form name in the error message #2

wants to merge 1 commit into from

Conversation

leabaertschi
Copy link

Use the translation mechanism to replace the form name in the error message instead of sprintf. Like this you can define one single translation in you translations instead of having to have an entry for every single form field.

…essage instead of sprintf. Like this you can define one single translation in you translations instead of having to have an entry for every single form field.
@fabpot
Copy link
Member

fabpot commented Aug 13, 2011

Can you make a PR on symfony/symfony instead. The symfony/Form repository is read-only. Thanks.

@fabpot fabpot closed this Aug 13, 2011
fabpot added a commit that referenced this pull request Nov 25, 2013
Commits
-------

07298ac Detect EOF when reading input stream

Discussion
----------

[Console] Detect EOF when reading input stream

This is related to commits 511a9a1 and 3a5d508.

First of them introduced abort-on-EOF and the second regressed the functionality.
Problem is stream_get_line() doesn't return false on EOF. So it needs call to feof() to
detect the situation.

Still, it's not ideal. With fgets() it worked fine, but with stream_get_line() one has to press
CTRL+D twice to get out. I presume this could be bug in PHP itself.

But better than nothing. Please consider.

---------------------------------------------------------------------------

by fabpot at 2011/07/19 22:47:53 -0700

I have used `stream_get_line` especially because it does not return `false` on eof. This is needed when you pass your own stream for unit tests.

---------------------------------------------------------------------------

by lenar at 2011/07/25 06:05:59 -0700

This is not the best solution I think. Tests should mimic and cope with real life not the other way around.
Better solution would be to fix testcase. Like this: lenar/SensioGeneratorBundle@6ff3f26. Or maybe create a special "testing" stream wrapper that wraps php://memory and gives out just linefeeds after real data ends.

And then change stream_get_line() back to fgets() if there is no other reason for this change.

---------------------------------------------------------------------------

by fabpot at 2011/07/25 06:24:20 -0700

When applying your patch to the generator bundle (and revert to use `fgets`), I get "RuntimeException: Aborted" exceptions.

---------------------------------------------------------------------------

by lenar at 2011/07/25 06:35:08 -0700

With d326f89 added + lenar/SensioGeneratorBundle@6ff3f26 I can successfully run every test in that file.

---------------------------------------------------------------------------

by fabpot at 2011/07/26 23:31:36 -0700

@lenar: not for me. I have many 'Aborted' exception on my Mac.

---------------------------------------------------------------------------

by fabpot at 2011/07/26 23:41:18 -0700

And I have the exact same errors on Linux:

    There were 7 errors:

    1) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateBundleCommandTest::testInteractiveCommand with data set #0 (array('/tmp'), 'Foo/BarBundle
    ', array('Foo\\BarBundle', 'FooBarBundle', '/tmp/', 'annotation', false))
    RuntimeException: Aborted

    .../Symfony/Component/Console/Helper/DialogHelper.php:40
    .../Symfony/Component/Console/Helper/DialogHelper.php:97
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateBundleCommand.php:165
    .../Symfony/Component/Console/Command/Command.php:205
    .../Symfony/Component/Console/Tester/CommandTester.php:66
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateBundleCommandTest.php:39

    2) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateBundleCommandTest::testInteractiveCommand with data set #1 (array('/tmp'), 'Foo/BarBundle
    BarBundle
    foo
    yml
    n', array('Foo\\BarBundle', 'BarBundle', 'foo/', 'yml', false))
    RuntimeException: Aborted

    .../Symfony/Component/Console/Helper/DialogHelper.php:40
    .../Symfony/Component/Console/Helper/DialogHelper.php:62
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateBundleCommand.php:83
    .../Symfony/Component/Console/Command/Command.php:214
    .../Symfony/Component/Console/Tester/CommandTester.php:66
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateBundleCommandTest.php:39

    3) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateBundleCommandTest::testInteractiveCommand with data set #2 (array('/tmp', 'yml', 'BarBundle', true), 'Foo/BarBundle
    ', array('Foo\\BarBundle', 'BarBundle', '/tmp/', 'yml', true))
    RuntimeException: Aborted

    .../Symfony/Component/Console/Helper/DialogHelper.php:40
    .../Symfony/Component/Console/Helper/DialogHelper.php:97
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateBundleCommand.php:165
    .../Symfony/Component/Console/Command/Command.php:205
    .../Symfony/Component/Console/Tester/CommandTester.php:66
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateBundleCommandTest.php:39

    4) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateDoctrineEntityCommandTest::testInteractiveCommand with data set #0 (array(), 'AcmeBlogBundle:Blog/Post
    ', array('Blog\\Post', 'annotation', array()))
    RuntimeException: Aborted

    .../Symfony/Component/Console/Helper/DialogHelper.php:40
    .../Symfony/Component/Console/Helper/DialogHelper.php:97
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineEntityCommand.php:145
    .../Symfony/Component/Console/Command/Command.php:205
    .../Symfony/Component/Console/Tester/CommandTester.php:66
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateDoctrineEntityCommandTest.php:39

    5) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateDoctrineEntityCommandTest::testInteractiveCommand with data set #1 (array('AcmeBlogBundle:Blog/Post'), '', array('Blog\\Post', 'annotation', array()))
    RuntimeException: Aborted

    .../Symfony/Component/Console/Helper/DialogHelper.php:40
    .../Symfony/Component/Console/Helper/DialogHelper.php:97
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineEntityCommand.php:121
    .../Symfony/Component/Console/Command/Command.php:205
    .../Symfony/Component/Console/Tester/CommandTester.php:66
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateDoctrineEntityCommandTest.php:39

    6) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateDoctrineEntityCommandTest::testInteractiveCommand with data set #2 (array(), 'AcmeBlogBundle:Blog/Post
    yml

    ', array('Blog\\Post', 'yml', array()))
    RuntimeException: Aborted

    .../Symfony/Component/Console/Helper/DialogHelper.php:40
    .../Symfony/Component/Console/Helper/DialogHelper.php:62
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineEntityCommand.php:153
    .../Symfony/Component/Console/Command/Command.php:205
    .../Symfony/Component/Console/Tester/CommandTester.php:66
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateDoctrineEntityCommandTest.php:39

    7) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateDoctrineEntityCommandTest::testInteractiveCommand with data set #3 (array(), 'AcmeBlogBundle:Blog/Post
    yml
    title

    255
    description
    text

    ', array('Blog\\Post', 'yml', array(array('title', 'string', 255), array('description', 'text'))))
    RuntimeException: Aborted

    .../Symfony/Component/Console/Helper/DialogHelper.php:40
    .../Symfony/Component/Console/Helper/DialogHelper.php:62
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineEntityCommand.php:153
    .../Symfony/Component/Console/Command/Command.php:205
    .../Symfony/Component/Console/Tester/CommandTester.php:66
    .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateDoctrineEntityCommandTest.php:39

---------------------------------------------------------------------------

by lenar at 2011/07/26 23:56:46 -0700

@fabpot: and you modified all those tests? I only modified ```Tests/Command/GenerateDoctrineCrudCommandTest.php```
and that doesn't fail as I see from your log. I just provided example, though I could add necessary changes for other tests too.

---------------------------------------------------------------------------

by fabpot at 2011/07/27 00:09:32 -0700

@lenar: ah, sorry about that. Then, can you provide a fix for all the other tests too? Thanks a lot.

---------------------------------------------------------------------------

by lenar at 2011/07/27 00:22:54 -0700

@fabpot: actually what do you think about this kind of fix instead for tests: lenar/SensioGeneratorBundle@517f263cb01ea2ea1ef2 instead my previous proposal (lenar/SensioGeneratorBundle@6ff3f26). Really simple, short and effective.

---------------------------------------------------------------------------

by fabpot at 2011/07/27 00:37:51 -0700

@lenar: looks good to me. Can you create a PR?

---------------------------------------------------------------------------

by lenar at 2011/07/27 00:45:36 -0700

@fabpot: sensiolabs/SensioGeneratorBundle#60
nicolas-grekas added a commit that referenced this pull request Nov 27, 2015
…ion on-demand (nicolas-grekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[Bridge\PhpUnit] Display the stack trace of a deprecation on-demand

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This PR has been essential into making #16708, and I think everyone working on a 3.0 migration will need this.

Example:

```
$ SYMFONY_DEPRECATIONS_HELPER=/FormExtensionBootstrap3LayoutTest/ ./phpunit src/Symfony/Bridge/Twig/
PHPUnit 4.8.18 by Sebastian Bergmann and contributors.

Testing src/Symfony/Bridge/Twig/
................................................
Remaining deprecation triggered by Symfony\Bridge\Twig\Tests\Extension\FormExtensionBootstrap3LayoutTest::testSingleChoiceGrouped:
The value "false" for the "choices_as_values" option is deprecated since version 2.8 and will not be supported anymore in 3.0. Set this option to "true" and flip the contents of the "choices" option instead.
Stack trace:
#0 src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php(286): trigger_error()
#1 src/Symfony/Component/OptionsResolver/OptionsResolver.php(962): Symfony\Component\Form\Extension\Core\Type\ChoiceType->Symfony\Component\Form\Extension\Core\Type\{closure}()
#2 src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php(277): Symfony\Component\OptionsResolver\OptionsResolver->offsetGet()
#3 src/Symfony/Component/OptionsResolver/OptionsResolver.php(962): Symfony\Component\Form\Extension\Core\Type\ChoiceType->Symfony\Component\Form\Extension\Core\Type\{closure}()
#4 src/Symfony/Component/OptionsResolver/OptionsResolver.php(791): Symfony\Component\OptionsResolver\OptionsResolver->offsetGet()
#5 src/Symfony/Component/Form/ResolvedFormType.php(156): Symfony\Component\OptionsResolver\OptionsResolver->resolve()
#6 src/Symfony/Component/Form/FormFactory.php(119): Symfony\Component\Form\ResolvedFormType->createBuilder()
#7 src/Symfony/Component/Form/FormFactory.php(48): Symfony\Component\Form\FormFactory->createNamedBuilder()
#8 src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php(540): Symfony\Component\Form\FormFactory->createNamed()
#9 [internal function]: Symfony\Component\Form\Tests\AbstractBootstrap3LayoutTest->testSingleChoiceGrouped()
#10 {main}
KO src/Symfony/Bridge/Twig/
```

Commits
-------

5a88fb6 [Bridge\PhpUnit] Display the stack trace of a deprecation on-demand
nicolas-grekas added a commit that referenced this pull request Nov 28, 2015
…ion on-demand (nicolas-grekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[Bridge\PhpUnit] Display the stack trace of a deprecation on-demand

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This PR has been essential into making #16708, and I think everyone working on a 3.0 migration will need this.

Example:

```
$ SYMFONY_DEPRECATIONS_HELPER=/FormExtensionBootstrap3LayoutTest/ ./phpunit src/Symfony/Bridge/Twig/
PHPUnit 4.8.18 by Sebastian Bergmann and contributors.

Testing src/Symfony/Bridge/Twig/
................................................
Remaining deprecation triggered by Symfony\Bridge\Twig\Tests\Extension\FormExtensionBootstrap3LayoutTest::testSingleChoiceGrouped:
The value "false" for the "choices_as_values" option is deprecated since version 2.8 and will not be supported anymore in 3.0. Set this option to "true" and flip the contents of the "choices" option instead.
Stack trace:
#0 src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php(286): trigger_error()
#1 src/Symfony/Component/OptionsResolver/OptionsResolver.php(962): Symfony\Component\Form\Extension\Core\Type\ChoiceType->Symfony\Component\Form\Extension\Core\Type\{closure}()
#2 src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php(277): Symfony\Component\OptionsResolver\OptionsResolver->offsetGet()
#3 src/Symfony/Component/OptionsResolver/OptionsResolver.php(962): Symfony\Component\Form\Extension\Core\Type\ChoiceType->Symfony\Component\Form\Extension\Core\Type\{closure}()
#4 src/Symfony/Component/OptionsResolver/OptionsResolver.php(791): Symfony\Component\OptionsResolver\OptionsResolver->offsetGet()
#5 src/Symfony/Component/Form/ResolvedFormType.php(156): Symfony\Component\OptionsResolver\OptionsResolver->resolve()
#6 src/Symfony/Component/Form/FormFactory.php(119): Symfony\Component\Form\ResolvedFormType->createBuilder()
#7 src/Symfony/Component/Form/FormFactory.php(48): Symfony\Component\Form\FormFactory->createNamedBuilder()
#8 src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php(540): Symfony\Component\Form\FormFactory->createNamed()
#9 [internal function]: Symfony\Component\Form\Tests\AbstractBootstrap3LayoutTest->testSingleChoiceGrouped()
#10 {main}
KO src/Symfony/Bridge/Twig/
```

Commits
-------

5a88fb6 [Bridge\PhpUnit] Display the stack trace of a deprecation on-demand
symfony-splitter pushed a commit that referenced this pull request Sep 4, 2018
This PR was merged into the 4.2-dev branch.

Discussion
----------

Mark ExceptionInterfaces throwable #2

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This has been reverted in beta of 4.1 because of lack of support in prophecy, which has been fixed since then (incl. release). Can be merged again.

References:
symfony/symfony#26702
symfony/symfony#27420
symfony/symfony#27419
phpspec/prophecy#412

ping @dunglas @ciaranmcnulty @dkarlovi @Wirone @teohhanhui @stof @nicolas-grekas @ondrejmirtes

Commits
-------

17c3675226 Mark ExceptionInterfaces throwable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants