Skip to content

Commit 26cb28c

Browse files
committed
I have just fixed an error in the method isEmpty and added new test
1 parent 34d8da6 commit 26cb28c

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
All Notable changes to `Redsys` will be documented in this file
44

5+
## Version 1.5.0 (2025-01-16)
6+
### Added
7+
- None
8+
9+
### Changed
10+
- Updated isEmpty method to properly handle non-string values
11+
12+
### Fixed
13+
- Fixed deprecated warning in isEmpty method when passing null values to trim().
14+
- Fixed incorrect validation of boolean values in isEmpty method
15+
516
## Version 1.4.9 (2025-01-11)
617
### Added
718
- None

src/Sermepa/Tpv/Tpv.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,11 @@ protected function decodeParameters($data)
10761076
*/
10771077
protected function isEmpty($value)
10781078
{
1079-
return '' === trim($value);
1079+
if ($value === null) {
1080+
return true;
1081+
}
1082+
1083+
return is_string($value) && '' === trim($value);
10801084
}
10811085

10821086
/**

tests/TpvTest.php

+65-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,76 @@
22

33
namespace Sermepa\Tpv;
44

5+
use ReflectionClass;
56
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
67

78
class TpvTest extends PHPUnitTestCase
89
{
910

11+
private $isEmptyMethod;
12+
private $redsys;
13+
14+
protected function setUp(): void
15+
{
16+
$this->redsys = new Tpv();
17+
$reflection = new ReflectionClass(Tpv::class);
18+
$this->isEmptyMethod = $reflection->getMethod('isEmpty');
19+
$this->isEmptyMethod->setAccessible(true);
20+
}
21+
22+
/**
23+
* Data provider for the isEmpty method
24+
*
25+
* @return array Array of empty values
26+
*/
27+
public function emptyValuesProvider()
28+
{
29+
return [
30+
'null value' => [null],
31+
'empty string' => [''],
32+
'whitespace string' => [' '],
33+
'tabs' => ["\t\t"],
34+
'newlines' => ["\n\r"],
35+
];
36+
}
37+
38+
/**
39+
* @test
40+
* @dataProvider emptyValuesProvider
41+
*/
42+
public function isEmpty_should_handle_empty_values($value)
43+
{
44+
$result = $this->isEmptyMethod->invoke($this->redsys, $value);
45+
$this->assertTrue($result);
46+
}
47+
48+
/**
49+
* Data provider for the isEmpty method
50+
*
51+
* @return array Array of empty values
52+
*/
53+
public function nonEmptyValuesProvider()
54+
{
55+
return [
56+
'boolean true' => [true],
57+
'boolean false' => [false],
58+
'empty array' => [[]],
59+
'zero as string' => ['0'],
60+
'zero as integer' => [0],
61+
'normal string' => ['test'],
62+
];
63+
}
64+
65+
/**
66+
* @test
67+
* @dataProvider nonEmptyValuesProvider
68+
*/
69+
public function isEmpty_returns_false_for_non_empty_values($value)
70+
{
71+
$result = $this->isEmptyMethod->invoke($this->redsys, $value);
72+
$this->assertFalse($result);
73+
}
74+
1075
/** @test */
1176
public function identifier_by_default_required()
1277
{
@@ -650,7 +715,6 @@ public function test_should_validate_a_merchant_cof_ini($cofIni)
650715
$parameters = $redsys->getParameters();
651716
$this->assertArrayHasKey('DS_MERCHANT_COF_INI', $parameters);
652717
$this->assertContains($parameters['DS_MERCHANT_COF_INI'], [$cofIni]);
653-
654718
}
655719

656720
public function invalidSetMerchantCofIni()

0 commit comments

Comments
 (0)