Request: control Strict Mode per test

Đang mở
#249 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

@BrianHenryIE đang làm issue này rồi.

Từ ngày 16/1/2026.

  • #265 của @BrianHenryIE — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
php
Lĩnh vực
testing

Hướng nghiên cứu

Bắt đầu trong php/WP_Mock.php bằng cách đọc activateStrictMode() và strictMode(), sau đó kiểm tra các lệnh gọi strict mode trong WP_Mock/Hook.php và WP_Mock/Functions/Handler.php. Xem lại TestCase::setUp() và FeatureContext::forceStrictModeOn() để hiểu hành vi reset. Được xem là hoàn tất khi từng test có thể kiểm soát strict mode mà không làm trạng thái đó rò rỉ sang các test khác, với coverage cho hành vi được yêu cầu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Feature request

Currently, in my bootstrap.php I typically use WP_Mock::activateStrictMode().

I would like to disable strict mode for some tests, in particular where I use WP_Mock::expectActionAdded(). Often, a function that adds one action adds many, but I will only be interested in testing that one add_action() I've most recently added.

With strict mode on, other add_action/add_filter calls without their corresponding WP_Mock::expectActionAdded() result in:

Unexpected use of add_action for action init with callback BrianHenryIE\Example::init
Proposed solution

Add a public setter on WP_Mock::$__strict_mode() that can be used during individual tests, then in TestCase::setUp() reset strict mode to the configured/default value.

WP_Mock::activateStrictMode() only allows setting it before boostrap, and the documentation says it has to be enabled before bootstrap, but WP_Mock::strictMode() is only actually used in one, two places that don't read to me like it would matter.

The feature tests are already enabling/disabling it as desired in FeatureContext::forceStrictModeOn().

Ngôn ngữ chính
PHP
Star
714
Fork
72
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của 10up/wp_mock

Tất cả issue của 10up/wp_mock

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.