-
Notifications
You must be signed in to change notification settings - Fork 248
PHP 7 Syntax usage for Magento Contribution
At the beginning of this week, we've merged a pull request upgrading PHPUnit version to 6.2 https://github.com/magento/magento2/blob/develop/composer.json#L77
Along with that we've updated all the Unit Tests in our code base for Magento Open Source (Community Edition)
magento2 iminiailo$ find ./app/code/Magento/ -type f -name "*Test.php" | wc -l
3069
and Magento Commerce (Enterprise Edition)
magento2ee iminiailo$ find ./app/code/Magento/ -type f -name "*Test.php" | wc -l
1176
As you probably know PHPUnit 6 is Backward Incompatible release to 4.1 which was previously used by Magento 2. The list of most significant changes could be found here.
Main changes we were fixing in Magento 2 Unit test suit were:
-
PHPUnit_Framework_TestCase is now PHPUnit\Framework\TestCase
PHPUnit's units of code are now namespaced. Among other things, this means that your test case classes now need to extend
PHPUnit\Framework\TestCase
instead ofPHPUnit_Framework_TestCase
. Thus, parent class for all Unit tests should be changed. -
Deprecated APIs Removed
Methods such as
getMock(), getMockWithoutInvokingTheOriginalConstructor(), setExpectedException(), setExpectedExceptionRegExp(), or hasPerformedExpectationsOnOutput()
that were deprecated before have now been removed from PHPUnit 6.createMock(), createConfiguredMock(), createPartialMock(), createTestProxy(), and getMockBuilder()
should be used instead ofgetMock() and getMockWithoutInvokingTheOriginalConstructor()
. AndexpectException()
should be used instead ofsetExpectedException()
(or the @expectException annotation).
Similar changes should be done by extension developers who cover their code with Unit Tests and relied on PHPUnit 4.1 APIs.
This Upgrade was the last step on a way to PHP 7 syntax support.
- Return types declaration
- Scalar type hinting
From this time Community Engineering team starts to accept PRs using PHP 7 syntax.
But because Magento 2.2.0 supports PHP 7 from version 7.0.* we don't support usage of:
- Nullable types (which could be handy for our Data interfaces)
function testReturn(): ?string
{
return null;
}
function test(?string $name)
{
var_dump($name);
}
- Void return type (which could be handy for our Commands, as they follow CQRS and return Void)
function testReturn(): void
{
return;
}
As these features were added in PHP 7.1 release.
Multi-Source Inventory developed by Magento 2 Community
- Technical Vision. Catalog Inventory
- Installation Guide
- List of Inventory APIs and their legacy analogs
- MSI Roadmap
- Known Issues in Order Lifecycle
- MSI User Guide
- 2.3 LIVE User Guide
- MSI Release Notes and Installation
- Overview
- Get Started with MSI
- MSI features and processes
- Global and Product Settings
- Configure Source Selection Algorithm
- Create Sources
- Create Stock
- Assign Inventory and Product Notifications
- Configure MSI backorders
- MSI Import and Export Product Data
- Mass Action Tool
- Shipment and Order Management
- CLI reference
- Reports and MSI
- MSI FAQs
- DevDocs Documentation
- Manage Inventory Management Modules (install/upgrade info)
- Inventory Management
- Reservations
- Inventory CLI reference
- Inventory API reference
- Inventory In-Store Pickup API reference
- Order Processing with Inventory Management
- Managing sources
- Managing stocks
- Link and unlink stocks and sources
- Manage source items
- Perform bulk actions
- Manage Low-Quantity Notifications
- Check salable quantities
- Manage source selection algorithms
- User Stories
- Support of Store Pickup for MSI
- Product list assignment per Source
- Source assignment per Product
- Stocks to Sales Channel Mapping
- Adapt Product Import/Export to support multi Sourcing
- Introduce SourceCode attribute for Source and SourceItem entities
- Assign Source Selector for Processing of Returns Credit Memo
- User Scenarios:
- Technical Designs:
- Module Structure in MSI
- When should an interface go into the Model directory and when should it go in the Api directory?
- Source and Stock Item configuration Design and DB structure
- Stock and Source Configuration design
- Open Technical Questions
- Inconsistent saving of Stock Data
- Source API
- Source WebAPI
- Sources to Sales Channels mapping
- Service Contracts MSI
- Salable Quantity Calculation and Mechanism of Reservations
- StockItem indexation
- Web API and How To cover them with Functional Testing
- Source Selection Algorithms
- Validation of Domain Entities
- PHP 7 Syntax usage for Magento contribution
- The first step towards pre generated IDs. And how this will improve your Integration tests
- The Concept of Default Source and Domain Driven Design
- Extension Point of Product Import/Export
- Source Selection Algorithm
- SourceItem Entity Extension
- Design Document for changing SerializerInterface
- Stock Management for Order Cancelation
- Admin UI
- MFTF Extension Tests
- Weekly MSI Demos
- Tutorials