CanUseForCountryTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Model\Checks;
  7. use Magento\Payment\Model\Checks\CanUseForCountry;
  8. class CanUseForCountryTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * Expected country id
  12. */
  13. const EXPECTED_COUNTRY_ID = 1;
  14. /**
  15. * @var \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $countryProvider;
  18. /**
  19. * @var CanUseForCountry
  20. */
  21. protected $_model;
  22. protected function setUp()
  23. {
  24. $this->countryProvider = $this->createMock(
  25. \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider::class
  26. );
  27. $this->_model = new CanUseForCountry($this->countryProvider);
  28. }
  29. /**
  30. * @dataProvider paymentMethodDataProvider
  31. * @param bool $expectation
  32. */
  33. public function testIsApplicable($expectation)
  34. {
  35. $quoteMock = $this->getMockBuilder(\Magento\Quote\Model\Quote::class)->disableOriginalConstructor()->setMethods(
  36. []
  37. )->getMock();
  38. $paymentMethod = $this->getMockBuilder(
  39. \Magento\Payment\Model\MethodInterface::class
  40. )->disableOriginalConstructor()->setMethods([])->getMock();
  41. $paymentMethod->expects($this->once())->method('canUseForCountry')->with(
  42. self::EXPECTED_COUNTRY_ID
  43. )->will($this->returnValue($expectation));
  44. $this->countryProvider->expects($this->once())->method('getCountry')->willReturn(self::EXPECTED_COUNTRY_ID);
  45. $this->assertEquals($expectation, $this->_model->isApplicable($paymentMethod, $quoteMock));
  46. }
  47. /**
  48. * @return array
  49. */
  50. public function paymentMethodDataProvider()
  51. {
  52. return [[true], [false]];
  53. }
  54. }