Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Tests incompatible with PHPUnit 8 #27500

Closed
lbajsarowicz opened this issue Mar 30, 2020 · 147 comments
Closed

Unit Tests incompatible with PHPUnit 8 #27500

lbajsarowicz opened this issue Mar 30, 2020 · 147 comments
Assignees
Labels
Fixed in phpunit8 Fixed in 2.4.x The issue has been fixed in 2.4-develop branch good first issue Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@lbajsarowicz
Copy link
Contributor

lbajsarowicz commented Mar 30, 2020

Magento is slowly moving towards the latest dependencies in the PHP world. Part of this is to have (at least) supported version of PHPUnit ( https://phpunit.de/supported-versions.html )

Preconditions (*)

  1. Current Unit, Integration and API functional tests are not compatible with PHPUnit 8

Steps to reproduce (*)

  1. Install PHPUnit 8 on separate directory and run Unit Tests from Magento

Expected result (*)

  1. Tests should pass.

Actual result (*)

  1. Tests are failing due to multiple compatibility issues

Contribution

What needs to be done

Most of the cases, the scenario to make Unit Tests compatible with PHPUnit 8 is:

  1. setUp and tearDown methods has to have : void return type hint
  2. Replace PHPUnit_Framework_TestCase with PHPUnit\Framework\TestCase
  3. Replace \PHPUnit_Framework_MockObject_MockObject with \PHPUnit\Framework\MockObject\MockObject
  4. Replace @expectedException \Magento\Framework\Exception\ConfigurationMismatchException annotation with $this->expectException(\Magento\Framework\Exception\ConfigurationMismatchException::class)
  5. Replace @expectedExceptionMessage with $this->expectExceptionMessage('The message');

If you find any other typical steps to be done - let me know in the comment, I'm going to update the issue.

PHPUnit 9+ compatibility

https://phpunit.de/announcements/phpunit-8.html

Review the use of deprecated methods: assertContains, assertNotContains etc.
... and annotations expectException, expectExceptionMessage etc.

Notice!

Make sure that you have linted your code after finish your work!
❗ ❗ ❗ If you see Tests that test nothing - rewrite or remove them. Let's avoid massive delusion of Tests coverage, based on the tests that test implementation instead of method / unit outcome!

Modules

Due to some compatibility issues and to make Code Review easier - please do your changes per module. You can find list of checkboxes underneath with list of modules that should be covered. When you start working on specific module, please check the chekbox and add the comment which module you start work. When you finish - edit your commend adding the link to PR.

Open Source

  • app/code/Magento/AdminNotification
  • app/code/Magento/AdminAnalytics
  • app/code/Magento/AdvancedPricingImportExport
  • app/code/Magento/AdvancedSearch
  • app/code/Magento/Amqp
  • app/code/Magento/Analytics
  • app/code/Magento/AsynchronousOperations
  • app/code/Magento/Authorization
  • app/code/Magento/Authorizenet
  • app/code/Magento/Backend
  • app/code/Magento/Backup
  • app/code/Magento/Braintree
  • app/code/Magento/Bundle
  • app/code/Magento/BundleImportExport
  • app/code/Magento/CacheInvalidate
  • app/code/Magento/Captcha
  • app/code/Magento/CardinalCommerce
  • app/code/Magento/Catalog
  • app/code/Magento/CatalogImportExport
  • app/code/Magento/CatalogInventory
  • app/code/Magento/CatalogRule
  • app/code/Magento/CatalogRuleConfigurable
  • app/code/Magento/CatalogSearch
  • app/code/Magento/CatalogUrlRewrite
  • app/code/Magento/CatalogWidget
  • app/code/Magento/Checkout
  • app/code/Magento/CheckoutAgreements
  • app/code/Magento/Cms
  • app/code/Magento/CmsUrlRewrite
  • app/code/Magento/Config
  • app/code/Magento/ConfigurableImportExport
  • app/code/Magento/ConfigurableProduct
  • app/code/Magento/Contact
  • app/code/Magento/Cookie
  • app/code/Magento/Cron
  • app/code/Magento/CurrencySymbol
  • app/code/Magento/Customer
  • app/code/Magento/CustomerImportExport
  • app/code/Magento/Deploy
  • app/code/Magento/Developer
  • app/code/Magento/Directory
  • app/code/Magento/Downloadable
  • app/code/Magento/DownloadableImportExport
  • app/code/Magento/Eav
  • app/code/Magento/Elasticsearch
  • app/code/Magento/Elasticsearch6
  • app/code/Magento/Elasticsearch7
  • app/code/Magento/Email
  • app/code/Magento/EncryptionKey
  • app/code/Magento/GiftMessage
  • app/code/Magento/GoogleAdwords
  • app/code/Magento/GoogleAnalytics
  • app/code/Magento/GoogleOptimizer
  • app/code/Magento/GroupedImportExport
  • app/code/Magento/GroupedProduct
  • app/code/Magento/ImportExport
  • app/code/Magento/Indexer
  • app/code/Magento/InstantPurchase
  • app/code/Magento/Integration
  • app/code/Magento/LayeredNavigation
  • app/code/Magento/Marketplace
  • app/code/Magento/MediaStorage
  • app/code/Magento/MessageQueue
  • app/code/Magento/Msrp
  • app/code/Magento/Multishipping
  • app/code/Magento/MysqlMq
  • app/code/Magento/NewRelicReporting
  • app/code/Magento/Newsletter
  • app/code/Magento/OfflinePayments
  • app/code/Magento/OfflineShipping
  • app/code/Magento/PageCache
  • app/code/Magento/Payment
  • app/code/Magento/Paypal
  • app/code/Magento/Persistent
  • app/code/Magento/ProductAlert
  • app/code/Magento/ProductVideo
  • app/code/Magento/Quote
  • app/code/Magento/ReleaseNotification
  • app/code/Magento/Reports
  • app/code/Magento/RequireJs
  • app/code/Magento/Review
  • app/code/Magento/Robots
  • app/code/Magento/Rss
  • app/code/Magento/Rule
  • app/code/Magento/Sales
  • app/code/Magento/SalesInventory
  • app/code/Magento/SalesRule
  • app/code/Magento/SalesSequence
  • app/code/Magento/SampleData
  • app/code/Magento/Search
  • app/code/Magento/Security
  • app/code/Magento/SendFriend
  • app/code/Magento/Shipping
  • app/code/Magento/Signifyd
  • app/code/Magento/Sitemap
  • app/code/Magento/Store
  • app/code/Magento/Swagger
  • app/code/Magento/SwaggerWebapi
  • app/code/Magento/SwaggerWebapiAsync
  • app/code/Magento/Swatches
  • app/code/Magento/Tax
  • app/code/Magento/TaxImportExport
  • app/code/Magento/Theme
  • app/code/Magento/Translation
  • app/code/Magento/Ui
  • app/code/Magento/UrlRewrite
  • app/code/Magento/User
  • app/code/Magento/Variable
  • app/code/Magento/Vault
  • app/code/Magento/Webapi
  • app/code/Magento/WebapiAsync
  • app/code/Magento/Weee

B2B

  • .b2b/app/code/Magento/BundleNegotiableQuote
  • .b2b/app/code/Magento/BundleSharedCatalog
  • .b2b/app/code/Magento/Company
  • .b2b/app/code/Magento/CompanyCredit
  • .b2b/app/code/Magento/CompanyPayment
  • .b2b/app/code/Magento/ConfigurableNegotiableQuote
  • .b2b/app/code/Magento/ConfigurableSharedCatalog
  • .b2b/app/code/Magento/GiftCardRequisitionList
  • .b2b/app/code/Magento/GiftCardSharedCatalog
  • .b2b/app/code/Magento/GroupedRequisitionList
  • .b2b/app/code/Magento/GroupedSharedCatalog
  • .b2b/app/code/Magento/NegotiableQuote
  • .b2b/app/code/Magento/NegotiableQuoteSharedCatalog
  • .b2b/app/code/Magento/OrderHistorySearch
  • .b2b/app/code/Magento/QuickOrder
  • .b2b/app/code/Magento/RequisitionList
  • .b2b/app/code/Magento/SharedCatalog

EE

  • .ee/app/code/Magento/AdminGws
  • .ee/app/code/Magento/AdvancedCatalog
  • .ee/app/code/Magento/AdvancedCheckout
  • .ee/app/code/Magento/AdvancedRule
  • .ee/app/code/Magento/AdvancedSalesRule
  • .ee/app/code/Magento/Banner
  • .ee/app/code/Magento/BannerCustomerSegment
  • .ee/app/code/Magento/BundleImportExportStaging
  • .ee/app/code/Magento/BundleStaging
  • .ee/app/code/Magento/CatalogEvent
  • .ee/app/code/Magento/CatalogImportExportStaging
  • .ee/app/code/Magento/CatalogInventoryStaging
  • .ee/app/code/Magento/CatalogPermissions
  • .ee/app/code/Magento/CatalogRuleStaging
  • .ee/app/code/Magento/CatalogStaging
  • .ee/app/code/Magento/CheckoutStaging
  • .ee/app/code/Magento/CmsStaging
  • .ee/app/code/Magento/ConfigurableProductStaging
  • .ee/app/code/Magento/CustomAttributeManagement
  • .ee/app/code/Magento/CustomerBalance
  • .ee/app/code/Magento/CustomerCustomAttributes
  • .ee/app/code/Magento/CustomerFinance
  • .ee/app/code/Magento/CustomerSegment
  • .ee/app/code/Magento/Cybersource
  • .ee/app/code/Magento/Enterprise
  • .ee/app/code/Magento/Eway
  • .ee/app/code/Magento/GiftCard
  • .ee/app/code/Magento/GiftCardAccount
  • .ee/app/code/Magento/GiftCardImportExport
  • .ee/app/code/Magento/GiftRegistry
  • .ee/app/code/Magento/GiftWrapping
  • .ee/app/code/Magento/GoogleTagManager
  • .ee/app/code/Magento/GroupedProductStaging
  • .ee/app/code/Magento/Invitation
  • .ee/app/code/Magento/Logging
  • .ee/app/code/Magento/MultipleWishlist
  • .ee/app/code/Magento/PaymentStaging
  • .ee/app/code/Magento/PersistentHistory
  • .ee/app/code/Magento/PricePermissions
  • .ee/app/code/Magento/PromotionPermissions
  • .ee/app/code/Magento/Reminder
  • .ee/app/code/Magento/ResourceConnections
  • .ee/app/code/Magento/ReviewStaging
  • .ee/app/code/Magento/Reward
  • .ee/app/code/Magento/Rma
  • .ee/app/code/Magento/SalesArchive
  • .ee/app/code/Magento/SalesRuleStaging
  • .ee/app/code/Magento/ScalableCheckout
  • .ee/app/code/Magento/ScalableInventory
  • .ee/app/code/Magento/ScalableOms
  • .ee/app/code/Magento/ScheduledImportExport
  • .ee/app/code/Magento/Staging
  • .ee/app/code/Magento/Support
  • .ee/app/code/Magento/TargetRule
  • .ee/app/code/Magento/VersionsCms
  • .ee/app/code/Magento/VisualMerchandiser
  • .ee/app/code/Magento/WebsiteRestriction
  • .ee/app/code/Magento/Worldpay
  • .ee/lib/internal/Magento/Framework/ForeignKey/Test/Unit

Inventory module

  • ext/magento/inventory/Inventory/
  • ext/magento/inventory/InventoryImportExport/
  • ext/magento/inventory/InventoryMultiDimensionalIndexerApi/
  • ext/magento/inventory/InventoryReservations/
@m2-assistant
Copy link

m2-assistant bot commented Mar 30, 2020

Hi @lbajsarowicz. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@lbajsarowicz do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@dmytro-ch
Copy link
Contributor

Hi @lbajsarowicz, I'll take care of app/code/Magento/AdvancedSearch. :)
Thank you!

@lbajsarowicz
Copy link
Contributor Author

I'm going to take care of Magento/Cron module

@AndreyChorniy
Copy link
Contributor

Hi @lbajsarowicz, I would like to care about app/code/Magento/Newsletter

@cristiano-pacheco
Copy link
Contributor

Hi @lbajsarowicz, I would like to take care app/code/Magento/Payment

@AndreyChorniy
Copy link
Contributor

Hey @lbajsarowicz,
I have added PR for compatibility test with PHPUnit8 for module Magento_Authorization

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27814 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27815 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27816 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27817 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27818 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27819 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27820 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27821 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27824 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27825 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27826 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27827 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz. Thank you for your report.
The issue has been fixed in #27885 by @lbajsarowicz in phpunit8 branch
Related commit(s):

The fix will be available with the upcoming release.

lbajsarowicz added a commit to lbajsarowicz/magento2 that referenced this issue May 1, 2020
lbajsarowicz added a commit to lbajsarowicz/inventory that referenced this issue May 6, 2020
lbajsarowicz added a commit to lbajsarowicz/inventory that referenced this issue May 6, 2020
@zhartaunik
Copy link
Contributor

zhartaunik commented Jul 27, 2020

cc @lbajsarowicz

magento@fpm:/var/www/magento$ vendor/bin/phpunit -c /var/www/magento/dev/tests/unit/phpunit.xml /var/www/magento/app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/
PHPUnit 9.1.5 by Sebastian Bergmann and contributors.

  Warning - The configuration file did not pass validation!
  The following problems have been detected:

  Line 18:
  - Element 'testsuite': This element is not expected.

  Test results may not be as expected.


EEEEE                                                                                                                                                                                          5 / 5 (100%)

Time: 00:00.782, Memory: 16.00 MB

There were 5 errors:

1) Magento\CatalogImportExport\Test\Unit\Model\Export\ProductTest::testGetEntityTypeCode
ArgumentCountError: Too few arguments to function Magento\Catalog\Model\ResourceModel\ProductFactory::__construct(), 0 passed in /var/www/magento/vendor/phpunit/phpunit/src/Framework/MockObject/Generator.php on line 539 and at least 1 expected

