# How to write Controller tests for actions requiring authentication?

**URL:** <https://discourse.laminas.dev/t/how-to-write-controller-tests-for-actions-requiring-authentication/2667>\
**Category:** Components & MVC\
**Tags:** laminas-test, laminas-authentication, laminas-permissions-acl\
**Created:** [December 24, 2021, 1:35pm UTC](https://discourse.laminas.dev/t/how-to-write-controller-tests-for-actions-requiring-authentication/2667 "2021-12-24T13:35:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koen1999](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/koen1999/32/1225_2.png) [@Koen1999](https://discourse.laminas.dev/u/Koen1999)\
**Post date:** [December 24, 2021, 1:35pm UTC](https://discourse.laminas.dev/t/how-to-write-controller-tests-for-actions-requiring-authentication/2667/1 "2021-12-24T13:35:46Z")

</div>

I haven’t been able to find any documentation regarding this while I think it is quite a common use case. Most websites have some form of authentication or access control and being able to test this could improve our workflow significantly.

I think one approach could be to mock our Authentication service, but this is also difficult given that it is retrieved through the service manager.

Did anyone implement a somewhat similar test in their open source repository that I can check out?
