magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.57k stars 9.32k forks source link

Magento integration test framework does not load the config file defined in (TESTS_GLOBAL_CONFIG_FILE) in the phpunit.xml #27864

Closed bunyamin-gc closed 3 years ago

bunyamin-gc commented 4 years ago

When running integration tests, Magento does not load configurations from this file config.local.php located in the sandbox. This file is created when Magento first builds the sandbox environment based on this constant TESTS_GLOBAL_CONFIG_FILE defined in the phpunit.xml.

image

Preconditions (*)

  1. Magento version 2.3.4
  2. Please make sure that you have the following content in your dev/tests/integration/etc/config-global.php.dist file:
    
    <?php
    /**
    * Copyright © Magento, Inc. All rights reserved.
    * See COPYING.txt for license details.
    */

return [ 'customer/password/limit_password_reset_requests_method' => 0, 'admin/security/admin_account_sharing' => 1, 'admin/security/limit_password_reset_requests_method' => 0, ];


### Steps to reproduce (*)
<!---
Important: Provide a set of clear steps to reproduce this bug. We can not provide support without clear instructions on how to reproduce.
-->
1. Install Magento 2.3.4 via composer.
2. Run the following integration test:

<?php declare(strict_types=1);

use Magento\Framework\App\Config\ScopeConfigInterface; use PHPUnit\Framework\TestCase; use Magento\TestFramework\Helper\Bootstrap;

