-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix #24: bridge normalizer * Fix PHP5.5 typehint * Use custom normalizer bridge
- Loading branch information
1 parent
7b82fca
commit 6ebb7ed
Showing
14 changed files
with
221 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ | |
|
||
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; | ||
use CoopTilleuls\ForgotPasswordBundle\Manager\ForgotPasswordManager; | ||
use CoopTilleuls\ForgotPasswordBundle\Normalizer\NormalizerInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
/** | ||
* @author Vincent Chalamon <[email protected]> | ||
|
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,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the CoopTilleulsForgotPasswordBundle package. | ||
* | ||
* (c) Vincent Chalamon <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CoopTilleuls\ForgotPasswordBundle\Normalizer; | ||
|
||
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; | ||
use JMS\Serializer\ArrayTransformerInterface; | ||
|
||
/** | ||
* @author Vincent Chalamon <[email protected]> | ||
*/ | ||
final class JMSNormalizer implements NormalizerInterface | ||
{ | ||
/** | ||
* @var ArrayTransformerInterface | ||
*/ | ||
private $normalizer; | ||
|
||
/** | ||
* @param ArrayTransformerInterface $normalizer | ||
*/ | ||
public function __construct(ArrayTransformerInterface $normalizer) | ||
{ | ||
$this->normalizer = $normalizer; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function normalize(AbstractPasswordToken $object, $format, array $context = []) | ||
{ | ||
return $this->normalizer->toArray($object); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the CoopTilleulsForgotPasswordBundle package. | ||
* | ||
* (c) Vincent Chalamon <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CoopTilleuls\ForgotPasswordBundle\Normalizer; | ||
|
||
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; | ||
|
||
/** | ||
* @author Vincent Chalamon <[email protected]> | ||
*/ | ||
interface NormalizerInterface | ||
{ | ||
/** | ||
* @param AbstractPasswordToken $object | ||
* @param string $format | ||
* @param array $context | ||
* | ||
* @return mixed | ||
*/ | ||
public function normalize(AbstractPasswordToken $object, $format, array $context = []); | ||
} |
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,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the CoopTilleulsForgotPasswordBundle package. | ||
* | ||
* (c) Vincent Chalamon <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CoopTilleuls\ForgotPasswordBundle\Normalizer; | ||
|
||
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface as SymfonyNormalizerInterface; | ||
|
||
/** | ||
* @author Vincent Chalamon <[email protected]> | ||
*/ | ||
final class SymfonyNormalizer implements NormalizerInterface | ||
{ | ||
/** | ||
* @var SymfonyNormalizerInterface | ||
*/ | ||
private $normalizer; | ||
|
||
/** | ||
* @param SymfonyNormalizerInterface $normalizer | ||
*/ | ||
public function __construct(SymfonyNormalizerInterface $normalizer) | ||
{ | ||
$this->normalizer = $normalizer; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function normalize(AbstractPasswordToken $object, $format, array $context = []) | ||
{ | ||
return $this->normalizer->normalize($object, $format, $context); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -14,9 +14,9 @@ | |
use CoopTilleuls\ForgotPasswordBundle\Controller\ForgotPasswordController; | ||
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; | ||
use CoopTilleuls\ForgotPasswordBundle\Manager\ForgotPasswordManager; | ||
use CoopTilleuls\ForgotPasswordBundle\Normalizer\NormalizerInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
/** | ||
* @author Vincent Chalamon <[email protected]> | ||
|
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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the CoopTilleulsForgotPasswordBundle package. | ||
* | ||
* (c) Vincent Chalamon <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tests\ForgotPasswordBundle\Normalizer; | ||
|
||
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; | ||
use CoopTilleuls\ForgotPasswordBundle\Normalizer\JMSNormalizer; | ||
use JMS\Serializer\ArrayTransformerInterface; | ||
|
||
/** | ||
* @author Vincent Chalamon <[email protected]> | ||
*/ | ||
final class JMSNormalizerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testNormalize() | ||
{ | ||
$normalizerMock = $this->prophesize(ArrayTransformerInterface::class); | ||
$passwordTokenMock = $this->prophesize(AbstractPasswordToken::class); | ||
|
||
$normalizerMock->toArray($passwordTokenMock)->willReturn('foo')->shouldBeCalledTimes(1); | ||
|
||
$normalizer = new JMSNormalizer($normalizerMock->reveal()); | ||
$this->assertEquals('foo', $normalizer->normalize($passwordTokenMock->reveal(), 'json')); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the CoopTilleulsForgotPasswordBundle package. | ||
* | ||
* (c) Vincent Chalamon <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tests\ForgotPasswordBundle\Normalizer; | ||
|
||
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; | ||
use CoopTilleuls\ForgotPasswordBundle\Normalizer\SymfonyNormalizer; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
/** | ||
* @author Vincent Chalamon <[email protected]> | ||
*/ | ||
final class SymfonyNormalizerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testNormalize() | ||
{ | ||
$normalizerMock = $this->prophesize(NormalizerInterface::class); | ||
$passwordTokenMock = $this->prophesize(AbstractPasswordToken::class); | ||
|
||
$normalizerMock->normalize($passwordTokenMock, 'json', [])->willReturn('foo')->shouldBeCalledTimes(1); | ||
|
||
$normalizer = new SymfonyNormalizer($normalizerMock->reveal()); | ||
$this->assertEquals('foo', $normalizer->normalize($passwordTokenMock->reveal(), 'json')); | ||
} | ||
} |