# Middleware on CakePHP

**URL:** <https://discourse.cakephp.org/t/middleware-on-cakephp/1273>\
**Category:** Need Help\
**Created:** [October 2, 2016, 7:32pm UTC](https://discourse.cakephp.org/t/middleware-on-cakephp/1273 "2016-10-02T19:32:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![michimawan](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@michimawan](https://discourse.cakephp.org/u/michimawan)\
**Post date:** [October 2, 2016, 7:32pm UTC](https://discourse.cakephp.org/t/middleware-on-cakephp/1273/1 "2016-10-02T19:32:59Z")

</div>

hi, i want to ask question about middleware on cakephp. Because i want to take out isAuthorize from my controller, i’m wanting to put it on middleware.  
i’ve create the usermiddleware, and it can read the request and the session when i open the page on browser.

my question is, my unit testing in controller which has set the session is not readed on middleware, i’ve also do Session::write on unit test, it still can’t read on middleware,

to sum it: how can i make unit test for middleware which read session?  
thx in advance
