Skip to content

Commit

Permalink
Merge pull request #505 from Tetragramat/tests
Browse files Browse the repository at this point in the history
fixed compatibility with symfony 5
  • Loading branch information
makasim authored Feb 11, 2020
2 parents 6709cf9 + ff70503 commit 0841644
Show file tree
Hide file tree
Showing 24 changed files with 83 additions and 188 deletions.
2 changes: 2 additions & 0 deletions Command/CreateCaptureTokenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(sprintf('Url: <info>%s</info>', $token->getTargetUrl()));
$output->writeln(sprintf('After Url: <info>%s</info>', $token->getAfterUrl() ?: 'null'));
$output->writeln(sprintf('Details: <info>%s</info>', (string) $token->getDetails()));

return 0;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion Command/CreateNotifyTokenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$modelId = $input->getOption('model-id');
$model = null;

if ($modelClass && $modelId) {
if ($modelClass && $modelId) {
if (false == $model = $this->getPayum()->getStorage($modelClass)->find($modelId)) {
throw new RuntimeException(sprintf(
'Cannot find model with class %s and id %s.',
Expand All @@ -55,6 +55,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(sprintf('Hash: <info>%s</info>', $token->getHash()));
$output->writeln(sprintf('Url: <info>%s</info>', $token->getTargetUrl()));
$output->writeln(sprintf('Details: <info>%s</info>', (string) $token->getDetails() ?: 'null'));

return 0;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Command/DebugGatewayCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(sprintf("\t%s", get_class($api)));
}
}

return 0;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->getPayum()->getGateway($gatewayName)->execute($status);

$output->writeln(sprintf('Status: %s', $status->getValue()));

return 0;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Controller/CaptureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class CaptureController extends PayumController
{
public function doSessionTokenAction(Request $request)
{
if (false == $request->getSession()) {
if (false === $request->hasSession()) {
throw new HttpException(400, 'This controller requires session to be started.');
}

if (false == $hash = $request->getSession()->get('payum_token')) {
if (null === $hash = $request->getSession()->get('payum_token')) {
throw new HttpException(400, 'This controller requires token hash to be stored in the session.');
}

Expand Down Expand Up @@ -45,4 +45,4 @@ public function doAction(Request $request)

return $this->redirect($token->getAfterUrl());
}
}
}
6 changes: 3 additions & 3 deletions Controller/PayumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use Payum\Core\Payum;
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

abstract class PayumController extends Controller
abstract class PayumController extends AbstractController
{
/**
* @return Payum
Expand Down Expand Up @@ -35,4 +35,4 @@ protected function getTokenFactory()
{
return $this->getPayum()->getTokenFactory();
}
}
}
12 changes: 3 additions & 9 deletions DependencyInjection/MainConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ public function __construct(array $storageFactories)
*/
public function getConfigTreeBuilder()
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
$tb = new TreeBuilder('payum');
$rootNode = $tb->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$tb = new TreeBuilder();
$rootNode = $tb->root('payum');
}
$tb = new TreeBuilder('payum');
$rootNode = $tb->getRootNode();

$securityNode = $rootNode->children()
->arrayNode('security')->isRequired()
Expand Down Expand Up @@ -260,4 +254,4 @@ protected function addDynamicGatewaysSection(ArrayNodeDefinition $dynamicGateway
);
}
}
}
}
21 changes: 7 additions & 14 deletions EventListener/ReplyToHttpResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter;
use Payum\Core\Reply\ReplyInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;

class ReplyToHttpResponseListener
{
Expand All @@ -21,24 +21,17 @@ public function __construct(ReplyToSymfonyResponseConverter $replyToSymfonyRespo
}

/**
* @param GetResponseForExceptionEvent $event
* @param ExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
public function onKernelException(ExceptionEvent $event)
{
if (false == $event->getException() instanceof ReplyInterface) {
if (false === $event->getThrowable() instanceof ReplyInterface) {
return;
}

$response = $this->replyToSymfonyResponseConverter->convert($event->getException());

// BC for SF < 3.3
if (!method_exists($event, 'allowCustomResponseCode')) {
if (false === $response->headers->has('X-Status-Code')) {
$response->headers->set('X-Status-Code', $response->getStatusCode());
}
} else {
$event->allowCustomResponseCode();
}
$response = $this->replyToSymfonyResponseConverter->convert($event->getThrowable());

$event->allowCustomResponseCode();

$event->setResponse($response);
}
Expand Down
3 changes: 1 addition & 2 deletions Form/Extension/GatewayFactoriesChoiceTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Payum\Core\Bridge\Symfony\Form\Type\GatewayFactoriesChoiceType;
use Payum\Core\Registry\GatewayFactoryRegistryInterface;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Exception;
use Symfony\Component\OptionsResolver\OptionsResolver;

class GatewayFactoriesChoiceTypeExtension extends AbstractTypeExtension
Expand Down Expand Up @@ -53,7 +52,7 @@ public function getExtendedType()
/**
* {@inheritdoc}
*/
public static function getExtendedTypes()
public static function getExtendedTypes(): iterable
{
return [GatewayFactoriesChoiceType::class];
}
Expand Down
2 changes: 1 addition & 1 deletion Profiler/PayumCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PayumCollector extends DataCollector implements ExtensionInterface
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
foreach ($this->contexts as $context) {
$request = $context->getRequest();
Expand Down
5 changes: 3 additions & 2 deletions Resources/config/validation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
<constraint name="NotBlank">
<option name="groups">Payum</option>
</constraint>
<constraint name="DateTime">
<constraint name="Type">
<option name="type">DateTimeInterface</option>
<option name="groups">Payum</option>
</constraint>
<constraint name="Payum\Core\Bridge\Symfony\Validator\Constraints\CreditCardDate">
Expand All @@ -47,4 +48,4 @@
</property>
</class>

</constraint-mapping>
</constraint-mapping>
4 changes: 2 additions & 2 deletions Resources/doc/storages.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ doctrine_mongodb:
payum:
is_bundle: false
type: xml
dir: %kernel.root_dir%/../vendor/payum/core/Payum/Core/Bridge/Doctrine/Resources/mapping
dir: %kernel.project_dir%/vendor/payum/core/Payum/Core/Bridge/Doctrine/Resources/mapping
# set this dir instead if you use `payum/payum` library
#dir: %kernel.root_dir%/../vendor/payum/payum/src/Payum/Core/Bridge/Doctrine/Resources/mapping
#dir: %kernel.project_dir%/vendor/payum/payum/src/Payum/Core/Bridge/Doctrine/Resources/mapping

prefix: Payum\Core\Model

Expand Down
4 changes: 2 additions & 2 deletions Tests/Controller/AuthorizeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Storage\StorageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -24,7 +24,7 @@ public function shouldBeSubClassOfController()
{
$rc = new \ReflectionClass(AuthorizeController::class);

$this->assertTrue($rc->isSubclassOf(Controller::class));
$this->assertTrue($rc->isSubclassOf(AbstractController::class));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Tests/Controller/CancelControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Storage\StorageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -25,7 +25,7 @@ public function shouldBeSubClassOfController()
{
$rc = new \ReflectionClass(CancelController::class);

$this->assertTrue($rc->isSubclassOf(Controller::class));
$this->assertTrue($rc->isSubclassOf(AbstractController::class));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Tests/Controller/CaptureControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Storage\StorageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -27,7 +27,7 @@ public function shouldBeSubClassOfController()
{
$rc = new \ReflectionClass(CaptureController::class);

$this->assertTrue($rc->isSubclassOf(Controller::class));
$this->assertTrue($rc->isSubclassOf(AbstractController::class));
}

/**
Expand All @@ -43,7 +43,7 @@ public function throwBadRequestIfSessionNotStartedOnDoSessionAction()
$request = Request::create('/');

//guard
$this->assertNull($request->getSession());
$this->assertFalse($request->hasSession());

$controller->doSessionTokenAction($request);
}
Expand Down
6 changes: 2 additions & 4 deletions Tests/Controller/NotifyControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
use Payum\Core\GatewayInterface;
use Payum\Core\Registry\RegistryInterface;
use Payum\Core\Request\Notify;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;

class NotifyControllerTest extends \PHPUnit\Framework\TestCase
{
Expand All @@ -21,7 +19,7 @@ public function shouldBeSubClassOfController()
{
$rc = new \ReflectionClass(NotifyController::class);

$this->assertTrue($rc->isSubclassOf(Controller::class));
$this->assertTrue($rc->isSubclassOf(AbstractController::class));
}

/**
Expand Down
7 changes: 2 additions & 5 deletions Tests/Controller/PayoutControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Storage\StorageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\Routing\RouterInterface;

class PayoutControllerTest extends \PHPUnit\Framework\TestCase
{
Expand All @@ -27,7 +24,7 @@ public function shouldBeSubClassOfController()
{
$rc = new \ReflectionClass(PayoutController::class);

$this->assertTrue($rc->isSubclassOf(Controller::class));
$this->assertTrue($rc->isSubclassOf(AbstractController::class));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Tests/Controller/RefundControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Storage\StorageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -25,7 +25,7 @@ public function shouldBeSubClassOfController()
{
$rc = new \ReflectionClass(RefundController::class);

$this->assertTrue($rc->isSubclassOf(Controller::class));
$this->assertTrue($rc->isSubclassOf(AbstractController::class));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function shouldAllowAddConfiguration()
{
$factory = $this->createAbstractStorageFactory();

$tb = new TreeBuilder();
$rootNode = $tb->root('foo');
$tb = new TreeBuilder('foo');
$rootNode = $tb->getRootNode();

$factory->addConfiguration($rootNode);

Expand Down Expand Up @@ -94,4 +94,4 @@ protected function createAbstractStorageFactory()
{
return $this->getMockForAbstractClass('Payum\Bundle\PayumBundle\DependencyInjection\Factory\Storage\AbstractStorageFactory');
}
}
}
Loading

0 comments on commit 0841644

Please sign in to comment.