mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
102 lines
2.6 KiB
PHP
102 lines
2.6 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace Inpsyde\PayPalCommerce\ApiClient\Repository;
|
||
|
|
||
|
use Hamcrest\Matchers;
|
||
|
use Inpsyde\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
||
|
use Inpsyde\PayPalCommerce\TestCase;
|
||
|
use Mockery\MockInterface;
|
||
|
use Psr\Container\ContainerInterface;
|
||
|
use function Brain\Monkey\Functions\expect;
|
||
|
|
||
|
class ApplicationContextRepositoryTest extends TestCase
|
||
|
{
|
||
|
private static $mocks = [];
|
||
|
|
||
|
/**
|
||
|
* @dataProvider currentContextData
|
||
|
*/
|
||
|
public function testCurrentContext(array $container, string $userLocale, array $expected): void
|
||
|
{
|
||
|
$brandName = 'Acme Corp.';
|
||
|
|
||
|
// Config
|
||
|
foreach ($container as $key => $value) {
|
||
|
$this->buildTestee()[0]->shouldReceive('has')
|
||
|
->with(Matchers::identicalTo($key))
|
||
|
->andReturn(true);
|
||
|
$this->buildTestee()[0]->shouldReceive('get')
|
||
|
->with(Matchers::identicalTo($key))
|
||
|
->andReturn($value);
|
||
|
}
|
||
|
|
||
|
expect('get_user_locale')
|
||
|
->andReturn($userLocale);
|
||
|
|
||
|
/* @var ApplicationContextRepository $testee */
|
||
|
$testee = $this->buildTestee()[1];
|
||
|
|
||
|
$context = $testee->currentContext();
|
||
|
|
||
|
self::assertInstanceOf(
|
||
|
ApplicationContext::class,
|
||
|
$context
|
||
|
);
|
||
|
|
||
|
foreach ($expected as $method => $value) {
|
||
|
self::assertSame(
|
||
|
$value,
|
||
|
$context->{$method}(),
|
||
|
"Test failed for method {$method}"
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @see testCurrentContext
|
||
|
*/
|
||
|
public function currentContextData(): array
|
||
|
{
|
||
|
return [
|
||
|
'default test' => [
|
||
|
'container' => [
|
||
|
'brand_name' => 'Acme corp.',
|
||
|
'landing_page' => ApplicationContext::LANDING_PAGE_BILLING,
|
||
|
],
|
||
|
'user_locale' => 'de_DE',
|
||
|
'expected' => [
|
||
|
'locale' => 'de-DE',
|
||
|
'brandName' => 'Acme corp.',
|
||
|
'landingPage' => ApplicationContext::LANDING_PAGE_BILLING,
|
||
|
],
|
||
|
],
|
||
|
];
|
||
|
}
|
||
|
|
||
|
public function tearDown(): void
|
||
|
{
|
||
|
self::$mocks = [];
|
||
|
parent::tearDown();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return MockInterface[]
|
||
|
*/
|
||
|
private function buildTestee(): array
|
||
|
{
|
||
|
if (! self::$mocks) {
|
||
|
$config = \Mockery::mock(ContainerInterface::class);
|
||
|
$testee = new ApplicationContextRepository($config);
|
||
|
|
||
|
self::$mocks = [
|
||
|
$config,
|
||
|
$testee,
|
||
|
];
|
||
|
}
|
||
|
|
||
|
return self::$mocks;
|
||
|
}
|
||
|
}
|