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

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

Closed
yoannisj opened this issue Oct 11, 2022 · 1 comment · Fixed by #12091
Closed
Assignees

Comments

@yoannisj
Copy link

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

  • codeception/codeception 4.2.2
  • codeception/module-yii2 1.1.5
  • codeception/module-asserts 1.3.1
  • codeception/module-phpbrowser 1.0.3
@brianjhanson brianjhanson self-assigned this Oct 11, 2022
@yoannisj yoannisj changed the title [4.x]: Uncaught Error: Call to a member function getConfig() on null running Codeception tests [4.x]: Codeception throws Uncaught Error: Call to a member function getConfig() on null Oct 12, 2022
@brandonkelly
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants