Skip to content

Commit

Permalink
I have just fixed an error in the method isEmpty and added new test
Browse files Browse the repository at this point in the history
  • Loading branch information
ssheduardo committed Jan 16, 2025
1 parent 34d8da6 commit 26cb28c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

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

## Version 1.5.0 (2025-01-16)
### Added
- None

### Changed
- Updated isEmpty method to properly handle non-string values

### Fixed
- Fixed deprecated warning in isEmpty method when passing null values to trim().
- Fixed incorrect validation of boolean values in isEmpty method

## Version 1.4.9 (2025-01-11)
### Added
- None
Expand Down
6 changes: 5 additions & 1 deletion src/Sermepa/Tpv/Tpv.php
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,11 @@ protected function decodeParameters($data)
*/
protected function isEmpty($value)
{
return '' === trim($value);
if ($value === null) {
return true;
}

return is_string($value) && '' === trim($value);
}

/**
Expand Down
66 changes: 65 additions & 1 deletion tests/TpvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,76 @@

namespace Sermepa\Tpv;

use ReflectionClass;
use PHPUnit\Framework\TestCase as PHPUnitTestCase;

class TpvTest extends PHPUnitTestCase
{

private $isEmptyMethod;
private $redsys;

protected function setUp(): void
{
$this->redsys = new Tpv();
$reflection = new ReflectionClass(Tpv::class);
$this->isEmptyMethod = $reflection->getMethod('isEmpty');
$this->isEmptyMethod->setAccessible(true);
}

/**
* Data provider for the isEmpty method
*
* @return array Array of empty values
*/
public function emptyValuesProvider()
{
return [
'null value' => [null],
'empty string' => [''],
'whitespace string' => [' '],
'tabs' => ["\t\t"],
'newlines' => ["\n\r"],
];
}

/**
* @test
* @dataProvider emptyValuesProvider
*/
public function isEmpty_should_handle_empty_values($value)
{
$result = $this->isEmptyMethod->invoke($this->redsys, $value);
$this->assertTrue($result);
}

/**
* Data provider for the isEmpty method
*
* @return array Array of empty values
*/
public function nonEmptyValuesProvider()
{
return [
'boolean true' => [true],
'boolean false' => [false],
'empty array' => [[]],
'zero as string' => ['0'],
'zero as integer' => [0],
'normal string' => ['test'],
];
}

/**
* @test
* @dataProvider nonEmptyValuesProvider
*/
public function isEmpty_returns_false_for_non_empty_values($value)
{
$result = $this->isEmptyMethod->invoke($this->redsys, $value);
$this->assertFalse($result);
}

/** @test */
public function identifier_by_default_required()
{
Expand Down Expand Up @@ -650,7 +715,6 @@ public function test_should_validate_a_merchant_cof_ini($cofIni)
$parameters = $redsys->getParameters();
$this->assertArrayHasKey('DS_MERCHANT_COF_INI', $parameters);
$this->assertContains($parameters['DS_MERCHANT_COF_INI'], [$cofIni]);

}

public function invalidSetMerchantCofIni()
Expand Down

0 comments on commit 26cb28c

Please sign in to comment.