Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293926

KernelTestBaseTNG™

$
0
0

Mission

  1. Run all functional integration tests via PHPUnit.
  2. Convert KernelTestBase into a PHPUnit test base class.
  3. Add a second Kernel test suite, separate from the Unit test suite.

Why

  • Drupal should not be in the business of developing a testing framework.
  1. It will be possible that ~60% of Drupal's total test coverage is "rebased" onto PHPUnit, running entirely in memory.
  2. Many kernel tests should be refactored into pure unit tests. Now they already operate in PHPUnit. Major milestone.
  3. 2 of 3 test suites can be executed sans any Drupal [QA] infrastructure. → Proof.
  4. PHPUnit is much more strict regarding unintended errors than Simpletest. It prevents more bugs and thus improves software quality. Also, it cleanly isolates tests (if necessary).

How

  1. After 4 weeks of permanent work on porting KernelTestBase + fixing PHPUnit upstream, mission accomplished:

    OK (904 tests, 10081 assertions)
    Time: 14.04 minutes, Memory: 269.25Mb

    This work revealed many bogus tests in HEAD + fixes most remaining SQLite Database driver issues. (See Child issues.)

  2. Discuss whether to restructure PHPUnit test directories for discovery purposes:

    Test "type"    Location
    -------------- -------------------------------
    Unit           ./tests/src/Unit/*Test.php
    Kernel         ./tests/src/Kernel/*Test.php

    #2260121: PHPUnit Tests namespace of modules is ambiguous with regular runtime namespace (+ Simpletest tests)

    Based on that decision,

    1. Either move all kernel test files + adjust their namespace and use statements
    2. Or adjust the use statements only.
  3. Rebase, squash, and merge the final branch into Drupal core.

Technical overview

  1. Drop-in replacement for Drupal\simpletest\KernelTestBase.
  2. Operates entirely in memory; no artifacts. (vfsStream, sqlite::memory:)
  3. Highly optimized for performance.
  4. Leverages latest & greatest features of Drupal's dependencies. (PHPUnit, vfsStream, Psr\Log)
  5. Forward-compatible with PHPUnit 4.3.

API additions/changes

  1. New: Drupal\Tests\KernelTestBase
  2. New BC layer: Drupal\Tests\AssertLegacyTrait— to be removed before 8.0.0.

Drupal\simpletest\KernelTestBase remains unchanged — to be removed before 8.0.0.

Upgrading

  1. Use the new base class:
    -use Drupal\simpletest\KernelTestBase;
    +use Drupal\Tests\KernelTestBase;
  2. Ensure that all custom class properties are properly declared (and not overloaded).
  3. Run the test with --verbose (enabled by default) and check the test output, especially for deprecated warnings.

In 99% of all cases, step (1) is sufficient.

Dependencies

  1. Fix virtual filesystem: #2313989: Update vfsStream to 1.3.0
  2. Fix test class property overloading: #2306539: FieldUnitTestBase::createFieldWithInstance() pollutes test class with arbitrary properties
  3. Fix bogus tests: #2314123: Fix various tests
  4. Fix bogus ScriptTest: #2261477: Remove broken Drupal\system\Tests\ScriptTest
  5. Fix bogus theme calls + error reporting: #2301245: Entity system invokes non-existing theme hooks: "Theme hook $entity_type_id not found."
  6. Fix bogus Entity Query Aggregate test: #2315269: Entity/Query/Sql/QueryAggregate: PDOException: General error: GROUP BY clause is required before HAVING

Related issues

Change namespace for PHPUnit tests#2260121: PHPUnit Tests namespace of modules is ambiguous with regular runtime namespace (+ Simpletest tests)
Service Container self-reference breaks PHP GCsymfony/symfony#11422 (merged)
Fail upon unexpected severe log messages#652394: Aggressive watchdog message assertion (now built-in)
Use TestDiscovery in bootstrap.php#2301873: Use TestDiscovery to register test namespaces for running PHPUnit
Fix file discovery in phpunit.xml.dist
.
#2203747: Current PHPUnit configuration scans into contrib vendor dirs
#2287925: Profiles and themes can't contain PHPUnit tests
Views uses CONCAT_WS() but not supported#2427311: SQLite does not natively support CONCAT_WS()
Port @requires to Simpletest#1273478: Fully implement @requires and mark tests with unmet requirements as 'skipped'
Improve test @group annotations
.
.
#2297541: [policy, no patch] Secondary/additional test @group names
#2296615: Change Simpletest test listing UI to support multiple @groups per test class
#2301481: Remove duplicate test groups
Migrate Web tests to Mink + Guzzle#2232861: Create BrowserTestBase for web-testing on top of Mink

Full (rebased/polished) history: sun/drupal#2 + sun/drupal#1

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue categoryTask, because it enables an entire better world of testing
Issue priorityMajor because it improves the DX, removes fragility and is part of the general testing API overhaul
Unfrozen changesUnfrozen because it only changes tests.

Viewing all articles
Browse latest Browse all 293926

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>