Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

BC break - Trying to configure method "getDefinitions" which cannot be configured #299

Closed
nicolas-grekas opened this issue Mar 23, 2016 · 22 comments
Labels

Comments

@nicolas-grekas
Copy link
Contributor

The symfony test suite does not work with ec7832e

with a phpunit that has been checked out and composer-installed from source
e.g. phpunit src/Symfony/Component/HttpKernel/ displays:

PHPUnit 5.1.7 by Sebastian Bergmann and contributors.
[...]
1) Symfony\Component\HttpKernel\Tests\DependencyInjection\MergeExtensionConfigurationPassTest::testAutoloadMainExtension
PHPUnit_Framework_MockObject_RuntimeException: Trying to configure method "getDefinitions" which cannot be configured
@sebastianbergmann
Copy link
Owner

Please provide a minimal, self-contained, reproducing test case.

@stof
Copy link

stof commented Mar 23, 2016

I think this might be related to the fact that we call getMock() with just an interface name, without passing a list of methods. Is it now forbidden ?

See https://github.com/symfony/symfony/blob/v2.3.39/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php for such a failing test:

PHPUnit_Framework_MockObject_RuntimeException: Trying to configure method "getClassMetaData" which cannot be configured

/home/travis/build/symfony/symfony/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php:90

/home/travis/build/symfony/symfony/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php:26

@sebastianbergmann
Copy link
Owner

@stof I do not have time to look at "real world" tests. Please provide a minimal, self-contained, reproducing test case. I need something that I can copy/paste from this issue into a file for running and debugging.

The changes made in ec7832e are not supposed to disallow anything that used to work before. They were made to provide useful error messages when trying to configure methods that cannot be configured (see #296).

@sebastianbergmann
Copy link
Owner

As a hotfix, I have tagged b90749d as 3.1.1.

@nicolas-grekas
Copy link
Contributor Author

@sebastianbergmann thanks

@sebastianbergmann
Copy link
Owner

@stof While I am waiting for a minimal, self-contained, reproducing test case, I have briefly looked at https://github.com/symfony/symfony/blob/v2.3.39/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php.

When I put var_dump(class_exists('Doctrine\Common\Persistence\ObjectManager')); just before https://github.com/symfony/symfony/blob/v2.3.39/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php#L89 then I get false.

That means that Doctrine\Common\Persistence\ObjectManager is not known at this point in time. PHPUnit will therefore create an empty class named Doctrine\Common\Persistence\ObjectManager that has no methods.

nicolas-grekas added a commit to symfony/symfony that referenced this issue Mar 23, 2016
This PR was merged into the 2.3 branch.

Discussion
----------

[ci] Tweak scripts

| Q             | A
| ------------- | ---
| Branch?       | 2.3
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | sebastianbergmann/phpunit-mock-objects#299
| License       | MIT
| Doc PR        | -

Commits
-------

82c6bed [ci] Tweak scripts
@sebastianbergmann
Copy link
Owner

Just to be clear: the behavior described in #299 (comment) is expected.

I do not know why the Doctrine\Common\Persistence\ObjectManager is not found. The changes made in ec7832e make this fact obvious now where the error was silently ignored before.

@stof
Copy link

stof commented Mar 23, 2016

this looks weird. doctrine/orm is a dev dependency of Symfony and it itself depends on doctrine/common (the ORM provides an implementation). So doctrine/common should be available.

@stof
Copy link

stof commented Mar 23, 2016

actually, I know why you get false: it is an interface, not a class

@sebastianbergmann
Copy link
Owner

You're right, of course, and with interface_exists() I do get true. This problem would be so much easier to analyse if I had a minimal, self-contained, reproducing test case. Any chance of getting one?

@sebastianbergmann
Copy link
Owner

I think I have found the root cause: the simple/naive in_array() call in https://github.com/sebastianbergmann/phpunit-mock-objects/blob/master/src/Framework/MockObject/Builder/InvocationMocker.php#L271 is not sufficient.

In the case of https://github.com/symfony/symfony/blob/v2.3.39/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php, $constraint is 'getClassMetaData' whereas $this->configurableMethods contains 'getClassMetadata'.

Yay! for PHP's case insensitivity.

@sebastianbergmann
Copy link
Owner

@sebastianbergmann
Copy link
Owner

I now get the following errors:

There were 12 errors:

1) Symfony\Component\Form\Tests\Extension\Validator\Constraints\FormValidatorTest::testNoViolationIfAllowExtraData
PHPUnit_Framework_MockObject_RuntimeException: Trying to configure method "addViolationAt" which cannot be configured

