Skip to content

Symfony, phpunit 5.4 and deprecations #19125

@linaori

Description

@linaori

When upgrading to a newer phpunit, you will start getting warnings that amongst some getMock is deprecated and createMock should be used instead.

According to the contribution page, 4.2 or higher is required. Symfony doesn't have its own dependency on phpunit and thus it's up to the contributors to use the proper versions. Now that phpunit is picking up speed and starts dropping unsupported php versions and features, things change fast.

In phpunit 5.4 the biggest change is the deprecation of getMock. If this method is used with only 1 argument, it has to be replaced by createMock and if the other arguments were passed along, getMockBuilder should be used instead.

As symfony doesn't really have a constraint on phpunit other than 4.2+, you will run into some small issues:

$ f getMock -G "Test/"
src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php
96:        $translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
97:        $validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
98:        $contextualValidator = $this->getMock('Symfony\Component\Validator\Validator\ContextualValidatorInterface');

src/Symfony/Component/Form/Test/TypeTestCase.php
33:        $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');

The first one I don't know but the second one is used as a base class for form type tests. Besides of this, the test code might have to change as well as getMock is being deprecated. I can create a patch for those cases to check if createMock exists and call it instead or use the mock builder for example.

Besides of this issue, I would like to bring up the discussion of the supported phpunit versions and how to actively keep the tests up-to-date.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions