workshop-drupal-automated-testing icon indicating copy to clipboard operation
workshop-drupal-automated-testing copied to clipboard

Latest PHP 7.4/Drupal 9 setup error

Open taviroquai opened this issue 4 years ago • 0 comments

Hi!,

I'm learning Drupal TDD and trying to follow this repo steps.

I've setup and following your steps, I just got an error in the step 1f.

Here is the error: PHP Fatal error: Uncaught Error: Class 'Drupal\Tests\BrowserTestBase' not found

It seems that it cannot load the correct Class => file path mapping.

This is my setup:

Windows 10 Environment C:\ php --version

PHP 7.4.13 (cli) (built: Nov 24 2020 12:43:30) ( NTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Project directories/files

vendor web composer.json composer.lock

composer.json

{
    "name": "drupal/recommended-project",
    "description": "Project template for Drupal 9 projects with a relocated document root",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "homepage": "https://www.drupal.org/project/drupal",
    "support": {
        "docs": "https://www.drupal.org/docs/user_guide/en/index.html",
        "chat": "https://www.drupal.org/node/314178"
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "composer/installers": "^1.9",
        "drupal/core-composer-scaffold": "^9",
        "drupal/core-project-message": "^9",
        "drupal/core-recommended": "^9"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "sort-packages": true
    },
    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },
        "installer-paths": {
            "web/core": [
                "type:drupal-core"
            ],
            "web/libraries/{$name}": [
                "type:drupal-library"
            ],
            "web/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "web/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "web/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/Commands/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "web/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "web/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ]
        },
        "drupal-core-project-message": {
            "include-keys": [
                "homepage",
                "support"
            ],
            "post-create-project-cmd-message": [
                "<bg=blue;fg=white>                                                         </>",
                "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",
                "<bg=blue;fg=white>  from the drupal/recommended-project template!          </>",
                "<bg=blue;fg=white>                                                         </>",
                "",
                "<bg=yellow;fg=black>Next steps</>:",
                "  * Install the site: https://www.drupal.org/docs/8/install",
                "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
                "  * Get support: https://www.drupal.org/support",
                "  * Get involved with the Drupal community:",
                "      https://www.drupal.org/getting-involved",
                "  * Remove the plugin that prints this message:",
                "      composer remove drupal/core-project-message"
            ]
        }
    },
    "require-dev": {
        "drupal/core-dev": "^9.0"
    }
}

Runing "php -S localhost:8000 -t web" is fine image

On step 1d it was complaining about class FrontPageTest was not implementing method "assertSession", so I changed the code to this:

<?php

namespace Drupal\Tests\my_module\Functional;

use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\WebAssert;
use Symfony\Component\HttpFoundation\Response;

class FrontPageTest extends BrowserTestBase {

  protected static $modules = ['node', 'views'];

  public function assertSession($name = NULL) {
    $this->addToAssertionCount(1);
    return new WebAssert($this->getSession($name), $this->baseUrl);
  }

  /** @test */
  public function the_front_page_loads_for_anonymous_users() {
    $this->config('system.site')
      ->set('page.front', '/node')
      ->save(TRUE);

    $this->drupalGet('<front>');

    $assert = $this->assertSession();
    $assert->statusCodeEquals(Response::HTTP_OK);
    $assert->pageTextContains('Welcome to Drupal');
    $assert->pageTextContains('No front page content has been created yet.');
  }

}

After step 1e, on step 1f, running ...

.\vendor\bin\phpunit .\web\modules\custom\my_module

...from root dir, I got this:

PHP Fatal error: Uncaught Error: Class 'Drupal\Tests\BrowserTestBase' not found in .\web\modules\custom\my_module\tests\src\Functional\FrontPageTest.php:9

Any help is appreciated! :) Thanks!

taviroquai avatar Dec 02 '20 01:12 taviroquai