-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests - test coverage for factory classes
- Loading branch information
mustapayev
committed
Oct 12, 2024
1 parent
16f032d
commit 1055b66
Showing
10 changed files
with
443 additions
and
19 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
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,47 @@ | ||
<?php | ||
/** | ||
* @license MIT | ||
*/ | ||
|
||
namespace Mews\Pos\Tests\Unit\Factory; | ||
|
||
use Mews\Pos\Factory\CryptFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* @covers \Mews\Pos\Factory\CryptFactory | ||
*/ | ||
class CryptFactoryTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @dataProvider createGatewayCryptDataProvider | ||
*/ | ||
public function testCreateGatewayCrypt(string $gatewayClass, string $serializerClass): void | ||
{ | ||
$logger = $this->createMock(LoggerInterface::class); | ||
$crypt = CryptFactory::createGatewayCrypt($gatewayClass, $logger); | ||
$this->assertInstanceOf($serializerClass, $crypt); | ||
} | ||
|
||
public static function createGatewayCryptDataProvider(): array | ||
{ | ||
return [ | ||
[\Mews\Pos\Gateways\AkbankPos::class, \Mews\Pos\Crypt\AkbankPosCrypt::class], | ||
[\Mews\Pos\Gateways\EstPos::class, \Mews\Pos\Crypt\EstPosCrypt::class], | ||
[\Mews\Pos\Gateways\EstV3Pos::class, \Mews\Pos\Crypt\EstV3PosCrypt::class], | ||
[\Mews\Pos\Gateways\GarantiPos::class, \Mews\Pos\Crypt\GarantiPosCrypt::class], | ||
[\Mews\Pos\Gateways\InterPos::class, \Mews\Pos\Crypt\InterPosCrypt::class], | ||
[\Mews\Pos\Gateways\KuveytPos::class, \Mews\Pos\Crypt\KuveytPosCrypt::class], | ||
[\Mews\Pos\Gateways\PayFlexV4Pos::class, \Mews\Pos\Crypt\NullCrypt::class], | ||
[\Mews\Pos\Gateways\PayFlexCPV4Pos::class, \Mews\Pos\Crypt\PayFlexCPV4Crypt::class], | ||
[\Mews\Pos\Gateways\PayForPos::class, \Mews\Pos\Crypt\PayForPosCrypt::class], | ||
[\Mews\Pos\Gateways\PosNet::class, \Mews\Pos\Crypt\PosNetCrypt::class], | ||
[\Mews\Pos\Gateways\PosNetV1Pos::class, \Mews\Pos\Crypt\PosNetV1PosCrypt::class], | ||
[\Mews\Pos\Gateways\ToslaPos::class, \Mews\Pos\Crypt\ToslaPosCrypt::class], | ||
[\Mews\Pos\Gateways\VakifKatilimPos::class, \Mews\Pos\Crypt\KuveytPosCrypt::class], | ||
[\stdClass::class, \Mews\Pos\Crypt\NullCrypt::class], | ||
]; | ||
} | ||
} |
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,198 @@ | ||
<?php | ||
|
||
namespace Mews\Pos\Tests\Unit\Factory; | ||
|
||
use Mews\Pos\Entity\Account\AbstractPosAccount; | ||
use Mews\Pos\Exceptions\BankClassNullException; | ||
use Mews\Pos\Exceptions\BankNotFoundException; | ||
use Mews\Pos\Factory\PosFactory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \Mews\Pos\Factory\PosFactory | ||
*/ | ||
class PosFactoryTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @dataProvider createPosGatewayDataProvider | ||
*/ | ||
public function testCreatePosGateway(array $config, string $configKey, bool $cardTypeMapping, string $expectedGatewayClass): void | ||
{ | ||
$account = $this->createMock(AbstractPosAccount::class); | ||
$account->expects(self::atLeastOnce()) | ||
->method('getBank') | ||
->willReturn($configKey); | ||
|
||
$eventDispatcher = $this->createMock(\Psr\EventDispatcher\EventDispatcherInterface::class); | ||
$httpClient = $this->createMock(\Mews\Pos\Client\HttpClient::class); | ||
$logger = $this->createMock(\Psr\Log\LoggerInterface::class); | ||
|
||
$gateway = PosFactory::createPosGateway( | ||
$account, | ||
$config, | ||
$eventDispatcher, | ||
$httpClient, | ||
$logger | ||
); | ||
$this->assertInstanceOf($expectedGatewayClass, $gateway); | ||
|
||
$this->assertSame($account, $gateway->getAccount()); | ||
$this->assertNotEmpty($gateway->getCurrencies()); | ||
if ($cardTypeMapping) { | ||
$this->assertNotEmpty($gateway->getCardTypeMapping()); | ||
} else { | ||
$this->assertEmpty($gateway->getCardTypeMapping()); | ||
} | ||
} | ||
|
||
|
||
public function testCreatePosGatewayWithOnlyRequiredParameters(): void | ||
{ | ||
$gatewayClass = \Mews\Pos\Gateways\AkbankPos::class; | ||
$config = [ | ||
'banks' => [ | ||
'akbank' => [ | ||
'name' => 'Akbank', | ||
'class' => $gatewayClass, | ||
'gateway_endpoints' => [ | ||
'payment_api' => 'https://apipre.akbank.com/api/v1/payment/virtualpos', | ||
'gateway_3d' => 'https://virtualpospaymentgatewaypre.akbank.com/securepay', | ||
'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', | ||
], | ||
], | ||
], | ||
]; | ||
$account = $this->createMock(AbstractPosAccount::class); | ||
$account->expects(self::atLeastOnce()) | ||
->method('getBank') | ||
->willReturn('akbank'); | ||
|
||
$eventDispatcher = $this->createMock(\Psr\EventDispatcher\EventDispatcherInterface::class); | ||
|
||
$gateway = PosFactory::createPosGateway( | ||
$account, | ||
$config, | ||
$eventDispatcher, | ||
); | ||
$this->assertInstanceOf($gatewayClass, $gateway); | ||
} | ||
|
||
/** | ||
* @dataProvider createPosGatewayDataExceptionProvider | ||
*/ | ||
public function testCreatePosGatewayFail(array $config, string $configKey, string $expectedExceptionClass): void | ||
{ | ||
$account = $this->createMock(AbstractPosAccount::class); | ||
$account->expects(self::atLeastOnce()) | ||
->method('getBank') | ||
->willReturn($configKey); | ||
|
||
$eventDispatcher = $this->createMock(\Psr\EventDispatcher\EventDispatcherInterface::class); | ||
|
||
$this->expectException($expectedExceptionClass); | ||
PosFactory::createPosGateway( | ||
$account, | ||
$config, | ||
$eventDispatcher, | ||
); | ||
} | ||
|
||
public static function createPosGatewayDataExceptionProvider(): \Generator | ||
{ | ||
yield 'missing_gateway_class_in_config' => [ | ||
'config' => [ | ||
'banks' => [ | ||
'akbank' => [ | ||
'name' => 'Akbank', | ||
'gateway_endpoints' => [ | ||
'payment_api' => 'https://apipre.akbank.com/api/v1/payment/virtualpos', | ||
'gateway_3d' => 'https://virtualpospaymentgatewaypre.akbank.com/securepay', | ||
'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', | ||
], | ||
], | ||
], | ||
], | ||
'config_key' => 'akbank', | ||
'expected_exception_class' => BankClassNullException::class, | ||
]; | ||
|
||
yield 'invalid_gateway_class' => [ | ||
'config' => [ | ||
'banks' => [ | ||
'akbank' => [ | ||
'name' => 'Akbank', | ||
'class' => \stdClass::class, | ||
'gateway_endpoints' => [ | ||
'payment_api' => 'https://apipre.akbank.com/api/v1/payment/virtualpos', | ||
'gateway_3d' => 'https://virtualpospaymentgatewaypre.akbank.com/securepay', | ||
'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', | ||
], | ||
], | ||
], | ||
], | ||
'config_key' => 'akbank', | ||
'expected_exception_class' => \InvalidArgumentException::class, | ||
]; | ||
|
||
yield 'non_existing_config_key' => [ | ||
'config' => [ | ||
'banks' => [ | ||
'estpos' => [ | ||
'name' => 'Akbank', | ||
'class' => \stdClass::class, | ||
'gateway_endpoints' => [ | ||
'payment_api' => 'https://apipre.akbank.com/api/v1/payment/virtualpos', | ||
'gateway_3d' => 'https://virtualpospaymentgatewaypre.akbank.com/securepay', | ||
'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', | ||
], | ||
], | ||
], | ||
], | ||
'config_key' => 'akbank', | ||
'expected_exception_class' => BankNotFoundException::class, | ||
]; | ||
} | ||
|
||
public static function createPosGatewayDataProvider(): \Generator | ||
{ | ||
$gatewayClasses = [ | ||
\Mews\Pos\Gateways\AkbankPos::class => false, | ||
\Mews\Pos\Gateways\EstPos::class => false, | ||
\Mews\Pos\Gateways\EstV3Pos::class => false, | ||
\Mews\Pos\Gateways\GarantiPos::class => false, | ||
\Mews\Pos\Gateways\InterPos::class => true, | ||
\Mews\Pos\Gateways\KuveytPos::class => true, | ||
\Mews\Pos\Gateways\PayFlexCPV4Pos::class => true, | ||
\Mews\Pos\Gateways\PayFlexV4Pos::class => true, | ||
\Mews\Pos\Gateways\PayForPos::class => false, | ||
\Mews\Pos\Gateways\PosNet::class => false, | ||
\Mews\Pos\Gateways\PosNetV1Pos::class => false, | ||
\Mews\Pos\Gateways\ToslaPos::class => false, | ||
\Mews\Pos\Gateways\VakifKatilimPos::class => false, | ||
]; | ||
|
||
foreach ($gatewayClasses as $gatewayClass => $cardTypeMapping) { | ||
$configKey = 'abcdse'; | ||
$config = [ | ||
'banks' => [ | ||
$configKey => [ | ||
'name' => 'Akbank', | ||
'class' => $gatewayClass, | ||
'gateway_endpoints' => [ | ||
'payment_api' => 'https://apipre.akbank.com/api/v1/payment/virtualpos', | ||
'gateway_3d' => 'https://virtualpospaymentgatewaypre.akbank.com/securepay', | ||
'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', | ||
], | ||
], | ||
], | ||
]; | ||
yield [ | ||
$config, | ||
$configKey, | ||
$cardTypeMapping, | ||
$gatewayClass, | ||
]; | ||
} | ||
} | ||
} |
Oops, something went wrong.