PHPackages                             matt-czerner/http-smoke-testing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. matt-czerner/http-smoke-testing

ActiveLibrary[Testing &amp; Quality](/categories/testing)

matt-czerner/http-smoke-testing
===============================

HTTP smoke test case for testing all configured routes in your Symfony project

10.0.1(6y ago)05.0kMITPHPPHP ^7.2

Since May 23Pushed 6y agoCompare

[ Source](https://github.com/MattCzerner/http-smoke-testing)[ Packagist](https://packagist.org/packages/matt-czerner/http-smoke-testing)[ RSS](/packages/matt-czerner-http-smoke-testing/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (8)Versions (78)Used By (0)

Shopsys HTTP Smoke Testing
==========================

[](#shopsys-http-smoke-testing)

[![Build Status](https://camo.githubusercontent.com/3b5333ee8d22fe950747d38b16d7cbad8950d7e965a3bf5795347537222aa978/68747470733a2f2f7472617669732d63692e6f72672f73686f707379732f687474702d736d6f6b652d74657374696e672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/shopsys/http-smoke-testing)[![Downloads](https://camo.githubusercontent.com/930c9fc8d979f689b9557effe96c3e5006258a51f0cef1fcae9b17af61ad10d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73686f707379732f687474702d736d6f6b652d74657374696e672e737667)](https://packagist.org/packages/shopsys/http-smoke-testing)

This package enables you to do simple HTTP smoke testing of your Symfony application.

Basically, it generates a HTTP request for every page (controller action) provided by the application router and then asserts that the returned HTTP response code is correct.

While this is not a very sophisticated check, it can answer the essential question *"does it run?"*. It prevents you from triggering *500 Server Error* on some seemingly unrelated page when you are doing changes in shared code. Moreover, after initial configuration it is almost maintenance-free as it checks any new routes automatically.

This repository is maintained by shopsys/shopsys monorepo, information about changes is in [monorepo CHANGELOG.md](https://github.com/shopsys/shopsys/blob/master/CHANGELOG.md).

Installation
------------

[](#installation)

Add the package to `require-dev` in your application:

```
composer require --dev shopsys/http-smoke-testing

```

This package internally uses [PHPUnit](https://phpunit.de/) to run the tests. That means that you need to setup your `phpunit.xml` properly. Fortunately, Symfony comes with example configuration. Renaming the `phpunit.xml.dist` in your project root (or `app/phpunit.xml.dist` on Symfony 2) should be sufficient.

*Note: If you did not find the file in your project check out the example in [Symfony Standard Edition](https://github.com/symfony/symfony-standard).*

Usage
-----

[](#usage)

Create [new PHPUnit test](https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html) extending [`\Shopsys\HttpSmokeTesting\HttpSmokeTestCase`](./src/HttpSmokeTestCase.php) class and implement `customizeRouteConfigs` method.

You can run your new test by:

```
php vendor/bin/phpunit tests/AppBundle/Smoke/SmokeTest.php

```

(or `php bin/phpunit -c app/phpunit.xml src/AppBundle/Tests/Smoke/SmokeTest.php` on Symfony 2)

**Warning: This package checks all routes by making real requests.****It is important not to execute it on production data.****You may unknowingly delete or modify your data or real requests on 3rd party services.**Even if you implement some way of protecting the application from side-effect (eg. database transaction wrapping) you should never execute tests on production data.

### Example test class

[](#example-test-class)

```
namespace Tests\AppBundle\Smoke;

use Shopsys\HttpSmokeTesting\Auth\BasicHttpAuth;
use Shopsys\HttpSmokeTesting\HttpSmokeTestCase;
use Shopsys\HttpSmokeTesting\RouteConfig;
use Shopsys\HttpSmokeTesting\RouteConfigCustomizer;
use Shopsys\HttpSmokeTesting\RouteInfo;
use Symfony\Component\HttpFoundation\Request;

class SmokeTest extends HttpSmokeTestCase {
    /**
     * @param \Shopsys\HttpSmokeTesting\RouteConfigCustomizer $routeConfigCustomizer
     */
    protected function customizeRouteConfigs(RouteConfigCustomizer $routeConfigCustomizer)
    {
        $routeConfigCustomizer
            ->customize(function (RouteConfig $config, RouteInfo $info) {
                // This function will be called on every RouteConfig provided by RouterAdapter
                if ($info->getRouteName()[0] === '_') {
                    // You can use RouteConfig to change expected behavior or skip testing particular routes
                    $config->skipRoute('Route name is prefixed with "_" meaning internal route.');
                }
            })
            ->customizeByRouteName('acme_demo_secured_hello', function (RouteConfig $config, RouteInfo $info) {
                // You can customize RouteConfig to use authentication for secured routes
                $config->changeDefaultRequestDataSet('Log in as "user".')
                    ->setAuth(new BasicHttpAuth('user', 'userpass'));
            });
    }

    /**
     * @param \Symfony\Component\HttpFoundation\Request $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function handleRequest(Request $request)
    {
        $entityManager = self::$kernel->getContainer()->get('doctrine.orm.entity_manager');

        // Enclose request handling in rolled-back database transaction to prevent side-effects
        $entityManager->beginTransaction();
        $response = parent::handleRequest($request);
        $entityManager->rollback();

        return $response;
    }
}
```

Documentation
-------------

[](#documentation)

By default the test makes request to every route without using any authentication or providing any parameters and expects the response to have HTTP status code *200 OK*.

To change this behavior you must implement method `customizeRouteConfigs(RouteConfigCustomizer $routeConfigCustomizer)` in your test.

[`RouteConfigCustomizer`](./src/RouteConfigCustomizer.php) provides two methods for customizing individual route requests:

- `customize` accepts callback `function (RouteConfig $config, RouteInfo $info) {...}` as the only argument. This is called with each [`RouteConfig`](./src/RouteConfig.php) along with [`RouteInfo`](./src/RouteInfo.php) collected from your router.
    This method is useful when you want to define general rules for multiple routes (eg. skip all routes with name starting with underscore).
- `customizeByRouteName` accepts a single route name or an array of route names as the first argument and same callback as `customize` as the second argument. This is called with each [`RouteConfig`](./src/RouteConfig.php) along with [`RouteInfo`](./src/RouteInfo.php) with matching route name. If matching route config is not found a [`RouteNameNotFoundException`](./src/Exception/RouteNameNotFoundException.php) is thrown.
    This method is useful when you want to define rules for specific routes (eg. logging in to some secured route).

In your customizing callback you can call three methods on [`RouteConfig`](./src/RouteConfig.php) to change the tested behavior:

- `skipRoute` can be called to skip this route during test.
- `changeDefaultRequestDataSet` is the main method for configuring routes. It returns [`RequestDataSet`](./src/RequestDataSet.php) object offering the setters needed to change the actual behavior:
    - `setExpectedStatusCode` changes the expected response HTTP status code that will be asserted.
    - `setAuth` changes the authentication method for the route. (Use [`NoAuth`](./src/Auth/NoAuth.php) for anonymous access, [`BasicHttpAuth`](./src/Auth/BasicHttpAuth.php) for logging in via basic http headers or implement your own method using [`AuthInterface`](./src/Auth/AuthInterface.php).)
    - `setParameter` specifies value of a route parameter by name.
    - `addCallDuringTestExecution` adds a callback `function (RequestDataSet $requestDataSet, ContainerInterface $container) { ... }` to be called before test execution.
        (Useful for code that needs to access the same instance of container as the test method, eg. adding CSRF token as a route parameter)
- `addExtraRequestDataSet` can be used to test more requests on the same route (eg. test a secured route as both logged in and anonymous user). Returns [`RequestDataSet`](./src/RequestDataSet.php) that you can use the same way as the result from `changeDefaultRequestDataSet`. All configured options will extend the values from default request data set (even when you change the default [`RequestDataSet`](./src/RequestDataSet.php) after you add the extra [`RequestDataSet`](./src/RequestDataSet.php)).

*Note: All three methods of [`RouteConfigCustomizer`](./src/RouteConfigCustomizer.php) accept `string $debugNote` as an argument.**It is useful for describing the reasons of your configuration change because it may help you with debugging when the test fails.*

Additionally you can override these methods in your implementation of [`HttpSmokeTestCase`](./src/HttpSmokeTestCase.php) to further change the test behavior:

- `setUp` to change the way your kernel is booted (eg. boot it with different options).
- `getRouterAdapter` to change the object responsible for collecting routes from your application and generating urls.
- `createRequest` if you have specific needs about the way `Request` is created from [`RequestDataSet`](./src/RequestDataSet.php).
- `handleRequest` to customize handling `Request` in your application (eg. you can wrap it in database transaction to roll it back into original state).

### Annotations

[](#annotations)

To make smoke test configuration a little easier, you can use the annotations:

#### DataSet

[](#dataset)

Used for setting expected status code based on provided paramteters.

```
@DataSet(statusCode=404, parameters={
    @Parameter(name="name", value="Batman")
})

```

- arguments:
    - `parameters` *(optional)*
    - `statusCode` *(optional, default = `200`)*

#### Parameter

[](#parameter)

Parameter defines value for specified parameter.

```
@Parameter(name="name", value="Batman")

```

- arguments:
    - `name` *(required)*
    - `value` *(required)*

#### Skipped

[](#skipped)

Mark test as skipped

```
@Skipped()

```

You can add them directly to your controller methods. See the example in [`Shopsys\HttpSmokeTesting\Test\TestController`](./src/Test/TestController.php).

*Note: You should avoid using annotations with configuring via `changeDefaultRequestDataSet()` on same route. It may result in unexpected behavior.*

Troubleshooting
---------------

[](#troubleshooting)

### Tests do not fail on non-existing route

[](#tests-do-not-fail-on-non-existing-route)

PHPUnit by default does not fail on warnings. Setting `failOnWarning="true"` in `phpunit.xml` fixes this problem.

Contributing
------------

[](#contributing)

Thank you for your contributions to Shopsys HTTP Smoke Testing package. Together we are making Shopsys Framework better.

This repository is READ-ONLY. If you want to [report issues](https://github.com/shopsys/shopsys/issues/new) and/or send [pull requests](https://github.com/shopsys/shopsys/compare), please use the main [Shopsys repository](https://github.com/shopsys/shopsys).

Please, check our [Contribution Guide](https://github.com/shopsys/shopsys/blob/master/CONTRIBUTING.md) before contributing.

Support
-------

[](#support)

What to do when you are in troubles or need some help? Best way is to contact us on our Slack

If you want to [report issues](https://github.com/shopsys/shopsys/issues/new), please use the main [Shopsys repository](https://github.com/shopsys/shopsys).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Recently: every ~63 days

Total

34

Last Release

2239d ago

Major Versions

v1.1.0 → v7.0.0-alpha12018-04-12

v7.3.0 → 8.0.x-dev2019-06-24

v7.3.2 → v8.0.02019-07-30

v8.0.0 → 9.0.x-dev2019-12-13

9.0.x-dev → 10.0.02020-01-10

PHP version history (2 changes)v7.0.0-alpha1PHP ^5.6|^7.0

8.0.x-devPHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f79080dc751ac325f564d38d0f9d7199c3607f93b94a2f70aaf868556a9ce42?d=identicon)[MattCzerner](/maintainers/MattCzerner)

---

Top Contributors

[![PetrHeinz](https://avatars.githubusercontent.com/u/10008612?v=4)](https://github.com/PetrHeinz "PetrHeinz (49 commits)")[![vitek-rostislav](https://avatars.githubusercontent.com/u/10401898?v=4)](https://github.com/vitek-rostislav "vitek-rostislav (25 commits)")[![grossmannmartin](https://avatars.githubusercontent.com/u/1177414?v=4)](https://github.com/grossmannmartin "grossmannmartin (17 commits)")[![TomasLudvik](https://avatars.githubusercontent.com/u/5638367?v=4)](https://github.com/TomasLudvik "TomasLudvik (16 commits)")[![miroslav2stopka](https://avatars.githubusercontent.com/u/35224208?v=4)](https://github.com/miroslav2stopka "miroslav2stopka (5 commits)")[![boris-brtan](https://avatars.githubusercontent.com/u/39240194?v=4)](https://github.com/boris-brtan "boris-brtan (3 commits)")[![OndraM](https://avatars.githubusercontent.com/u/793041?v=4)](https://github.com/OndraM "OndraM (3 commits)")[![malyMiso](https://avatars.githubusercontent.com/u/2991752?v=4)](https://github.com/malyMiso "malyMiso (2 commits)")[![msshopsys](https://avatars.githubusercontent.com/u/128610012?v=4)](https://github.com/msshopsys "msshopsys (1 commits)")[![LukasHeinz](https://avatars.githubusercontent.com/u/33071107?v=4)](https://github.com/LukasHeinz "LukasHeinz (1 commits)")[![mariusbuescher](https://avatars.githubusercontent.com/u/4403491?v=4)](https://github.com/mariusbuescher "mariusbuescher (1 commits)")[![sustmi](https://avatars.githubusercontent.com/u/885946?v=4)](https://github.com/sustmi "sustmi (1 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (1 commits)")[![Miroslav-Stopka](https://avatars.githubusercontent.com/u/35930284?v=4)](https://github.com/Miroslav-Stopka "Miroslav-Stopka (1 commits)")[![MattCzerner](https://avatars.githubusercontent.com/u/16896425?v=4)](https://github.com/MattCzerner "MattCzerner (1 commits)")

---

Tags

testingphpunitsymfonyroutingsmoke testing

### Embed Badge

![Health badge](/badges/matt-czerner-http-smoke-testing/health.svg)

```
[![Health](https://phpackages.com/badges/matt-czerner-http-smoke-testing/health.svg)](https://phpackages.com/packages/matt-czerner-http-smoke-testing)
```

###  Alternatives

[shopsys/http-smoke-testing

HTTP smoke test case for testing all configured routes in your Symfony project

68258.7k1](/packages/shopsys-http-smoke-testing)[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[matthiasnoback/symfony-config-test

Library for testing user classes related to the Symfony Config Component

1679.8M395](/packages/matthiasnoback-symfony-config-test)[lchrusciel/api-test-case

Perfect PHPUnit TestCase for JSON/XML API TDD with Symfony.

4115.5M63](/packages/lchrusciel-api-test-case)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
