-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract the CardTypeDataTransformer from the TpayCardType
- Loading branch information
1 parent
be90545
commit fdc1446
Showing
5 changed files
with
81 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Form\DataTransformer; | ||
|
||
use Symfony\Component\Form\DataTransformerInterface; | ||
|
||
final class CardTypeDataTransformer implements DataTransformerInterface | ||
{ | ||
public function transform($value): ?array | ||
{ | ||
return null; | ||
} | ||
|
||
/** | ||
* @param mixed|array{card: string} $value | ||
*/ | ||
public function reverseTransform(mixed $value): string | ||
{ | ||
if (!is_array($value)) { | ||
return ''; | ||
} | ||
|
||
return $value['card']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/Unit/Form/DataTransformer/CardTypeDataTransformerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Form\DataTransformer; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Form\DataTransformer\CardTypeDataTransformer; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Form\DataTransformerInterface; | ||
|
||
final class CardTypeDataTransformerTest extends TestCase | ||
{ | ||
public function test_it_returns_null_on_a_transform(): void | ||
{ | ||
$dataTransformer = $this->createTestSubject(); | ||
|
||
$this->assertSame(null, $dataTransformer->transform(null)); | ||
$this->assertSame(null, $dataTransformer->transform(true)); | ||
$this->assertSame(null, $dataTransformer->transform('string')); | ||
$this->assertSame(null, $dataTransformer->transform(1)); | ||
} | ||
|
||
public function test_it_returns_an_empty_string_when_trying_to_reverse_transform_a_non_array(): void | ||
{ | ||
$dataTransformer = $this->createTestSubject(); | ||
|
||
$this->assertSame('', $dataTransformer->reverseTransform(null)); | ||
$this->assertSame('', $dataTransformer->reverseTransform(true)); | ||
$this->assertSame('', $dataTransformer->reverseTransform('string')); | ||
$this->assertSame('', $dataTransformer->reverseTransform(1)); | ||
} | ||
|
||
private function createTestSubject(): DataTransformerInterface | ||
{ | ||
return new CardTypeDataTransformer(); | ||
} | ||
} |