craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

[4.x]: Codeception throws `Uncaught Error: Call to a member function getConfig() on null` #12089

Closed yoannisj closed 2 years ago

yoannisj commented 2 years ago

What happened?

Description

Using the return GeneralConfig::create(); syntax in tests/_craft/config/general.php throws an error when running Codeception tests on a fresh Craft-CSM 4.2 installation.

Steps to reproduce

  1. Get a fresh Craft-CMS 4.3 installation I downloaded the zip file from the Installation Instructions to get up and running inside a DDEV project.
  2. Install Codeception ^4.1 with composer require codeception/codeception:^4.1 --dev Codeception ^3.1 is not compatible with PHP 8, and I did not manage to setup Craft-CMS tests with Codeception ^5.0.
  3. Follow steps to Setup Tests for Craft-CMS from the documentation To run the example unit test (steps 4-5), I had to un composer require codeception/module-yii2:^1.1 --dev first

Expected behavior

The example test should run and pass.

Actual behavior

The Uncaught Error: Call to a member function getConfig() on null error is thrown.

After replacing the GeneralConfig::create(); syntax with the array syntax the tests/_craft/config/general.php, the test runs and passes:

<?php
use craft\helpers\App;

return [

    // Set the default week start day for date pickers (0 = Sunday, 1 = Monday, etc.)
    'defaultWeekStartDay' => 1,
    // Prevent generated URLs from including "index.php"
    'omitScriptNameInUrls' => true,
    // Enable Dev Mode (see https://craftcms.com/guides/what-dev-mode-does)
    'devMode' => App::env('DEV_MODE') ?? false,
    // Allow administrative changes
    'allowAdminChanges' => App::env('ALLOW_ADMIN_CHANGES') ?? false,
    // Disallow robots
    'disallowRobots' => App::env('DISALLOW_ROBOTS') ?? false,

];

Craft CMS version

4.2.7

PHP version

8.0.21

Operating system and version

Linux 5.10.124-linuxkit (DDEV v1.20.0)

Database type and version

MySQL 10.4.25 (MariaDB 10.4)

Image driver and version

Imagick 3.6.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

brandonkelly commented 2 years ago

Thanks for reporting! Craft 4.2.8 is out now with a fix, via #12091.