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

Custom aliases not working with test framework #5932

Closed
mtwalsh opened this issue Apr 16, 2020 · 1 comment
Closed

Custom aliases not working with test framework #5932

mtwalsh opened this issue Apr 16, 2020 · 1 comment
Assignees

Comments

@mtwalsh
Copy link

mtwalsh commented Apr 16, 2020

Description

Custom aliases are not loaded from the general config when using the test framework.

Steps to reproduce

  1. Setup a test as per the Getting Started guide
  2. Run an acceptance test where the Twig template uses a custom alias and notice the following output:

[Twig\Error\RuntimeError] An exception has been thrown during the rendering of a template ("Invalid path alias: @aliasNameHere").

I seem to have been able to fix the issue by adding the following code:

        $configService = self::createConfigService();
        $generalConfig = $configService->getConfigFromFile('general');

        // Set any custom aliases
        $customAliases = $generalConfig['aliases'] ?? $generalConfig['environmentVariables'] ?? null;
        if (is_array($customAliases)) {
            foreach ($customAliases as $name => $value) {
                if (is_string($value)) {
                    Craft::setAlias($name, $value);
                }
            }
        }

Here:

https://github.com/craftcms/cms/blob/develop/src/test/TestSetup.php#L346

Additional info

  • Craft version: Craft Pro 3.3.20.1
  • PHP version: 7.3.14
  • Database driver & version: MySQL 5.7.28
@brandonkelly
Copy link
Member

Craft 3.4.20 is out now with this change.

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

No branches or pull requests

3 participants