I have serval Tests where i would like to read a specific value from app.php
Therefore i defined the following at app.php
app.php
'test' => [
some other fields ...
'email' => 'test@localhost.com'
],
MeasuresFixture.php
public function init()
{
$this->records = [
[
some other fields ...
'email' => Configure::read('test.email'),
],
];
parent::init();
}
MeasuresControllerTest.php
public function testSendAgain()
{
$this->setupUser();
$this->get('/admin/measures/send-again/1');
$this->assertRedirect("/");
$MeasuresTable = TableRegistry::get('Measures');
$measure = $MeasuresTable->get(1);
$this->assertEquals(0, $measure->exported);
}
MeasuresController.php
public function sendAgain(int $id = null): Response
{
$measure = $this->Measures->get($id);
if ($this->Measures->save($measure, $this->saveParameter())) {
$measure->sendNewMailingConfirmation();
$this->Flash->success(__('Email has been send'));
} else {
$this->Flash->error(__('Email could not been send'));
}
return $this->redirect($this->referer());
}
Entity/Measure.php
public function sendNewMailingConfirmation()
{
if (!empty($this->id)) {
$this->Email->viewBuilder()->setTemplate('confirmation');
$this->Email->setEmailFormat('html');
$this->Email->set('measure', $this);
$this->Email->setFrom([Configure::read('Staff.email') => Configure::read('Staff.name')]);
$this->Email->setSubject('TEXT');
$this->Email->setTo($this->email);
$this->Email->send();
}
}
But this Results in
App\Test\TestCase\Controller\Admin\MeasuresControllerTest::testSendAgain
InvalidArgumentException: The email set for "to" is empty.
If Email is hardcoded all Tests all working fine.
So how to use dynamic data?