google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.25k stars 290 forks source link

Enhance simulating AMP context in PHP tests #2123

Closed aaemnnosttv closed 4 years ago

aaemnnosttv commented 4 years ago

Feature Description

Currently, a number of features and behaviors are AMP-specific and rely on logic implemented in the Context class for determining the AMP context and mode.

In PHP tests, this has been less than ideal to handle and requires us mocking a dummy object with stubbed responses to is_amp method calls. Because classes under test still need to be instantiated with a real Context instance, we need to do that first and then force-set the private context property with the dummy instance. This is problematic because any internally instantiated classes will have the Context instance that was passed in the constructor rather than the fake one.

This is all overly complicated simply because Context is defined as final which it has been since the initial release and prevents us from using a simple sub-class for use in tests. This is unnecessarily restrictive as nearly our entire PHP codebase is intended to be private so anyone who might be extending this class would be "doing it wrong" so we shouldn't need to protect developers from taking risks that they shouldn't.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

Test Coverage

Visual Regression Changes

QA Brief

Changelog entry

felixarntz commented 4 years ago

IB βœ… πŸ˜„

aaemnnosttv commented 4 years ago

@felixarntz I've updated the ACs here to be less implementation-specific and accommodate the changes we agreed on in #2125 while preserving the original purpose of the issue.

tofumatt commented 4 years ago

QA βœ