Skip to content

Commit

Permalink
Fix SMOKE_TESTING_ROUTES_METHODS's behavior and disable custom consta…
Browse files Browse the repository at this point in the history
…nt usage
  • Loading branch information
Pierstoval committed Dec 30, 2024
1 parent a346b8d commit 35a42ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v1.1.0

* **BC break**: Disable possibility to use an `E_USER_*` constant in `SMOKE_TESTING_ROUTES_METHODS`.
* Fix `SMOKE_TESTING_ROUTES_METHODS`'s inconsistent configuration.

## v1.0.2

* Fix Routes extractor not providing proper naming for the test argument
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In the world of web development, smoke testing is often about opening all pages

Another **really important** use of smoke testing is when you work on big legacy projects that have no tests and/or no documentation.<br>
Running basic smoke testing (like when using this library) **comes with a very low cost** and can **check the whole project's average health**.<br>
Plus, adding **manual testing** (see the [Smoke-test routes manually](#smoke-test-routes-manually) section) allows you to have **more control** and more **advanced settings** for your tests (such as adding HTTP headers, making expectations on page content, etc.).
Plus, adding **manual testing** (see the [Smoke-test routes manually](#-smoke-test-routes-manually) section) allows you to have **more control** and more **advanced settings** for your tests (such as adding HTTP headers, making expectations on page content, etc.).

## Installation

Expand Down Expand Up @@ -103,11 +103,10 @@ If you do not want to trigger deprecations, you can customize the contents of th

##### Customizing the `SMOKE_TESTING_ROUTES_METHODS` environment variable

| Values | Effect |
|--------|--------|
| `no`, `false`, `disabled`, `0` | Disables the behavior |
| A constant starting with `E_USER_` | The `trigger_error` function will trigger an error based on the constant name you specify |
| Env var not set, or any non-empty value | Triggers a `E_USER_DEPRECATED` error. |
| Values | Effect |
|--------------------------------|---------------------------------------|
| Not set, or a non-empty value | Triggers a `E_USER_DEPRECATED` error. |
| `no`, `false`, `disabled`, `0` | Does not trigger deprecation error. |


### 🔬 Smoke test routes **manually**
Expand Down
10 changes: 6 additions & 4 deletions src/RoutesExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public static function extractRoutesFromRouter(RouterInterface $router): \Genera
if (!$methods) {
$errorMode = $_SERVER['SMOKE_TESTING_ROUTES_METHODS'] ?? $_ENV['SMOKE_TESTING_ROUTES_METHODS'] ?? getenv('SMOKE_TESTING_ROUTES_METHODS') ?: 'true';

if (!empty($errorMode) && 'false' !== $errorMode && 'no' !== $errorMode && '0' !== $errorMode && 'disabled' !== $errorMode) {
$mustTriggerError = match (\strtolower($errorMode)) {
'no', 'false', 'off', 'disabled', '0' => false,
default => true,
};

if ($mustTriggerError) {
$errorType = E_USER_DEPRECATED;
if (str_starts_with($errorMode, 'E_USER_')) {
$errorType = constant($errorMode);
}
$message = sprintf('Route "%s" has no configured HTTP methods. It is recommended that you set at least one HTTP method for your route in its configuration.', $routeName);
trigger_error($message, $errorType);
}
Expand Down

0 comments on commit 35a42ae

Please sign in to comment.