magento / magento2-functional-testing-framework

Magento2 Functional Testing Framework
Other
155 stars 133 forks source link

Eliminated Aspect Mock usage from FilesystemTest #833

Closed sivaschenko closed 3 years ago

sivaschenko commented 3 years ago

Goal

codeception/aspect-mock library is still not compatible with PHP 8.0 at the time of the creation of this ticket.

To speed up Magento compatibility with new PHP versions we'd like to eliminate codeception/aspect-mock dependency from MFTF. This will make MFTF compatible with PHP 8.0 that is required for declaring the Magento core PHP 8 compatible as well.

In order to do this existing unit tests using AspectMock should be refactored to use PHPUnit instead.

Task

Resolves https://github.com/magento/magento2/issues/33291

Replace AspectMock with PHPUnit for dev/tests/unit/Magento/FunctionalTestFramework/Config/Reader/FilesystemTest.php in https://github.com/magento/magento2-functional-testing-framework repository.

Example

Mocking an object using AspectMock (current):

        $mock = AspectMock::double(
            MockedClass::class,
            [
                'mockedMethodName' => 'methodReturnValue',
            ]
        )->make();

Mocking an object using PHPUnit (refactored code):

        $mock = $this->createMock(File::class);
        $file->expects($this->any())
            ->method('mockedMethodName')
            ->willReturn('methodReturnValue');
sivaschenko commented 3 years ago

@jilu1 I have created this pull request to use as an example of changes for the following tickets. Please review and suggest any best practices that should be applied or mentioned.

I think it's important for us to have stable Unit tests for the refactoring tasks, are there any expectations on when it can be stabilized?

jilu1 commented 3 years ago

@magento import pull request to https://github.com/magento-commerce/magento2-functional-testing-framework

magento-engcom-team commented 3 years ago

@jilu1 the pull request successfully imported.