Skip to content

Commit fcd39d4

Browse files
committed
Update type hint for $messages in FlashInterface::set() to allow mixed arrays #45
1 parent 36ac9c6 commit fcd39d4

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [6.4.0] - 2025-07-29
9+
10+
* Update type hint for $messages in FlashInterface::set() to allow mixed arrays
11+
812
## [6.3.0] - 2024-12-15
913

1014
* Add support for PHP 8.4

src/FlashInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function clear(): void;
4646
* Set all messages.
4747
*
4848
* @param string $key The key to clear
49-
* @param array<int, string> $messages The messages
49+
* @param array<int|string, string> $messages The messages
5050
*
5151
* @return void
5252
*/
@@ -55,7 +55,7 @@ public function set(string $key, array $messages): void;
5555
/**
5656
* Gets all flash messages.
5757
*
58-
* @return array<int, string> All messages. Can be an empty array.
58+
* @return array<int|string, string> All messages. Can be an empty array.
5959
*/
6060
public function all(): array;
6161
}

tests/FlashTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ public function testSet(): void
6161
$this->assertSame([0 => 'value1', 1 => 'value2'], $flash->get('key2'));
6262
}
6363

64+
public function testSetStringAsKey(): void
65+
{
66+
$session = [];
67+
$flash = new Flash($session);
68+
$flash->set('input', ['email' => 'john@example.com']);
69+
$this->assertSame(['email' => 'john@example.com'], $flash->get('input'));
70+
71+
$session = [];
72+
$flash = new Flash($session);
73+
$flash->set('message', [
74+
'type' => 'error',
75+
'text' => 'Invalid email or password.',
76+
]);
77+
$this->assertSame([
78+
'type' => 'error',
79+
'text' => 'Invalid email or password.',
80+
], $flash->get('message'));
81+
}
82+
6483
public function testClear(): void
6584
{
6685
$session = [];

tests/PhpSessionTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ protected function tearDown(): void
4747
$this->manager->destroy();
4848
}
4949

50-
unset($this->session);
51-
unset($this->manager);
50+
$this->session->clear();
5251
}
5352

5453
public function testStart(): void

0 commit comments

Comments
 (0)