|
2 | 2 |
|
3 | 3 | namespace Sermepa\Tpv;
|
4 | 4 |
|
| 5 | +use ReflectionClass; |
5 | 6 | use PHPUnit\Framework\TestCase as PHPUnitTestCase;
|
6 | 7 |
|
7 | 8 | class TpvTest extends PHPUnitTestCase
|
8 | 9 | {
|
9 | 10 |
|
| 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 | + |
10 | 75 | /** @test */
|
11 | 76 | public function identifier_by_default_required()
|
12 | 77 | {
|
@@ -650,7 +715,6 @@ public function test_should_validate_a_merchant_cof_ini($cofIni)
|
650 | 715 | $parameters = $redsys->getParameters();
|
651 | 716 | $this->assertArrayHasKey('DS_MERCHANT_COF_INI', $parameters);
|
652 | 717 | $this->assertContains($parameters['DS_MERCHANT_COF_INI'], [$cofIni]);
|
653 |
| - |
654 | 718 | }
|
655 | 719 |
|
656 | 720 | public function invalidSetMerchantCofIni()
|
|
0 commit comments