Skip to content

v2.12.4

Choose a tag to compare

@ttsuru ttsuru released this 15 Oct 02:11
· 560 commits to 2.x since this release
v2.12.4
ae60c1f

Note

No behavior changes. This release adds the IntegrationTestTrait / EmailTrait backport for request-level controller tests (see UPGRADE.md) and fixes docblock types and flaky tests.

Integration Testing Backport (PR #51)

  • IntegrationTestTrait: New test trait, a backport of Cake\TestSuite\IntegrationTestTrait from CakePHP 5.x (src/TestSuite/IntegrationTestTrait.php) adapted to CakePHP 2. Dispatches requests through the real Dispatcher and captures the CakeResponse; usable from any test case (no ControllerTestCase needed)
    • Requests: get(), post(), put(), patch(), delete(), head(), options() with string URLs, full URLs or routing arrays, array data or a raw body
    • Setup: configRequest(), replaceRequest(), requestAsJson(), session(), cookie(), cookieEncrypted() (CookieComponent format), enableSecurityToken() / setUnlockedFields() (valid SecurityComponent _Token fields and CSRF token), enableCsrfToken(), enableRetainFlashMessages(), disableErrorHandlerMiddleware() (throw exceptions instead of rendering the error page)
    • Assertions on the status, redirect, headers, content type, body, template, layout, session, flash messages, cookies and sent files (assertResponseOk(), assertRedirect(), assertHeader(), assertResponseContains(), assertTemplate(), assertSession(), assertFlashMessage(), assertCookieEncrypted(), assertFileResponse(), ...), and viewVariable()
    • exit after a sent response (Controller::redirect(), AuthComponent, AssetDispatcher, redirect routes) is replaced by IntegrationTestStop, thrown by the test response IntegrationTestResponse; IntegrationTestDispatcher dispatches without sending the response
  • Constraints: PHPUnit constraints backported from src/TestSuite/Constraint (Response/*, Session/*, View/*, Email/*), named with a Constraint suffix (e.g. StatusOkConstraint, FlashParamEqualsConstraint, MailSentToConstraint)
  • EmailTrait / TestEmailTransport: Backport of src/TestSuite/EmailTrait.php and src/TestSuite/TestEmailTransport.php. Every CakeEmail sends with TestEmailTransport during the test, and assertMailCount(), assertNoMailSent(), assertMailSentTo(), assertMailSentFrom(), assertMailSentWith(), assertMailContains(), assertMailContainsText(), assertMailContainsHtml(), assertMailSubjectContains(), assertMailContainsAttachment() (and ...At() variants) check the captured emails
  • CakeEmail: New CakeEmail::overrideTransport($name) / CakeEmail::transportOverride() to make every instance use one transport (used by TestEmailTransport::replaceAllTransports()); no change unless called
  • CookieCryptTrait (TestSuite): Encrypts and decrypts values in the CookieComponent format, backport of Cake\Utility\CookieCryptTrait

Docblock Types (PR #49)

  • ErrorHandler / ExceptionRenderer: Document the $exception parameters of handleException(), _getMessage(), _log(), ExceptionRenderer::__construct() and _getController() as Throwable, matching what set_exception_handler() passes on PHP 8 (no behavior change)
  • View: Document $subDir as string|null (its default is null)
  • AclComponent: Document $Aro / $Aco as the ACL adapter's node objects (Aro|PhpAro|null / Aco|PhpAco|null) instead of string
  • Tests: Fix flaky testConfigurationConflict in MemcacheEngineTest / MemcachedEngineTest (one-second expiry granularity), and CakeTimeTest::testWasWithinLast / testTimeAgoInWords (the clock can tick between the relative input and "now")