/var/www/magento/generated/code/Magento/Catalog/Model/ResourceModel/ProductFactory.php:29
/var/www/magento/app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php:175

2) Magento\CatalogImportExport\Test\Unit\Model\Export\ProductTest::testUpdateDataWithCategoryColumnsNoCategoriesAssigned
ArgumentCountError: Too few arguments to function Magento\Catalog\Model\ResourceModel\ProductFactory::__construct(), 0 passed in /var/www/magento/vendor/phpunit/phpunit/src/Framework/MockObject/Generator.php on line 539 and at least 1 expected

/var/www/magento/generated/code/Magento/Catalog/Model/ResourceModel/ProductFactory.php:29
/var/www/magento/app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php:175

3) Magento\CatalogImportExport\Test\Unit\Model\Export\ProductTest::testGetHeaderColumns
ArgumentCountError: Too few arguments to function Magento\Catalog\Model\ResourceModel\ProductFactory::__construct(), 0 passed in /var/www/magento/vendor/phpunit/phpunit/src/Framework/MockObject/Generator.php on line 539 and at least 1 expected

/var/www/magento/generated/code/Magento/Catalog/Model/ResourceModel/ProductFactory.php:29
/var/www/magento/app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php:175

4) Magento\CatalogImportExport\Test\Unit\Model\Export\ProductTest::testExportCountZeroBreakInternalCalls
ArgumentCountError: Too few arguments to function Magento\Catalog\Model\ResourceModel\ProductFactory::__construct(), 0 passed in /var/www/magento/vendor/phpunit/phpunit/src/Framework/MockObject/Generator.php on line 539 and at least 1 expected

