Skip to content

Commit

Permalink
Merge pull request #703 from FriendsOfCake/flash-check
Browse files Browse the repository at this point in the history
Fix FlashComponent check
  • Loading branch information
ADmad authored Oct 4, 2023
2 parents 4c01324 + 408da15 commit 4378ee9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Action/BaseAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function setFlash(string $type, Subject $subject): void
return;
}

if (!isset($this->_controller()->Flash)) {
if (!$this->_controller()->components()->has('Flash')) {
throw new RuntimeException('FlashComponent not loaded in controller.');
}

Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase/Action/BaseActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ public function testSetFlash()
->with('setFlash', $Subject)
->will($this->returnValue(new Event('Crud.setFlash')));

$this->Controller->Flash = $this->getMockBuilder(FlashComponent::class)
$flash = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->Registry])
->getMock();
$this->Controller->Flash
$flash
->expects($this->once())
->method('set')
->with(
Expand All @@ -267,6 +267,7 @@ public function testSetFlash()
'key' => $data['key'],
]
);
$this->Controller->components()->set('Flash', $flash);

$this->ActionClass->setConfig('name', 'test');
$this->ActionClass->setConfig('messages', [
Expand Down

0 comments on commit 4378ee9

Please sign in to comment.