How to use Configure::read within Fixtures / Controllers

I have serval Tests where i would like to read a specific value from app.php
Therefore i defined the following at app.php


'test' => [
    some other fields ...
   'email' => ''


public function init()
    $this->records = [
             some other fields ...
            'email' => Configure::read(''),


public function testSendAgain()
    $MeasuresTable = TableRegistry::get('Measures');
    $measure = $MeasuresTable->get(1);
     $this->assertEquals(0, $measure->exported);


public function sendAgain(int $id = null): Response
        $measure = $this->Measures->get($id);
        if ($this->Measures->save($measure, $this->saveParameter())) {
            $this->Flash->success(__('Email has been send'));
        } else {
            $this->Flash->error(__('Email could not been send'));

        return $this->redirect($this->referer());


public function sendNewMailingConfirmation()
        if (!empty($this->id)) {
            $this->Email->set('measure', $this);
            $this->Email->setFrom([Configure::read('') => Configure::read('')]);

But this Results in

InvalidArgumentException: The email set for "to" is empty.

If Email is hardcoded all Tests all working fine.
So how to use dynamic data?

Sounds like maybe your app.php isn’t being loaded at all during tests? You could confirm this by adding an echo or a die at the top of it.

Good Point. The CakePHP Docs gives me this anwser:
“CakePHP uses the connection named test in your config/app.php configuration file. If this connection is not usable, an exception will be raised and you will not be able to use database fixtures.”

I’ve added dd('loaded'); at the top of app.php and it throws the message as defined

Any conditional stuff in your app.php that might result in this bit not being executed? Anything later that calls consume on the test config instead of read? You haven’t shown the “send again” function at all. When you said if works if you hardcode the email, did you mean in that function or the measures fixture?

i’ve updated my code.
The Problem just exists when using “Configure::read()” within Fixtures/Controllers not within the main App

You use Configure::read('') in your sendNewMailingConfirmation function. Does that work okay? Wondering (but too lazy at the moment to check for myself) whether your fixture is being loaded before app.php.

It works when hardcoding Email like

$this->records = [
             some other fields ...
            'email' => '',

That doesn’t answer my questions…

using Configure::read within Entities works.

@Zuluru finally i have hardcoded the Email Addresses at Fixtures and just use Configure::read at ControllerTests. This works. Problem solved

It looks very good. Thanks for sharing.