|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2024 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\InventoryImportExport\Test\Unit\Model\Import\Validator; |
| 9 | + |
| 10 | +use Magento\Framework\Validation\ValidationResult; |
| 11 | +use Magento\Framework\Validation\ValidationResultFactory; |
| 12 | +use Magento\InventoryImportExport\Model\Import\Sources; |
| 13 | +use Magento\InventoryImportExport\Model\Import\Validator\QtyValidator; |
| 14 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 15 | +use PHPUnit\Framework\MockObject\MockObject; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | + |
| 18 | +class QtyValidatorTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var MockObject|null |
| 22 | + */ |
| 23 | + private ?MockObject $validationResultFactory; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var QtyValidator|null |
| 27 | + */ |
| 28 | + private ?QtyValidator $model; |
| 29 | + |
| 30 | + protected function setUp(): void |
| 31 | + { |
| 32 | + parent::setUp(); |
| 33 | + $this->validationResultFactory = $this->createMock(ValidationResultFactory::class); |
| 34 | + $this->model = new QtyValidator($this->validationResultFactory); |
| 35 | + } |
| 36 | + |
| 37 | + #[DataProvider('validateDataProvider')] |
| 38 | + public function testValidate(array $data, array $errors = []): void |
| 39 | + { |
| 40 | + $rowNumber = 1; |
| 41 | + $result = new ValidationResult([]); |
| 42 | + $this->validationResultFactory |
| 43 | + ->expects($this->once())->method('create') |
| 44 | + ->with(['errors' => $errors]) |
| 45 | + ->willReturn($result); |
| 46 | + $this->assertSame($result, $this->model->validate($data, $rowNumber)); |
| 47 | + } |
| 48 | + |
| 49 | + public static function validateDataProvider(): array |
| 50 | + { |
| 51 | + return [ |
| 52 | + [ |
| 53 | + [Sources::COL_QTY => 1,], |
| 54 | + ], |
| 55 | + [ |
| 56 | + [Sources::COL_QTY => 0,], |
| 57 | + ], |
| 58 | + [ |
| 59 | + [Sources::COL_QTY => -1,], |
| 60 | + ], |
| 61 | + [ |
| 62 | + [Sources::COL_QTY => 0.1,], |
| 63 | + ], |
| 64 | + [ |
| 65 | + [Sources::COL_QTY => '1',], |
| 66 | + ], |
| 67 | + [ |
| 68 | + [Sources::COL_QTY => '0',], |
| 69 | + ], |
| 70 | + [ |
| 71 | + [Sources::COL_QTY => '-1',], |
| 72 | + ], |
| 73 | + [ |
| 74 | + [Sources::COL_QTY => '0.1',], |
| 75 | + ], |
| 76 | + [ |
| 77 | + [Sources::COL_QTY => 'abc',], |
| 78 | + [__('"%column" contains incorrect value', ['column' => Sources::COL_QTY])], |
| 79 | + ], |
| 80 | + [ |
| 81 | + ['qty' => 1,], |
| 82 | + [__('Missing required column "%column"', ['column' => Sources::COL_QTY])], |
| 83 | + ], |
| 84 | + ]; |
| 85 | + } |
| 86 | +} |
0 commit comments