/home/sb/symfony/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php:627

2) Symfony\Component\Form\Tests\Extension\Validator\ValidatorExtensionTest::test2Dot5ValidationApi
PHPUnit_Framework_MockObject_RuntimeException: Trying to configure method "getMetadataFactory" which cannot be configured

/home/sb/symfony/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php:43

3) Symfony\Component\HttpKernel\Tests\DependencyInjection\MergeExtensionConfigurationPassTest::testAutoloadMainExtension
PHPUnit_Framework_MockObject_RuntimeException: Trying to configure method "getDefinitions" which cannot be configured

/home/sb/symfony/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/MergeExtensionConfigurationPassTest.php:45

4) Symfony\Component\HttpKernel\Tests\EventListener\RouterListenerTest::testSubRequestWithDifferentMethod
PHPUnit_Framework_MockObject_RuntimeException: Trying to configure method "getContext" which cannot be configured

/home/sb/symfony/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php:115

5) Symfony\Component\HttpKernel\Tests\HttpCache\HttpCacheTest::testTerminateDelegatesTerminationOnlyForTerminableInterface
PHPUnit_Framework_MockObject_RuntimeException: Trying to configure method "terminate" which cannot be configured

/home/sb/symfony/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php:35

6) Symfony\Component\HttpKernel\Tests\KernelTest::testClassCacheIsNotLoadedByDefault
PHPUnit_Framework_MockObject_RuntimeException: Trying to configure method "doLoadClassCache" which cannot be configured

/home/sb/symfony/src/Symfony/Component/HttpKernel/Tests/KernelTest.php:103

7) Symfony\Component\HttpKernel\Tests\KernelTest::testTerminateDelegatesTerminationOnlyForTerminableInterface
PHPUnit_Framework_MockObject_RuntimeException: Trying to configure method "terminate" which cannot be configured

/home/sb/symfony/src/Symfony/Component/HttpKernel/Tests/KernelTest.php:696

8) Symfony\Component\Translation\Tests\Writer\TranslationWriterTest::testDisableBackup
PHPUnit_Framework_MockObject_RuntimeException: Trying to configure method "setBackup" which cannot be configured

/home/sb/symfony/src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php:36

9) Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest::testRenderViewTwig
Error: Call to protected method Symfony\Bundle\FrameworkBundle\Controller\Controller::renderView() from context 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest'

/home/sb/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php:256

10) Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest::testRenderTwig
Error: Call to protected method Symfony\Bundle\FrameworkBundle\Controller\Controller::render() from context 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest'

/home/sb/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php:272

11) Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest::testStreamTwig
Error: Call to protected method Symfony\Bundle\FrameworkBundle\Controller\Controller::stream() from context 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest'

/home/sb/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php:287

12) Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest::testCreateAccessDeniedException
Error: Call to protected method Symfony\Bundle\FrameworkBundle\Controller\Controller::createAccessDeniedException() from context 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest'

/home/sb/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php:328

--

There were 2 failures:

1) Symfony\Component\Templating\Tests\DelegatingEngineTest::testStreamRequiresStreamingEngine
Failed asserting that exception of type "PHPUnit_Framework_MockObject_RuntimeException" matches expected exception "\LogicException". Message was: "Trying to configure method "stream" which cannot be configured" at
/home/sb/symfony/src/Symfony/Component/Templating/Tests/DelegatingEngineTest.php:70
.

2) Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest::testGenerator
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
 Generator {
   this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
   executing: {
     Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz(): {
-      %sGeneratorDemo.php:14: """
-        {\n
-            yield from bar();\n
-        }\n
+      /home/sb/symfony/src/Symfony/Component/VarDumper/Tests/Fixtures/GeneratorDemo.php:12: """
+        \n
+            public function baz()\n
+            {\n
         """
     }
   }
 }

/home/sb/symfony/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php:29
/home/sb/symfony/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php:168

As there are still Trying to configure method "..." which cannot be configured errors I do not think that all BC breaks introduced in ec7832e are solved yet.

@sebastianbergmann
Copy link
Owner

I stopped debugging after looking at the first remaining error because ExecutionContextInterface does not have a method named addViolationAt. This is an error that was silently ignored before.

@stof
Copy link

stof commented Mar 23, 2016

For Symfony\Component\Templating\Tests\DelegatingEngineTest::testStreamRequiresStreamingEngine, the issue is a bug in the Symfony testsuite. We are indeed trying to configure a non-existent method.

I think it may be great to have a different error message when the method does not exist at all rather than existing but not configurable (final or private). It would make it easier to understand the mistake.

@sebastianbergmann
Copy link
Owner

I agree but I am afraid that this would require significant work. I will probably do it eventually (unless someone beats me to it with a pull request) but no promises as to when.

@stof
Copy link

stof commented Mar 23, 2016

@sebastianbergmann a first easy step might be to add more explanations in the exception message about what cannot be configured means for PHPUnit (as people using PHPUnit might not know the rules determining this)

@sebastianbergmann
Copy link
Owner

Attempted in 957b4b2

xabbuh added a commit to symfony/symfony that referenced this issue Mar 23, 2016
This PR was merged into the 3.0 branch.

Discussion
----------

fix controller tests

| Q             | A
| ------------- | ---
| Branch?       | 3.0
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | items 9 to 12 from sebastianbergmann/phpunit-mock-objects#299 (comment)
| License       | MIT
| Doc PR        |

Add missing public method stubs to `TestController` (all methods in the base `Controller` class from the FrameworkBundle are `protected` since Symfony 3.0).

Commits
-------

fb963d2 fix controller tests
@sebastianbergmann
Copy link
Owner

@stof @nicolas-grekas Is the current state of master ready to be released as 3.1.2?

@nicolas-grekas
Copy link
Contributor Author

OK for me, we'll fix Symfony's tests to not mock undefined methods afterwards. Thanks

Tobion added a commit to symfony/symfony that referenced this issue Mar 23, 2016
This PR was merged into the 3.0 branch.

Discussion
----------

[3.0] fix mocking of some methods

| Q             | A
| ------------- | ---
| Branch?       | 3.0
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | items 1 and 2 of sebastianbergmann/phpunit-mock-objects#299 (comment)
| License       | MIT
| Doc PR        |

Commits
-------

07308e9 [3.0] fix mocking of some methods
Tobion added a commit to symfony/symfony that referenced this issue Mar 23, 2016
This PR was merged into the 2.3 branch.

Discussion
----------

[2.3] fix mocking of some methods

| Q             | A
| ------------- | ---
| Branch?       | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? |no
| Tests pass?   | yes
| Fixed tickets | items 3, 4, 5, and 7 of sebastianbergmann/phpunit-mock-objects#299 (comment)
| License       | MIT
| Doc PR        |

Commits
-------

542cf6b [2.3] fix mocking of some methods
@sebastianbergmann
Copy link
Owner

Thank you for bringing this to my attention, @nicolas-grekas and @stof, and for helping to resolve it.

@sebastianbergmann
Copy link
Owner

Sidenote: with PHPUnit 5.3, due on April 1, these errors will be warnings:

There were 4 errors:

1) Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest::testRenderViewTwig
Error: Call to protected method Symfony\Bundle\FrameworkBundle\Controller\Controller::renderView() from context 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest'

/home/sb/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php:256

2) Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest::testRenderTwig
Error: Call to protected method Symfony\Bundle\FrameworkBundle\Controller\Controller::render() from context 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest'

/home/sb/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php:272

3) Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest::testStreamTwig
Error: Call to protected method Symfony\Bundle\FrameworkBundle\Controller\Controller::stream() from context 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest'

/home/sb/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php:287

4) Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest::testCreateAccessDeniedException
Error: Call to protected method Symfony\Bundle\FrameworkBundle\Controller\Controller::createAccessDeniedException() from context 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ControllerTest'

/home/sb/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php:328

--

There were 8 warnings:

1) Symfony\Component\Form\Tests\Extension\Validator\Constraints\FormValidatorTest::testNoViolationIfAllowExtraData
Trying to configure method "addViolationAt" which cannot be configured because it does not exist, has not been specified, is final, or is static

2) Symfony\Component\Form\Tests\Extension\Validator\ValidatorExtensionTest::test2Dot5ValidationApi
Trying to configure method "getMetadataFactory" which cannot be configured because it does not exist, has not been specified, is final, or is static

3) Symfony\Component\HttpKernel\Tests\DependencyInjection\MergeExtensionConfigurationPassTest::testAutoloadMainExtension
Trying to configure method "getDefinitions" which cannot be configured because it does not exist, has not been specified, is final, or is static

4) Symfony\Component\HttpKernel\Tests\EventListener\RouterListenerTest::testSubRequestWithDifferentMethod
Trying to configure method "getContext" which cannot be configured because it does not exist, has not been specified, is final, or is static

5) Symfony\Component\HttpKernel\Tests\HttpCache\HttpCacheTest::testTerminateDelegatesTerminationOnlyForTerminableInterface
Trying to configure method "terminate" which cannot be configured because it does not exist, has not been specified, is final, or is static

6) Symfony\Component\HttpKernel\Tests\KernelTest::testClassCacheIsNotLoadedByDefault
Trying to configure method "doLoadClassCache" which cannot be configured because it does not exist, has not been specified, is final, or is static

7) Symfony\Component\HttpKernel\Tests\KernelTest::testTerminateDelegatesTerminationOnlyForTerminableInterface
Trying to configure method "terminate" which cannot be configured because it does not exist, has not been specified, is final, or is static

8) Symfony\Component\Translation\Tests\Writer\TranslationWriterTest::testDisableBackup
Trying to configure method "setBackup" which cannot be configured because it does not exist, has not been specified, is final, or is static

Tobion added a commit to symfony/symfony that referenced this issue Mar 24, 2016
This PR was merged into the 2.7 branch.

Discussion
----------

[2.7] fix mocking of some methods

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | items 6 and 8 of sebastianbergmann/phpunit-mock-objects#299 (comment)
| License       | MIT
| Doc PR        |

Commits
-------

a45b93d [2.7] fix mocking of some methods
greg0ire pushed a commit to greg0ire/SonataAdminBundle that referenced this issue Mar 24, 2016
These methods do not actually exist on the mock object, which means we will get
an error anyway if they are called. Recent versions of phpunit forbid
configuring inexistant methods in mocks, which makes tests fail.
See sebastianbergmann/phpunit-mock-objects#299
fabpot added a commit to symfony/symfony that referenced this issue Mar 27, 2016
This PR was merged into the 2.3 branch.

Discussion
----------

[phpunit] disable prophecy

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

Both Prophecy and Symfony require some phpdocumentor dependencies, but incompatible versions.
Since we don't use Prophecy, let's disable it.
phpunit-mock-objects is forced to v3.1.1 until we fix our test suite (see sebastianbergmann/phpunit-mock-objects#299).

Commits
-------

ae9bae7 [phpunit] disable prophecy
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants