barkeron.blogg.se

Phpunit mocks
Phpunit mocks










phpunit mocks
  1. Phpunit mocks update#
  2. Phpunit mocks code#

Phpunit mocks code#

This allows developers to catch such cases and either extend the interface or fix the constructor dependency to be on the concrete instance (this is not a backward compatibility break as the code defacto already has this dependency - it just was hidden so far). PHPUnit 4.1 can not create mocks of classes with methods specifying return types. Such warnings for for example highlight the use of concrete instance methods when the mocked dependency is an interface. In fact, I think it would benefit the Magento core code, too, since some of the new features added in PHPUnit 5 are to show warnings when using bad practices in tests, such as mocking non-existent methods. Updating PHPUnit to allow third party developers to already utilize some PHP7 features would be a relatively easy to do step in that direction. This can be done in multiple steps however, I think nobody expects the Magento core to make this big move immediately. I believe in order to stay current Magento 2 will have to be adjusted to be fully compatible with PHP7 features. There already have been multiple issues where developers attempted to use PHP7 specific features with Magento 2. vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php(290) PHP Fatal error: Declaration of Mock_CollectorInterface_c5f77d44::collectForModule(string $moduleDir) must be compatible with VinaiKopp\Example\Src\CollectorInterface::collectForModule(string $moduleDir): string in. The mock PHPUnit 4.1 generates is not compatible with the PHP7 code and PHP throws an exception. A test that attempts to mock such the class or interface.A module containing a class or interface with a method using a PHP7 return type.A Magento 2 installation (any version, beta to current develop HEAD).

Phpunit mocks update#

This would be possible by an update of the bundled testing library to PHPUnit 5. This feature was added to PHPUnit version 5 (more specifically, phpunit-mock-objects version 3, which is a dependency of PHPUnit 5).Īs an external developer, I would like to be able to write PHP7 code if my client uses it.Īlso, I would like to be able to easily test my code using the testing library bundled with Magento 2. PHPUnit 4.1 can not create mocks of classes with methods specifying return types.

phpunit mocks

Magento 2 currently uses the PHP testing library PHPUnit version 4.1. compilation and ObjectManager compliance). However, code written for specific Magento 2 instances known to be running on PHP7, may already utilize the many features PHP7 provides under certain circumstances (e.g. This feature of PHP7 (and others) is not used by the Magento 2 core code, since it still supports the old PHP version 5.6. PHP7 allows methods to declare return types. Feature request from Vinai, posted on GitHub Aug 20, 2016












Phpunit mocks