CarrierRegistrationTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\ViewModel\Carrier;
  6. use Magento\Framework\App\ProductMetadataInterface;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. use PHPUnit\Framework\MockObject\MockObject;
  9. /**
  10. * Temando Carrier Registration Component Test
  11. *
  12. * @package Temando\Shipping\Test\Unit
  13. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  14. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  15. * @link https://www.temando.com/
  16. */
  17. class CarrierRegistrationTest extends \PHPUnit\Framework\TestCase
  18. {
  19. /**
  20. * @var ObjectManager
  21. */
  22. private $objectManager;
  23. protected function setUp()
  24. {
  25. $this->objectManager = new ObjectManager($this);
  26. parent::setUp();
  27. }
  28. /**
  29. * Provide different input with expectations.
  30. *
  31. * @return string[]
  32. */
  33. public function versionStringDataProvider()
  34. {
  35. return [
  36. 'dist' => ['2.1.13', '2.1.13'],
  37. 'src 2.2' => ['2.2.8-dev', '2.2.8'],
  38. 'src 2.3' => ['dev-2.3-develop', '2.3'],
  39. 'src PR' => ['dev-pr-foo', ''],
  40. 'unknown' => ['UNKNOWN', ''],
  41. ];
  42. }
  43. /**
  44. * @test
  45. * @dataProvider versionStringDataProvider
  46. *
  47. * @param string $version
  48. * @param string $expected
  49. */
  50. public function extractVersionNumberFromString($version, $expected)
  51. {
  52. $productMetaData = $this->createMock(ProductMetadataInterface::class);
  53. $productMetaData->expects(self::once())->method('getVersion')->willReturn($version);
  54. $subject = $this->objectManager->getObject(CarrierRegistration::class, [
  55. 'productMetaData' => $productMetaData,
  56. ]);
  57. $extracted = $subject->getMagentoVersion();
  58. self::assertSame($expected, $extracted);
  59. }
  60. }