Skip to content

Commit e315ba9

Browse files
committed
Added tests to check expection thrown
1 parent 701a710 commit e315ba9

6 files changed

Lines changed: 46 additions & 0 deletions

File tree

tests/system/Cache/Handlers/ApcuHandlerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use CodeIgniter\Cache\CacheFactory;
1717
use CodeIgniter\CLI\CLI;
18+
use CodeIgniter\Exceptions\InvalidArgumentException;
1819
use CodeIgniter\I18n\Time;
1920
use Config\Cache;
2021
use PHPUnit\Framework\Attributes\Group;
@@ -126,6 +127,14 @@ public function testRememberWithTTLCallableAndValuePassed(): void
126127
$this->assertNull($this->handler->get(self::$key1));
127128
}
128129

130+
public function testRememberWithTTLCallableAndMultipleParameters(): void
131+
{
132+
$this->expectException(InvalidArgumentException::class);
133+
$this->expectExceptionMessage('Argument #2 ($ttl) must accept 0 or 1 parameter, 2 given.');
134+
135+
$this->handler->remember(self::$key1, static fn ($a, $b): int => 2, static fn (): string => 'value');
136+
}
137+
129138
public function testSave(): void
130139
{
131140
$this->assertTrue($this->handler->save(self::$key1, 'value'));

tests/system/Cache/Handlers/DummyHandlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace CodeIgniter\Cache\Handlers;
1515

1616
use CodeIgniter\Cache\CacheFactory;
17+
use CodeIgniter\Exceptions\InvalidArgumentException;
1718
use CodeIgniter\Test\CIUnitTestCase;
1819
use Config\Cache;
1920
use PHPUnit\Framework\Attributes\Group;

tests/system/Cache/Handlers/FileHandlerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CodeIgniter\Cache\CacheFactory;
1717
use CodeIgniter\Cache\Exceptions\CacheException;
1818
use CodeIgniter\CLI\CLI;
19+
use CodeIgniter\Exceptions\InvalidArgumentException;
1920
use CodeIgniter\I18n\Time;
2021
use Config\Cache;
2122
use PHPUnit\Framework\Attributes\DataProvider;
@@ -178,6 +179,14 @@ public function testRememberWithTTLCallableAndValuePassed(): void
178179
$this->assertNull($this->handler->get(self::$key1));
179180
}
180181

182+
public function testRememberWithTTLCallableAndMultipleParameters(): void
183+
{
184+
$this->expectException(InvalidArgumentException::class);
185+
$this->expectExceptionMessage('Argument #2 ($ttl) must accept 0 or 1 parameter, 2 given.');
186+
187+
$this->handler->remember(self::$key1, static fn ($a, $b): int => 2, static fn (): string => 'value');
188+
}
189+
181190
/**
182191
* chmod('path', 0444) does not work on Windows
183192
*/

tests/system/Cache/Handlers/MemcachedHandlerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CodeIgniter\Cache\CacheFactory;
1717
use CodeIgniter\CLI\CLI;
1818
use CodeIgniter\Exceptions\BadMethodCallException;
19+
use CodeIgniter\Exceptions\InvalidArgumentException;
1920
use CodeIgniter\I18n\Time;
2021
use Config\Cache;
2122
use PHPUnit\Framework\Attributes\Group;
@@ -133,6 +134,14 @@ public function testRememberWithTTLCallableAndValuePassed(): void
133134
$this->assertNull($this->handler->get(self::$key1));
134135
}
135136

137+
public function testRememberWithTTLCallableAndMultipleParameters(): void
138+
{
139+
$this->expectException(InvalidArgumentException::class);
140+
$this->expectExceptionMessage('Argument #2 ($ttl) must accept 0 or 1 parameter, 2 given.');
141+
142+
$this->handler->remember(self::$key1, static fn ($a, $b): int => 2, static fn (): string => 'value');
143+
}
144+
136145
public function testSave(): void
137146
{
138147
$this->assertTrue($this->handler->save(self::$key1, 'value'));

tests/system/Cache/Handlers/PredisHandlerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use CodeIgniter\Cache\LockStoreInterface;
1818
use CodeIgniter\Cache\LockStoreProviderInterface;
1919
use CodeIgniter\CLI\CLI;
20+
use CodeIgniter\Exceptions\InvalidArgumentException;
2021
use CodeIgniter\I18n\Time;
2122
use Config\Cache;
2223
use PHPUnit\Framework\Attributes\Group;
@@ -143,6 +144,14 @@ public function testRememberWithTTLCallableAndValuePassed(): void
143144
$this->assertNull($this->handler->get(self::$key1));
144145
}
145146

147+
public function testRememberWithTTLCallableAndMultipleParameters(): void
148+
{
149+
$this->expectException(InvalidArgumentException::class);
150+
$this->expectExceptionMessage('Argument #2 ($ttl) must accept 0 or 1 parameter, 2 given.');
151+
152+
$this->handler->remember(self::$key1, static fn ($a, $b): int => 2, static fn (): string => 'value');
153+
}
154+
146155
public function testSave(): void
147156
{
148157
$this->assertTrue($this->handler->save(self::$key1, 'value'));

tests/system/Cache/Handlers/RedisHandlerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use CodeIgniter\Cache\LockStoreInterface;
1818
use CodeIgniter\Cache\LockStoreProviderInterface;
1919
use CodeIgniter\CLI\CLI;
20+
use CodeIgniter\Exceptions\InvalidArgumentException;
2021
use CodeIgniter\I18n\Time;
2122
use Config\Cache;
2223
use PHPUnit\Framework\Attributes\DataProvider;
@@ -144,6 +145,14 @@ public function testRememberWithTTLCallableAndValuePassed(): void
144145
$this->assertNull($this->handler->get(self::$key1));
145146
}
146147

148+
public function testRememberWithTTLCallableAndMultipleParameters(): void
149+
{
150+
$this->expectException(InvalidArgumentException::class);
151+
$this->expectExceptionMessage('Argument #2 ($ttl) must accept 0 or 1 parameter, 2 given.');
152+
153+
$this->handler->remember(self::$key1, static fn ($a, $b): int => 2, static fn (): string => 'value');
154+
}
155+
147156
public function testSave(): void
148157
{
149158
$this->assertTrue($this->handler->save(self::$key1, 'value'));

0 commit comments

Comments
 (0)