PHPackages                             mroca/request-log-bundle - 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. mroca/request-log-bundle

ActiveSymfony-bundle[Testing &amp; Quality](/categories/testing)

mroca/request-log-bundle
========================

An HTTP requests mock generator symfony bundle.

v0.1.6(10y ago)33.9k2MITPHPPHP &gt;=5.5.0

Since Jan 5Pushed 10y agoCompare

[ Source](https://github.com/mRoca/MrocaRequestLogBundle)[ Packagist](https://packagist.org/packages/mroca/request-log-bundle)[ Docs](https://github.com/mRoca/MrocaRequestLogBundle)[ RSS](/packages/mroca-request-log-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (8)Used By (0)

MrocaRequestLogBundle
=====================

[](#mrocarequestlogbundle)

An HTTP requests mock generator symfony bundle.

[![Build Status](https://camo.githubusercontent.com/0a0146c23126fde315bd016d7be6dec9e5ca40b9b058213220d0a13b197de807/68747470733a2f2f7472617669732d63692e6f72672f6d526f63612f4d726f6361526571756573744c6f6742756e646c652e737667)](https://travis-ci.org/mRoca/MrocaRequestLogBundle)[![SensioLabsInsight](https://camo.githubusercontent.com/e9f0d39e9651049bf8ad9d44f905424cccf707e0c04a5018a1df13b27a80f918/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f32346232643930372d306464632d343464352d396666352d3433376433643965366164382f6d696e692e706e67)](https://insight.sensiolabs.com/projects/24b2d907-0ddc-44d5-9ff5-437d3d9e6ad8)

Description
-----------

[](#description)

This bundle allows to log HTTP requests and associated responses as json files. This generated json files can be used as API mock in order to test a front app without running the api.

How it works ?
--------------

[](#how-it-works-)

After each request (`Kernel::TERMINATE` event) containing the `x-generate-response-mock` header, a json file is created containing the request and the response.

**Examples :**

> GET /categories

`app/log/mocks/categories/GET__.json`

```
{
    "request": {
        "uri": "/categories",
        "method": "GET",
        "parameters": [],
        "content": ""
    },
    "response": {
        "statusCode": 200,
        "contentType": "application/json",
        "content": {
            "@context": "/contexts/Category",
            "@id": "/categories",
            "hydra:member": [
                {"name": "foo"},
                {"name": "bar"}
            ]
        }
    }
}
```

> PUT /categories/1 {"foo": "bar"}

`app/log/mocks/categories/PUT__1-a5e74.json`

```
{
    "request": {
        "uri": "/categories/1",
        "method": "PUT",
        "parameters": [],
        "content": {
            "foo": "bar"
        }
    },
    "response": {
        "statusCode": 204,
        "contentType": "application/json",
        "content": ""
    }
}
```

**File naming strategy**

All files are created with the following convention :

`uri/METHOD__segments{--sorted-query=string&others}{__}{__}.json`

*Examples* :

URLFilenameGET /GET\_\_.jsonGET /categoriescategories/GET\_\_.jsonGET /categories/1categories/GET\_\_1.jsonGET /categories?search\[category\]\[\]=foocategories/GET\_\_--search%5Bcategory%5D%5B%5D=foo.jsonGET /categories?order\[foo\]=asc&amp;order\[bar\]=desccategories/GET\_\_--order%5Bbar%5D=desc&amp;order%5Bfoo%5D=asc.jsonGET /categories?parent=/my/iricategories/GET\_\_--parent=%2Fmy%2Firi.jsonPOST /categories PARAMS: foo1=bar1; foo2=bar2categories/POST\_\_\_\_3e038.jsonPOST /categories CONTENT: {"foo1":"bar1", "foo2":"bar2"}categories/POST\_\_\_\_3e038.jsonPUT /categories/1 CONTENT: {"foo2":"bar2", "foo1":"bar1"}categories/POST\_\_1\_\_3e038.json```
The filenames query strings can be hashed by setting the `hash_query_params` option to `true`.
For example, `categories/GET__--order[bar]=desc&order[foo]=asc.json` will be `categories/GET__--b0324.json`

The filenames query strings with non-asssocitive arrays are not indexed by default : `?foo[]=bar`.
You can use the indexed format by setting the `use_indexed_associative_array` option to `true` : `?foo[0]=bar`.

```

See the [ResponseLoggerTest](/Tests/Service/ResponseLoggerTest.php#L135) file for more examples.

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

[](#installation)

You can use [Composer](https://getcomposer.org/) to install the bundle to your project as a dev dependency :

```
composer require --dev mroca/request-log-bundle
```

Then, enable the bundle by updating your `app/config/AppKernel.php` file to enable the bundle:

```