class ConfigTest extends TestCase { /**

Expected result (*)

  1. I expect this test to pass because account sharing is enabled in the configuration file.

Actual result (*)

  1. Unfortunately, Magento does not read this file at all.
m2-assistant[bot] commented 4 years ago

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

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.

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


bnymn commented 4 years ago

@magento give me 2.4-develop instance

magento-engcom-team commented 4 years ago

Hi @bnymn. Thank you for your request. I'm working on Magento 2.4-develop instance for you

magento-engcom-team commented 4 years ago

Hi @bnymn, here is your Magento instance. Admin access: https://i-27864-2-4-develop.instances.magento-community.engineering/admin_7e68 Login: b9233226 Password: c16c3b542b9f Instance will be terminated in up to 3 hours.

bunyamin-gc commented 4 years ago

15196 This issue is related to this one.

tudalrik-ls commented 4 years ago

Hi @bunyamin-gc - do you know of any solution or workaround to that open issue yet?

I am trying to run integration tests for a extension refactoring but the installation process stops at step 4 and there is nothing I can do to fix the default website configuration currently. None of my configuration adaptions is being integrated for the test setup.

Exception: Starting Magento installation:                                                                                                                                                
File permissions check...                                                                                                                                                                
[Progress: 1 / 1321]                                                                                                                                                                     
Required extensions check...                                                                                                                                                             
[Progress: 2 / 1321]                                                                                                                                              
Enabling Maintenance Mode...                                                                                                                                          
[Progress: 3 / 1321]                                                                                                                                                         
Installing deployment configuration...                                                                                                                                 
[Progress: 4 / 1321]                                                                                                                            
Installing database schema:                                                                                                                 

In WebsiteRepository.php line 159:                                                                                                                                

  [DomainException]                                                                                                                                                          
  The default website isn't defined. Set the website and try again.                                                                                                    

Exception trace:                                                                                                                          
 () at /var/www/src/vendor/magento/module-store/Model/WebsiteRepository.php:159                                  
 Magento\Store\Model\WebsiteRepository->getDefault() at /var/www/src/vendor/magento/module-store/Model/StoreResolver/Website.php:49
 Magento\Store\Model\StoreResolver\Website->getAllowedStoreIds() at /var/www/src/vendor/magento/module-store/Model/StoresData.php:65
 Magento\Store\Model\StoresData->getStoresData() at /var/www/src/vendor/magento/module-store/Model/StoreResolver.php:138
bnymn commented 4 years ago

Does @magento-team know that integration tests are failing even with fresh installation? This is not really developer friendly...

I am also getting the same error message:

In WebsiteRepository.php line 159:

  [DomainException]
  The default website isn't defined. Set the website and try again.
bnymn commented 4 years ago

Hi @tudalrik-ls ,

I have found this part. I don't know if it will help.

Issue: Magento displays this error message during installation of Magento with third-party extensions that have dependencies on APIs for the Store module in CLI commands: The default website isn't defined. Set the website and try again. Workaround: Remove dependencies on third-party extensions from Composer, install Magento, and then install third-party extensions.

https://devdocs.magento.com/guides/v2.4/release-notes/release-notes-2-4-0-commerce.html

tudalrik-ls commented 4 years ago

Hi @bnymn

do you see any context?

@jissereitsma postet this: https://twitter.com/jissereitsma/status/1288177211934150656?s=12

Ok, here we go with 2.4: Declaration of Dotdigitalgroup\Email\Test\Integration\Model\Sync\Review\ReviewTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in dotmailer/dotmailer-magento2-extension/Test/Integration/Model/Sync/Review/ReviewTest.php So apparently, the new out of the box Magento 2.4 breaks Integration Tests, thanks to unchecked third party extensions. Why was this released without a proper pre-release? Fixed it by removing all bundled extensions again!!!: composer require yireo/magento2-replace-bundled --no-update; rm -r vendor/ composer.lock; composer install

bnymn commented 4 years ago

Hi @tudalrik-ls ,

When I run the integration tests, the dependency manager resolves and initializes all console commands. If any of them depends on the Store class, then you will get that error.

I did not have any external package in my project. However, I had my custom module with a console command. So, I have replaced it with a Proxy in di.xml. Problem solved.

You can put a break point here: In WebsiteRepository.php line 159, then look through the function call stack. There, you will see one of the Command class triggers Store class to load.

The tweet is talking about something else though. The return type is added to the new version of PHPUnit, on the other hand, some third party extensions are not compatible with that.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

snez commented 3 years ago

@bnymn how do you find the problem dependency? If I look at the stack trace, there doesn't seem to be a dependency module in there:

DomainException: The default website isn't defined. Set the website and try again. in app/code/Magento/Store/Model/WebsiteRepository.php:159
Stack trace:
#0 app/code/Magento/Store/Model/StoreResolver/Website.php(49): Magento\Store\Model\WebsiteRepository->getDefault()
#1 app/code/Magento/Store/Model/StoresData.php(67): Magento\Store\Model\StoreResolver\Website->getAllowedStoreIds(NULL)
#2 app/code/Magento/Store/Model/StoreResolver.php(138): Magento\Store\Model\StoresData->getStoresData('website', NULL)
#3 app/code/Magento/Store/Model/StoreResolver.php(97): Magento\Store\Model\StoreResolver->getStoresData()
#4 app/code/Magento/Store/Model/StoreManager.php(160): Magento\Store\Model\StoreResolver->getCurrentStoreId()
#5 dev/tests/integration/framework/Magento/TestFramework/Store/StoreManager.php(88): Magento\Store\Model\StoreManager->getStore(NULL)
#6 dev/tests/integration/tmp/sandbox-0-14871485b9d8e028b7f1f97fb2d718416e12671f162cb7498b941b7eaa3245b7/generated/code/Magento/Store/Model/StoreManagerInterface/Proxy.php(119): Magento\TestFramework\Store\StoreManager->getStore(NULL)
#7 app/code/Magento/Store/Model/Resolver/Store.php(30): Magento\Store\Model\StoreManagerInterface\Proxy->getStore(NULL)
#8 lib/internal/Magento/Framework/App/Config/ScopeCodeResolver.php(49): Magento\Store\Model\Resolver\Store->getScope(NULL)
#9 dev/tests/integration/framework/Magento/TestFramework/App/Config.php(80): Magento\Framework\App\Config\ScopeCodeResolver->resolve('stores', NULL)
#10 dev/tests/integration/framework/Magento/TestFramework/App/MutableScopeConfig.php(50): Magento\TestFramework\App\Config->setValue('customer/passwo...', 0, 'stores', NULL)
#11 dev/tests/integration/framework/Magento/TestFramework/Config.php(38): Magento\TestFramework\App\MutableScopeConfig->setValue('customer/passwo...', 0, 'store')
#12 dev/tests/integration/framework/Magento/TestFramework/Application.php(468): Magento\TestFramework\Config->rewriteAdditionalConfig()
#13 dev/tests/integration/framework/bootstrap.php(95): Magento\TestFramework\Application->initialize(Array)
#14 vendor/phpunit/phpunit/src/Util/FileLoader.php(65): include_once('/Users/Pro...')
#15 vendor/phpunit/phpunit/src/Util/FileLoader.php(49): PHPUnit\Util\FileLoader::load('/Users/Pro...')
#16 vendor/phpunit/phpunit/src/TextUI/Command.php(562): PHPUnit\Util\FileLoader::checkAndLoad('/Users/Pro...')
#17 vendor/phpunit/phpunit/src/TextUI/Command.php(344): PHPUnit\TextUI\Command->handleBootstrap('/Users/Pro...')
#18 vendor/phpunit/phpunit/src/TextUI/Command.php(111): PHPUnit\TextUI\Command->handleArguments(Array)
#19 vendor/phpunit/phpunit/src/TextUI/Command.php(96): PHPUnit\TextUI\Command->run(Array, true)
#20 vendor/phpunit/phpunit/phpunit(92): PHPUnit\TextUI\Command::main()
#21 {main}
snez commented 3 years ago

It turns out in my case I had to change from:

<const name="TESTS_CLEANUP" value="true"/>

to:

<const name="TESTS_CLEANUP" value="enabled"/>

I also deleted all database tables, deleted the caches from dev/tests/integration/tmp/*, and ran phpunit once with no parameters:

cd dev/tests/integration
../../../vendor/bin/phpunit

This rebuilt a clean database.