# Testing

**URL:** https://discourse.cakephp.org/c/testing/7.md

[Latest](https://discourse.cakephp.org/latest.md) · [Categories](https://discourse.cakephp.org/categories.md) · [Tags](https://discourse.cakephp.org/tags.md)

---

## [About the Testing category](https://discourse.cakephp.org/t/about-the-testing-category/22)

<div class="topic-metadata">

**Author:** [@markstory](https://discourse.cakephp.org/u/markstory)\
**Replies:** 1\
**Last updated:** [March 15, 2017, 9:53am UTC](https://discourse.cakephp.org/t/about-the-testing-category/22 "2017-03-15T09:53:45Z")

</div>

---

## [Composer 2.9 Issue](https://discourse.cakephp.org/t/composer-2-9-issue/12743)

<div class="topic-metadata">

**Author:** [@ed3](https://discourse.cakephp.org/u/ed3)\
**Replies:** 6\
**Last updated:** [December 4, 2025, 10:51am UTC](https://discourse.cakephp.org/t/composer-2-9-issue/12743 "2025-12-04T10:51:04Z")

</div>

Hello, I tested Cakephp 4.6.3 with composer 2.8.x which work correctly, but with composer 2.9 not work. Do you have any suggestions for the following message: Problem 1 Root composer.json requires cakephp/cakephp ^4.…

---

## [Elseif condition is explicitly a boolean true but doesn't evaluate as true](https://discourse.cakephp.org/t/elseif-condition-is-explicitly-a-boolean-true-but-doesnt-evaluate-as-true/12282)

<div class="topic-metadata">

**Author:** [@makamo66](https://discourse.cakephp.org/u/makamo66)\
**Replies:** 6\
**Last updated:** [October 23, 2024, 9:02am UTC](https://discourse.cakephp.org/t/elseif-condition-is-explicitly-a-boolean-true-but-doesnt-evaluate-as-true/12282 "2024-10-23T09:02:53Z")

</div>

I simply put elseif ( true ) {echo "Lorem ipsum dolor sit amet";} in my foreach loop and then expected the Latin statement to print but the condition never evaluates as true even though I explicitly set the condition to …

---

## [Session data in phpunittest](https://discourse.cakephp.org/t/session-data-in-phpunittest/12214)

<div class="topic-metadata">

**Author:** [@webdeveloper](https://discourse.cakephp.org/u/webdeveloper)\
**Replies:** 11\
**Last updated:** [September 3, 2024, 3:29pm UTC](https://discourse.cakephp.org/t/session-data-in-phpunittest/12214 "2024-09-03T15:29:20Z")

</div>

In my test controller, in a test action, I am setting the Auth.User session. $this-\>session(\['Auth' =\> \['User' =\> $user-\>toArray()\]\]); But in my Behavior I am not able to get the session data. When I print $\_SESSION\['…

---

## [Create test for pdf files](https://discourse.cakephp.org/t/create-test-for-pdf-files/12020)

<div class="topic-metadata">

**Author:** [@arodu](https://discourse.cakephp.org/u/arodu)\
**Replies:** 2\
**Last updated:** [May 17, 2024, 3:54am UTC](https://discourse.cakephp.org/t/create-test-for-pdf-files/12020 "2024-05-17T03:54:43Z")

</div>

What is the best way to create a test from a pdf file? I thought about using a predefined file, and then comparing it against the generated file, but it is not working for me. Although the content of the 2 files is the…

---

## [No code coverage driver available error - PHPUnit](https://discourse.cakephp.org/t/no-code-coverage-driver-available-error-phpunit/12008)

<div class="topic-metadata">

**Author:** [@webdeveloper](https://discourse.cakephp.org/u/webdeveloper)\
**Replies:** 2\
**Last updated:** [May 10, 2024, 5:48pm UTC](https://discourse.cakephp.org/t/no-code-coverage-driver-available-error-phpunit/12008 "2024-05-10T17:48:05Z")

</div>

I am on PHP 8.1. My App is on CakePHP 4.4 and have PHPUnit 9.6. When I try to generate the code coverage report I get ‘no code coverage driver available’ error. But I do have the built-in phpdbg. Isn’t this enough?

---

## [Cannot override final method assertDirectoryDoesNotExist error](https://discourse.cakephp.org/t/cannot-override-final-method-assertdirectorydoesnotexist-error/12007)

<div class="topic-metadata">

**Author:** [@webdeveloper](https://discourse.cakephp.org/u/webdeveloper)\
**Replies:** 3\
**Last updated:** [May 6, 2024, 8:06pm UTC](https://discourse.cakephp.org/t/cannot-override-final-method-assertdirectorydoesnotexist-error/12007 "2024-05-06T20:06:11Z")

</div>

Hello, I am on CakepHP 4.4. I upgraded my PHPUnit to 10 from 9 and now when i try to run the tests, I get the below error: \[PHP Fatal error: Cannot override final method PHPUnit\\Framework\\Assert::assertDirectoryDoesNot…

---

## [How to test variable from controller](https://discourse.cakephp.org/t/how-to-test-variable-from-controller/11827)

<div class="topic-metadata">

**Author:** [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Replies:** 4\
**Last updated:** [January 26, 2024, 3:15pm UTC](https://discourse.cakephp.org/t/how-to-test-variable-from-controller/11827 "2024-01-26T15:15:01Z")

</div>

I have function: /\*\* \* Password forgot method \* \* @return \\Cake\\Http\\Response|null|void Renders view \*/ public function passwordForgot() { $user = new UserPasswordForgotForm(); …

---

## [How to properly inject an association for a test](https://discourse.cakephp.org/t/how-to-properly-inject-an-association-for-a-test/11801)

<div class="topic-metadata">

**Author:** [@hakito](https://discourse.cakephp.org/u/hakito)\
**Replies:** 6\
**Last updated:** [January 13, 2024, 10:02pm UTC](https://discourse.cakephp.org/t/how-to-properly-inject-an-association-for-a-test/11801 "2024-01-13T22:02:47Z")

</div>

Hi! Can anyone tell me what is the intendend way to mock an association without getting a deprecation warning. In my TestSetup I load a Model like this: $this-\>Orders = $this-\>getTableLocator()-\>get('Orders'); In the…

---

## [PHPSTAN settings correctly](https://discourse.cakephp.org/t/phpstan-settings-correctly/11607)

<div class="topic-metadata">

**Author:** [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Replies:** 6\
**Last updated:** [November 21, 2023, 7:12am UTC](https://discourse.cakephp.org/t/phpstan-settings-correctly/11607 "2023-11-21T07:12:20Z")

</div>

Please advise how to set up PHPSTAN correctly? For example, this gives me errors. Function \_\_x not found. Method App\\Controller\\Component\\ConfigComponent::initialize() has parameter $config with no value type specifi…

---

## [SQL query is returning the literal SQL query and not executing it in CakePHP 4](https://discourse.cakephp.org/t/sql-query-is-returning-the-literal-sql-query-and-not-executing-it-in-cakephp-4/11622)

<div class="topic-metadata">

**Author:** [@makamo66](https://discourse.cakephp.org/u/makamo66)\
**Replies:** 17\
**Last updated:** [November 13, 2023, 5:44pm UTC](https://discourse.cakephp.org/t/sql-query-is-returning-the-literal-sql-query-and-not-executing-it-in-cakephp-4/11622 "2023-11-13T17:44:21Z")

</div>

I don’t know what any of this is called so I don’t know how to google for it. The query I’m trying to execute in CakePHP 4 is returning the SQL query literally and not executing it. The send\_email method in UsersControll…

---

## [How to test page if enabled FormProtection](https://discourse.cakephp.org/t/how-to-test-page-if-enabled-formprotection/11624)

<div class="topic-metadata">

**Author:** [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Replies:** 2\
**Last updated:** [November 6, 2023, 7:19am UTC](https://discourse.cakephp.org/t/how-to-test-page-if-enabled-formprotection/11624 "2023-11-06T07:19:11Z")

</div>

I have enabled: $this-\>loadComponent('FormProtection'); If run test, then get error: Possibly related to \`Cake\\Http\\Exception\\BadRequestException\`: "\`\_Token\` was not found in request data." Test public function …

---

## [Making Tables that only are used in tests](https://discourse.cakephp.org/t/making-tables-that-only-are-used-in-tests/11605)

<div class="topic-metadata">

**Author:** [@dreamingmind](https://discourse.cakephp.org/u/dreamingmind)\
**Replies:** 5\
**Last updated:** [November 3, 2023, 4:03pm UTC](https://discourse.cakephp.org/t/making-tables-that-only-are-used-in-tests/11605 "2023-11-03T16:03:53Z")

</div>

I’m working on some code that will eventually be a plugin. While testing the code I need some tables but those tables are not required by the plugin, they would come from the app that uses the plugin. So I don’t want th…

---

## [Fixture Factories v3.0](https://discourse.cakephp.org/t/fixture-factories-v3-0/11568)

<div class="topic-metadata">

**Author:** [@pabloelcolombiano](https://discourse.cakephp.org/u/pabloelcolombiano)\
**Replies:** 0\
**Last updated:** [October 10, 2023, 12:25am UTC](https://discourse.cakephp.org/t/fixture-factories-v3-0/11568 "2023-10-10T00:25:28Z")

</div>

Hey community, here is to announce that the version v3.0 of the fixture factories is out! More here. Happy testing!

---

## [How to test database - sqlite](https://discourse.cakephp.org/t/how-to-test-database-sqlite/11551)

<div class="topic-metadata">

**Author:** [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Replies:** 5\
**Last updated:** [October 5, 2023, 6:30pm UTC](https://discourse.cakephp.org/t/how-to-test-database-sqlite/11551 "2023-10-05T18:30:02Z")

</div>

I have config for test database 'test' =\> \[ 'host' =\> 'localhost', 'username' =\> '', 'password' =\> '', 'database' =\> '', 'url' =\> env('DATABASE\_TEST\_UR…

---

## [Test with HttpsEnforcerMiddleware](https://discourse.cakephp.org/t/test-with-httpsenforcermiddleware/11543)

<div class="topic-metadata">

**Author:** [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Replies:** 1\
**Last updated:** [September 28, 2023, 7:08pm UTC](https://discourse.cakephp.org/t/test-with-httpsenforcermiddleware/11543 "2023-09-28T19:08:05Z")

</div>

I have config in Application.php this: $middlewareQueue -\>add(new HttpsEnforcerMiddleware(\[ 'hsts' =\> \['maxAge' =\> 31536000, 'includeSubDomains' =\> true\], \])) In the test …

---

## [Query Durations on loading time](https://discourse.cakephp.org/t/query-durations-on-loading-time/11362)

<div class="topic-metadata">

**Author:** [@Rods](https://discourse.cakephp.org/u/Rods)\
**Replies:** 2\
**Last updated:** [July 17, 2023, 10:36am UTC](https://discourse.cakephp.org/t/query-durations-on-loading-time/11362 "2023-07-17T10:36:32Z")

</div>

Any Idea how to get the query durations on loading? I tried this. $connection = ConnectionManager::get(‘default’); $connection-\>enableQueryLogging(true); $data = $this-\>Statistics-\>find(); $connection = $connection-\>…

---

## [CakePHP Fixture Factories v2.7](https://discourse.cakephp.org/t/cakephp-fixture-factories-v2-7/10493)

<div class="topic-metadata">

**Author:** [@pabloelcolombiano](https://discourse.cakephp.org/u/pabloelcolombiano)\
**Replies:** 0\
**Last updated:** [July 2, 2022, 6:59am UTC](https://discourse.cakephp.org/t/cakephp-fixture-factories-v2-7/10493 "2022-07-02T06:59:35Z")

</div>

Hi everyone, here is a little announcement for a new release of the fixture factories. v2.7 brings a nice performance improvement by enabling to skip entity setters by default or on the fly. More https://github.com/vie…

---

## [Cakephp 4.x run all core tests using phpunit](https://discourse.cakephp.org/t/cakephp-4-x-run-all-core-tests-using-phpunit/10336)

<div class="topic-metadata">

**Author:** [@chetanvarshney](https://discourse.cakephp.org/u/chetanvarshney)\
**Replies:** 7\
**Last updated:** [April 26, 2022, 4:09pm UTC](https://discourse.cakephp.org/t/cakephp-4-x-run-all-core-tests-using-phpunit/10336 "2022-04-26T16:09:58Z")

</div>

I am trying run all test cases using phpunit on local but no lock I have modified cakephp/src/View/Helper/FormHelper.php and tried to create pull request to merge, but when github running all tests, it failed all time, …

---

## [In string method notation in Fixture Factories v2.6](https://discourse.cakephp.org/t/in-string-method-notation-in-fixture-factories-v2-6/10068)

<div class="topic-metadata">

**Author:** [@pabloelcolombiano](https://discourse.cakephp.org/u/pabloelcolombiano)\
**Replies:** 0\
**Last updated:** [January 11, 2022, 3:17pm UTC](https://discourse.cakephp.org/t/in-string-method-notation-in-fixture-factories-v2-6/10068 "2022-01-11T15:17:56Z")

</div>

Hi community, this is a poll for the users of the fixture factories. We are introducing a new feature on our next release. If you want to give your opinion on how it should look like, feel free to vote here: Greetings…

---

## [CakePHP fixture factories v2.3 release](https://discourse.cakephp.org/t/cakephp-fixture-factories-v2-3-release/9429)

<div class="topic-metadata">

**Author:** [@pabloelcolombiano](https://discourse.cakephp.org/u/pabloelcolombiano)\
**Replies:** 1\
**Last updated:** [June 10, 2021, 2:00am UTC](https://discourse.cakephp.org/t/cakephp-fixture-factories-v2-3-release/9429 "2021-06-10T02:00:09Z")

</div>

This is an announcement for a new release of the CakePHP fixture factories. v2.3 (v1.3 for CakePHP 3) brings you: Insert fixtures on the command line (CakePHP 4 only) Test fixture scenarios Find and count methods to …

---

## [How to setup PHPUnit testing](https://discourse.cakephp.org/t/how-to-setup-phpunit-testing/9374)

<div class="topic-metadata">

**Author:** [@kamleshkumar](https://discourse.cakephp.org/u/kamleshkumar)\
**Replies:** 4\
**Last updated:** [May 28, 2021, 6:26pm UTC](https://discourse.cakephp.org/t/how-to-setup-phpunit-testing/9374 "2021-05-28T18:26:05Z")

</div>

How to setup phpunit testing? I followed by book at Install PHPUnit with Composer but not success

---

## [Unit testing of file uploads (solved)](https://discourse.cakephp.org/t/unit-testing-of-file-uploads-solved/5241)

<div class="topic-metadata">

**Author:** [@nickinok](https://discourse.cakephp.org/u/nickinok)\
**Replies:** 1\
**Last updated:** [January 19, 2021, 3:26pm UTC](https://discourse.cakephp.org/t/unit-testing-of-file-uploads-solved/5241 "2021-01-19T15:26:18Z")

</div>

Hi Cakers! I thought I would share something I figured out how to do. It took a few hours, so maybe this will save you some time too. And there is very little info on Google on how to do this on any PHP platform. If you…

---

## [Load a fixture and its data](https://discourse.cakephp.org/t/load-a-fixture-and-its-data/8533)

<div class="topic-metadata">

**Author:** [@thornstrom](https://discourse.cakephp.org/u/thornstrom)\
**Replies:** 1\
**Last updated:** [December 27, 2020, 9:09pm UTC](https://discourse.cakephp.org/t/load-a-fixture-and-its-data/8533 "2020-12-27T21:09:34Z")

</div>

I’m trying to load a fixture and its data into my CakePHP Unit tests. The fixture listener is set in phpunit.xml.dist. There’s the fixture ‘AdminServiceFixture.php’ in the tests/Fixture folder with the content: \<?php …

---

## [CakePHP 4 PHPUnit testing - fixture listener](https://discourse.cakephp.org/t/cakephp-4-phpunit-testing-fixture-listener/8503)

<div class="topic-metadata">

**Author:** [@thornstrom](https://discourse.cakephp.org/u/thornstrom)\
**Replies:** 2\
**Last updated:** [October 17, 2020, 1:06am UTC](https://discourse.cakephp.org/t/cakephp-4-phpunit-testing-fixture-listener/8503 "2020-10-17T01:06:48Z")

</div>

Hi, I’m having trouble setting up the fixture listener for my project. I’ve added the xml in phpunit.xml.dist: \<!-- Setup a listener for fixtures --\> \<listeners\> \<listener class="Cake\\TestSuite\\Fixture\\Fi…

---

## [Mailer Previews and deprecated warning and DebugKit](https://discourse.cakephp.org/t/mailer-previews-and-deprecated-warning-and-debugkit/8396)

<div class="topic-metadata">

**Author:** [@spooknick](https://discourse.cakephp.org/u/spooknick)\
**Replies:** 0\
**Last updated:** [September 18, 2020, 12:51pm UTC](https://discourse.cakephp.org/t/mailer-previews-and-deprecated-warning-and-debugkit/8396 "2020-09-18T12:51:46Z")

</div>

Hi, I’m trying to implement Mailer as suggested in the book creating-reusable-emails and came across a dichotomy between unit testing and Mailer Previews in debugKit. Either I have a deprecation warning Deprecated Er…

---

## [Alert me that MySQL 5.6 EOL ---\> UPGRADE to MySQL 5.7](https://discourse.cakephp.org/t/alert-me-that-mysql-5-6-eol-upgrade-to-mysql-5-7/8245)

<div class="topic-metadata">

**Author:** [@lsepolis123](https://discourse.cakephp.org/u/lsepolis123)\
**Replies:** 8\
**Last updated:** [August 21, 2020, 11:28pm UTC](https://discourse.cakephp.org/t/alert-me-that-mysql-5-6-eol-upgrade-to-mysql-5-7/8245 "2020-08-21T23:28:31Z")

</div>

My WHM/cPanel Alert me that MySQL 5.6 EOL —\> UPGRADE to MySQL 5.7… I have some CakePHP Sites I think version CakePHP 3.x in LAMP stack. How to find the exact CakePHP version??? CakePHP 3.x supports MySQL 5.7 \[strick …

---

## [Dependeny Injection on Integration Tests](https://discourse.cakephp.org/t/dependeny-injection-on-integration-tests/8214)

<div class="topic-metadata">

**Author:** [@gersonfs](https://discourse.cakephp.org/u/gersonfs)\
**Replies:** 2\
**Last updated:** [August 19, 2020, 5:54pm UTC](https://discourse.cakephp.org/t/dependeny-injection-on-integration-tests/8214 "2020-08-19T17:54:49Z")

</div>

Hello! How can I inject dependencies in the controller that I will test in integration tests? I would like something similar to this in an integration test: Inject Dependency on FooController Then $this-\>post('/foo/ac…

---

## [Fetch response of redirect in IntegrationTest](https://discourse.cakephp.org/t/fetch-response-of-redirect-in-integrationtest/8135)

<div class="topic-metadata">

**Author:** [@mario](https://discourse.cakephp.org/u/mario)\
**Replies:** 4\
**Last updated:** [July 28, 2020, 6:57pm UTC](https://discourse.cakephp.org/t/fetch-response-of-redirect-in-integrationtest/8135 "2020-07-28T18:57:58Z")

</div>

In HttpClient there is the option of following a redirect after eg. a GET-request. Is there a similar feature in the IntegrationTest? As far as I got, there is only the possibility to get the redirected location. T…

---

## [PHPUnit CakePHP 4.X - mock up the identity object, but how?](https://discourse.cakephp.org/t/phpunit-cakephp-4-x-mock-up-the-identity-object-but-how/8056)

<div class="topic-metadata">

**Author:** [@profdanibest](https://discourse.cakephp.org/u/profdanibest)\
**Replies:** 3\
**Last updated:** [July 22, 2020, 6:18am UTC](https://discourse.cakephp.org/t/phpunit-cakephp-4-x-mock-up-the-identity-object-but-how/8056 "2020-07-22T06:18:58Z")

</div>

i written a webaplication with cakephp 4.x. In my controller(AppController.php) i have implements the following: ... public function beforeRender(\\Cake\\Event\\EventInterface $event) { #Load User\_ID if($this-\>Au…

[Next page](https://discourse.cakephp.org/c/testing/7.md?page=1)
