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

[3.x]: Error running codeception Acceptance tests with module setting in config/app.php #12088

Closed
yoannisj opened this issue Oct 11, 2022 · 6 comments
Assignees

Comments

@yoannisj
Copy link

yoannisj commented Oct 11, 2022

What happened?

Description

Running Codeception acceptance tests with modules defined in config/app.php throws error [TypeError] get_class(): Argument #1 ($object) must be of type object, string given.

To make sure this is not an issue with my project's module configuration, I tried with a fresh Craft-CMS 3.7 install, and could reproduce the error.

Steps to reproduce

  1. Get a fresh Craft-CMS 3.7 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 run composer require codeception/module-yii2:^1.1 --dev first
  4. Add an example Acceptance test in tests/acceptance/ExampleCest.php like so:
<?php
namespace yournamespace\tests\acceptance;

class ExampleCest
{
    public function testExample( \AcceptanceTester $I )
    {
        // when
        $I->amOnPage('/admin/login');

        // then
        $I->seeInTitle('Login');
    }
}
  1. run php vendor/bin/codecept run acceptance

Expected behavior

The acceptance test should run and pass.

Actual behavior

The [TypeError] get_class(): Argument #1 ($object) must be of type object, string given error is thrown.

The [TypeError] get_class(): Argument #1 ($object) must be of type object, array given error is thrown if I define the module as an array in tests/_craft/config/app.php:

   'modules' => [
       'my-module' => [ 'class' => \modules\Module::class ],
   ],

The test runs and passes if I comment out the 'modules' setting altogether in tests/_craft/config/app.php.

Craft CMS version

3.7.55.3

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

  • Element API 2.8.6.1
  • codeception/codeception 4.2.2
  • codeception/module-yii2 1.1.5
  • codeception/module-asserts 1.3.1
  • codeception/module-phpbrowser 1.0.3
@yoannisj
Copy link
Author

yoannisj commented Oct 11, 2022

I just followed the steps above on a Craft 4.2 installation, and confirm this is also happening for Craft-CMS 4.x.
I just opened a corresponding bug issue for 4.x, hope that was the right thing to do: #12090

@brianjhanson
Copy link
Contributor

@yoannisj do you have the bootstrap line in your app.php file within the _tests folder?

The full file should look similar to the following

<?php

use craft\helpers\App;

return [
    'id' => App::env('APP_ID') ?: 'CraftCMS',
    'modules' => [
        'my-module' => \modules\Module::class,
    ],
    'bootstrap' => ['my-module'],
];

That being said, not including bootstrap in there shouldn't break things (because it doesn't break a normal install). I've opened a PR to address that piece.

@yoannisj
Copy link
Author

yoannisj commented Oct 11, 2022

@brianjhanson , no I removed the 'bootstrap' => [ 'my-module' ] line.

Yes, it does not throw an error in a normal install, and I also figured that one might want to define/configure a module that gets loaded inside a test without bootstrapping it.

@brianjhanson
Copy link
Contributor

@yoannisj just wanted to note if you add back the bootstrap line things should work until #12093 is merged and released. The change over there is super simple so you can also patch it yourself for the time being.

@brandonkelly
Copy link
Member

This is fixed for the next Craft 3 and 4 releases, via #12093.

@brandonkelly
Copy link
Member

Craft 3.7.57 and 4.2.8 are out now with the fix. Thanks again!

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