We could use more test coverage for this module. There are a lot of users, a lot of configuration options, and a lot of open issues.

To start, the existing tests could use some TLC. I'd like to start with the kernel test EasyBreadcrumbBuilderTest.

  • Consolidate duplicated code
  • Remove calls to \Drupal

This should reduce the file by about 100 lines and improve readability.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

loopduplicate created an issue. See original summary.

loopduplicate’s picture

Assigned: loopduplicate » Unassigned
Status: Active » Needs review

csakiistvan’s picture

Assigned: Unassigned » csakiistvan
csakiistvan’s picture

Assigned: csakiistvan » Unassigned
Status: Needs review » Reviewed & tested by the community

Environment

  • Drupal: 11.4.4
  • PHP: 8.5.5
  • Database: MariaDB 10.11.16
  • DDEV: v1.25.2
  • Easy Breadcrumb: 2.x-dev (base commit da98433)

Prerequisites

  • A Drupal 11 site with Easy Breadcrumb installed from the 2.x branch.
  • This is a test-only refactor, so there is nothing to reproduce in the UI. Verification is a kernel test run plus a coding standards run, before and after the change.
  • Record the baseline on unpatched 2.x:
ddev exec 'cd /var/www/html/web && ../vendor/bin/phpunit -c core/phpunit.xml.dist modules/contrib/easy_breadcrumb/tests/src/Kernel/EasyBreadcrumbBuilderTest.php'
ddev exec 'cd /var/www/html && vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php web/modules/contrib/easy_breadcrumb/tests/src/Kernel/EasyBreadcrumbBuilderTest.php'
  • Baseline results: 12 tests / 112 assertions passing; file is 409 lines; phpcs reports 5 errors and 2 warnings.

Steps

  1. Apply the fix from MR !179: consolidate the duplicated EasyBreadcrumbBuilder construction into a shared helper, add helpers for building and asserting the custom-path breadcrumb, and replace all static \Drupal:: calls with $this->container->get().
  2. Rebuild caches: ddev drush cr
  3. Re-run the kernel test with the same command used for the baseline and compare the test and assertion counts.
  4. Re-run phpcs with the same command used for the baseline and compare the error and warning counts.
  5. Compare the line count of tests/src/Kernel/EasyBreadcrumbBuilderTest.php against the baseline.

Expected results

  • The kernel test still passes with an unchanged number of tests and assertions, confirming the refactor preserves coverage.
  • The file is roughly 100 lines shorter.
  • No remaining static \Drupal:: calls in the test file.
  • No coding standards violations.

Actual results

The refactor achieves its goals. The kernel test still passes with exactly the same coverage as before (12 tests, 112 assertions, unchanged deprecation counts), the file shrinks from 409 to 310 lines (99 lines removed, matching the roughly 100 lines predicted in the issue summary), and all 140 lines containing static \Drupal:: calls are gone. The consolidation into getEasyBreadcrumbBuilder(), getBreadcrumbByCustomRoute() and assertCustomPath() is a clear readability win.

Two problems were found in the first round of testing, at commit 3bd0fa9, and have since been fixed on the branch:

  • The refactor introduced a duplicated semicolon at two sites — $router = $this->container->get('router.no_access_checks');; — pushing phpcs from 5 errors / 2 warnings up to 7 errors / 4 warnings. This was visible on the MR pipeline too: the phpcs job failed on pipeline 901101, and only avoided turning the pipeline red because that job is configured with allow_failure: true.
  • The four new docblocks used malformed type references: @param Drupal\Core\Routing\RequestContextRequestContext $request_context (duplicated class name), plus @param/@return types written without a leading backslash, so none of them resolved.

Both were corrected in commit 281803e. A follow-up commit 1051c64 also cleared the 5 errors and 2 warnings that pre-dated this issue in the same file (docblock indentation, a summary line over 80 characters, and two lowercase true literals), so the file is now fully clean.

Final state on the branch: phpcs reports no errors and no warnings, and the kernel test passes with 12 tests and 112 assertions — identical coverage to the baseline.


Testing produced with the assistance of an LLM.

  • loopduplicate committed 6032104f on 2.x
    task: #3612936 Tidy up EasyBreadcrumbBuilderTest
    
    By: loopduplicate
    By:...
loopduplicate’s picture

Status: Reviewed & tested by the community » Fixed

thank you @csakiistvan

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

csakiistvan’s picture

Welcome @loopduplicate :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.