{"action":"opened","issue":{"url":"https://api.github.com/repos/magento/magento2/issues/6254","repository_url":"https://api.github.com/repos/magento/magento2","labels_url":"https://api.github.com/repos/magento/magento2/issues/6254/labels{/name}","comments_url":"https://api.github.com/repos/magento/magento2/issues/6254/comments","events_url":"https://api.github.com/repos/magento/magento2/issues/6254/events","html_url":"https://github.com/magento/magento2/issues/6254","id":172253635,"number":6254,"title":"PHPUnit 4 can not mock classes with methods using PHP7 return types","user":{"login":"Vinai","id":72463,"avatar_url":"https://avatars.githubusercontent.com/u/72463?v=3","gravatar_id":"","url":"https://api.github.com/users/Vinai","html_url":"https://github.com/Vinai","followers_url":"https://api.github.com/users/Vinai/followers","following_url":"https://api.github.com/users/Vinai/following{/other_user}","gists_url":"https://api.github.com/users/Vinai/gists{/gist_id}","starred_url":"https://api.github.com/users/Vinai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vinai/subscriptions","organizations_url":"https://api.github.com/users/Vinai/orgs","repos_url":"https://api.github.com/users/Vinai/repos","events_url":"https://api.github.com/users/Vinai/events{/privacy}","received_events_url":"https://api.github.com/users/Vinai/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-20T04:58:24Z","updated_at":"2016-08-20T04:58:24Z","closed_at":null,"body":"PHP7 allows methods to declare return types.\r\nFor example:\r\n\r\n```php\r\ninterface FooInterface\r\n{\r\n    public function bar(): int;\r\n}\r\n```\r\n\r\nThis feature of PHP7 (and others) is not used by the Magento 2 core code, since it still supports the old PHP version 5.6.\r\nHowever, 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. compilation and `ObjectManager` compliance).\r\n\r\nMagento 2 currently uses the PHP testing library PHPUnit version 4.1.\r\nPHPUnit 4.1 can not create mocks of classes with methods specifying return types.\r\nThis feature was added to PHPUnit version 5 (more specifically, phpunit-mock-objects version 3, which is a dependency of PHPUnit 5).\r\n\r\nAs an external developer, I would like to be able to write PHP7 code if my client uses it.\r\nAlso, I would like to be able to easily test my code using the testing library bundled with Magento 2.\r\nThis would be possible by an update of the bundled testing library to PHPUnit 5.\r\n\r\n### Preconditions\r\n1. PHP7\r\n2. A Magento 2 installation (any version, beta to current develop HEAD).\r\n\r\n### Steps to reproduce\r\n1. A module containing a class or interface with a method using a PHP7 return type.\r\n2. A test that attempts to mock such the class or interface.\r\n\r\n### Expected result\r\nPHPUnit creates the mock\r\n\r\n### Actual result\r\nThe mock PHPUnit 4.1 generates is not compatible with the PHP7 code and PHP throws an exception.\r\n\r\n```\r\nPHP Fatal error:  Declaration of Mock_CollectorInterface_c5f77d44::collectForModule(string $moduleDir) must be compatible with VinaiKopp\\Example\\Src\\CollectorInterface::collectForModule(string $moduleDir): string in .../vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php(290)\r\n```\r\n\r\nThere already have been multiple issues where developers attempted to use PHP7 specific features with Magento 2. This is just the latest in this chain. I believe in order to stay current Magento 2 will have to be adjusted to be fully compatible with PHP7 features.  \r\nThis can be done in multiple steps however, I think nobody expects the Magento core to make this big move immediately. Updating PHPUnit to allow third party developers to already utilize some PHP7 features would be a relatively easy to do step in that direction."}}
{"actor":{"display_login":"Vinai"}}