/var/www/magento/generated/code/Magento/Catalog/Model/ResourceModel/ProductFactory.php:29
/var/www/magento/app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php:175

5) Magento\CatalogImportExport\Test\Unit\Model\Export\ProductTest::testExportCurPageEqualToLastBreakInternalCalls
ArgumentCountError: Too few arguments to function Magento\Catalog\Model\ResourceModel\ProductFactory::__construct(), 0 passed in /var/www/magento/vendor/phpunit/phpunit/src/Framework/MockObject/Generator.php on line 539 and at least 1 expected

/var/www/magento/generated/code/Magento/Catalog/Model/ResourceModel/ProductFactory.php:29
/var/www/magento/app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php:175

ERRORS!
Tests: 5, Assertions: 0, Errors: 5.

Need to ->disableOriginalConstructor() for 3 Factories or am I running something wrong?

@ihor-sviziev
Copy link
Contributor

@zhartaunik do you have this issue on 2.4-develop branch?

@zhartaunik
Copy link
Contributor

@zhartaunik do you have this issue on 2.4-develop branch?

Yes

@ihor-sviziev
Copy link
Contributor

@zhartaunik could you report separate issue for that? Thank you!

@zhartaunik
Copy link
Contributor

Hi @ihor-sviziev
I noticed that I was mistaken with my branches and this issue referred to some old revision.
Tests work well now.

@magento-engcom-team
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in phpunit8 Fixed in 2.4.x The issue has been fixed in 2.4-develop branch good first issue Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests