Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed Nov 20, 2023
1 parent 05c8eba commit b4ef678
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 101 deletions.
50 changes: 0 additions & 50 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -660,41 +660,6 @@ parameters:
count: 1
path: src/Payum/Core/Model/Token.php

-
message: "#^Call to an undefined method Omnipay\\\\Common\\\\GatewayFactory\\:\\:getSupportedGateways\\(\\)\\.$#"
count: 1
path: src/Payum/Core/PayumBuilder.php

-
message: "#^If condition is always true\\.$#"
count: 2
path: src/Payum/Core/PayumBuilder.php

-
message: "#^Method Payum\\\\Core\\\\PayumBuilder\\:\\:addCoreGatewayFactoryConfig\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
count: 1
path: src/Payum/Core/PayumBuilder.php

-
message: "#^Method Payum\\\\Core\\\\PayumBuilder\\:\\:addGateway\\(\\) has parameter \\$gateway with no value type specified in iterable type array\\.$#"
count: 1
path: src/Payum/Core/PayumBuilder.php

-
message: "#^Method Payum\\\\Core\\\\PayumBuilder\\:\\:addGatewayFactoryConfig\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
count: 1
path: src/Payum/Core/PayumBuilder.php

-
message: "#^Method Payum\\\\Core\\\\PayumBuilder\\:\\:buildCoreGatewayFactory\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
count: 1
path: src/Payum/Core/PayumBuilder.php

-
message: "#^Method Payum\\\\Core\\\\PayumBuilder\\:\\:buildOmnipayGatewayFactories\\(\\) should return array\\<Payum\\\\Core\\\\GatewayFactoryInterface\\> but returns array\\<string, Payum\\\\OmnipayBridge\\\\OmnipayGatewayFactory\\>\\.$#"
count: 1
path: src/Payum/Core/PayumBuilder.php

-
message: "#^Method Payum\\\\Core\\\\PayumBuilder\\:\\:buildRegistry\\(\\) has parameter \\$gatewayFactories with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -720,21 +685,6 @@ parameters:
count: 1
path: src/Payum/Core/Registry/AbstractRegistry.php

-
message: "#^Property Payum\\\\Core\\\\Registry\\\\AbstractRegistry\\:\\:\\$storages type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Payum/Core/Registry/AbstractRegistry.php

-
message: "#^PHPDoc tag @var for property Payum\\\\Core\\\\Registry\\\\DynamicRegistry\\:\\:\\$gatewayFactoryRegistry with type Payum\\\\Core\\\\Registry\\\\GatewayFactoryRegistryInterface\\|null is not subtype of native type Payum\\\\Core\\\\Registry\\\\GatewayFactoryRegistryInterface\\.$#"
count: 1
path: src/Payum/Core/Registry/DynamicRegistry.php

-
message: "#^Method Payum\\\\Core\\\\Registry\\\\SimpleRegistry\\:\\:getService\\(\\) should return object but returns string\\.$#"
count: 1
path: src/Payum/Core/Registry/SimpleRegistry.php

-
message: "#^Method Payum\\\\Core\\\\Reply\\\\HttpPostRedirect\\:\\:__construct\\(\\) has parameter \\$fields with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
5 changes: 3 additions & 2 deletions src/Payum/Core/Registry/SimpleRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ protected function getService($id): object | string
*/
protected function addStorageToGateway(string $name, GatewayInterface $gateway): void
{
/** @var Gateway $gateway */
if (isset($this->initializedStorageExtensions[$name])) {
return;
}

foreach ($this->getStorages() as $storage) {
$gateway->addExtension(new StorageExtension($storage));
if ($gateway instanceof Gateway) {
$gateway->addExtension(new StorageExtension($storage));
}
}

$this->initializedStorageExtensions[$name] = true;
Expand Down
5 changes: 3 additions & 2 deletions src/Payum/Core/Tests/Action/GetTokenActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Iterator;
use Payum\Core\Action\GetTokenAction;
use Payum\Core\Exception\LogicException;
use Payum\Core\Model\Identity;
use Payum\Core\Request\Generic;
use Payum\Core\Request\GetToken;
use Payum\Core\Security\TokenInterface;
Expand Down Expand Up @@ -47,7 +48,7 @@ public function testShouldSetFoundToken(): void
$tokenStorage
->expects($this->once())
->method('find')
->with($hash)
->with(new Identity($hash, TokenInterface::class))
->willReturn($token)
;

Expand All @@ -70,7 +71,7 @@ public function testThrowIfTokenNotFound(): void
$tokenStorage
->expects($this->once())
->method('find')
->with($hash)
->with(new Identity($hash, TokenInterface::class))
->willReturn(null)
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testShouldProxyCriteriaToRepositoryFindByMethodOnFindByCall(): v
->expects($this->once())
->method('findBy')
->with($criteria)
->willReturn($model)
->willReturn([$model])
;

$objectManagerMock = $this->createObjectManagerMock();
Expand All @@ -89,7 +89,7 @@ public function testShouldProxyCriteriaToRepositoryFindByMethodOnFindByCall(): v
TestModel::class
);

$this->assertSame($model, $storage->findBy($criteria));
$this->assertSame([$model], $storage->findBy($criteria));
}

public function testShouldFindModelById(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testThrowIfStorageCouldNotFindTokenByGivenHashOnVerify(): void
public function testThrowIfTargetUrlPathNotMatchServerRequestUriPathOnVerify(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The current url https://target.com/bar not match target url http://target.com/foo set in the token.');
$this->expectExceptionMessage('The current url https://target.com/bar not match target url https://target.com/foo set in the token.');
$_SERVER['REQUEST_URI'] = 'https://target.com/bar';

$token = new Token();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Payum\Core\Tests\Bridge\Symfony;

use Payum\Core\Bridge\Symfony\ContainerAwareRegistry;
use Payum\Core\GatewayFactoryInterface;
use Payum\Core\GatewayInterface;
use Payum\Core\Registry\AbstractRegistry;
use Payum\Core\Storage\StorageInterface;
Expand Down Expand Up @@ -66,13 +67,13 @@ public function testShouldReturnStorageSetToContainer(): void
public function testShouldReturnGatewayFactorySetToContainer(): void
{
$container = new Container();
$container->set('fooFactoryServiceId', $this->createMock(StorageInterface::class));
$container->set(GatewayFactoryInterface::class, $this->createMock(GatewayFactoryInterface::class));

$registry = new ContainerAwareRegistry([], [], [
'fooName' => 'fooFactoryServiceId',
'fooName' => GatewayFactoryInterface::class,
]);
$registry->setContainer($container);

$this->assertSame($container->get('fooFactoryServiceId'), $registry->getGatewayFactory('fooName'));
$this->assertSame($container->get(GatewayFactoryInterface::class), $registry->getGatewayFactory('fooName'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testThrowIfStorageCouldNotFindTokenByGivenHashOnVerify(): void
public function testThrowIfTargetUrlPathNotMatchServerRequestUriPathOnVerify(): void
{
$this->expectException(HttpException::class);
$this->expectExceptionMessage('The current url https://target.com/bar not match target url http://target.com/foo set in the token.');
$this->expectExceptionMessage('The current url https://target.com/bar not match target url https://target.com/foo set in the token.');
$token = new Token();
$token->setHash('theHash');
$token->setTargetUrl('https://target.com/foo');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public function testShouldAllowCreateAfterUrlWithoutPayumToken(): void
$model,
'https://example.com/authorize.php',
[],
'http://googlehttps://ayum_token=foo',
'https://google.com/?afterKey=afterVal',
[
'payum_token' => null,
'afterKey' => 'afterVal',
Expand Down
28 changes: 20 additions & 8 deletions src/Payum/Core/Tests/PayumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use Exception;
use Payum\Core\Exception\LogicException;
use Payum\Core\GatewayFactoryInterface;
use Payum\Core\GatewayInterface;
use Payum\Core\Model\PaymentInterface;
use Payum\Core\Payum;
use Payum\Core\Registry\RegistryInterface;
use Payum\Core\Registry\SimpleRegistry;
use Payum\Core\Registry\StorageRegistryInterface;
use Payum\Core\Reply\HttpPostRedirect;
use Payum\Core\Reply\HttpRedirect;
use Payum\Core\Reply\HttpResponse;
Expand All @@ -25,15 +27,22 @@
use ReflectionClass;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use function spl_object_hash;

final class PayumTest extends TestCase
{
/**
* @var RegistryInterface<StorageRegistryInterface<StorageInterface<TokenInterface>>>|MockObject
*/
private RegistryInterface | MockObject $registryMock;

private HttpRequestVerifierInterface | MockObject $httpRequestVerifierMock;

private GenericTokenFactoryInterface | MockObject $tokenFactoryMock;

/**
* @var StorageInterface<TokenInterface>|MockObject
*/
private StorageInterface | MockObject $storageMock;

protected function setUp(): void
Expand Down Expand Up @@ -133,8 +142,8 @@ public function testShouldAllowGetStoragesFromRegistryInConstructor(): void
'bar' => 'barGateway',
],
[
$fooStorage::class => $fooStorage,
$barStorage::class => $barStorage,
spl_object_hash($fooStorage) => $fooStorage,
spl_object_hash($barStorage) => $barStorage,
],
[
'foo' => 'fooGatewayFactory',
Expand All @@ -149,11 +158,11 @@ public function testShouldAllowGetStoragesFromRegistryInConstructor(): void
$this->storageMock,
);

$this->assertSame($fooStorage, $payum->getStorage($fooStorage::class));
$this->assertSame($barStorage, $payum->getStorage($barStorage::class));
$this->assertSame($fooStorage, $payum->getStorage(spl_object_hash($fooStorage)));
$this->assertSame($barStorage, $payum->getStorage(spl_object_hash($barStorage)));
$this->assertSame([
$fooStorage::class => $fooStorage,
$barStorage::class => $barStorage,
spl_object_hash($fooStorage) => $fooStorage,
spl_object_hash($barStorage) => $barStorage,
], $payum->getStorages());
}

Expand All @@ -162,14 +171,17 @@ public function testShouldAllowGetGatewayFactoriesFromRegistryInConstructor(): v
$fooStorage = $this->createMock(StorageInterface::class);
$barStorage = $this->createMock(StorageInterface::class);

$fooGatewayFactory = $this->createMock(GatewayFactoryInterface::class);
$barGatewayFactory = $this->createMock(GatewayFactoryInterface::class);

$registry = new SimpleRegistry(
[
'foo' => 'fooGateway',
'bar' => 'barGateway',
],
[
$fooStorage::class => $fooStorage,
$barStorage::class => $barStorage,
spl_object_hash($fooStorage) => $fooStorage,
spl_object_hash($barStorage) => $barStorage,
],
[
'foo' => $fooGatewayFactory,
Expand Down
Loading

0 comments on commit b4ef678

Please sign in to comment.