/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/Data/Test/Unit/AbstractCriteriaTest.php
452 строки
12 KB
Manish Ranjan
AC-16248: PHPUnit 12 Upgrade | Fix Framework unit tests
09 янв 2026, 19:35
09 янв 2026, 19:35
de6cafc
Код
Авторство
О чём код?
<?php /** * Copyright 2015 Adobe * All Rights Reserved. */ declare(strict_types=1); namespace Magento\Framework\Data\Test\Unit; use Magento\Framework\Api\CriteriaInterface; use Magento\Framework\Data\Test\Unit\Criteria\Sample; use Magento\Framework\DataObject; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\DataProvider; class AbstractCriteriaTest extends TestCase { /** * @var Sample */ protected $criteria; /** * Set up * * @return void */ protected function setUp(): void { $objectManager = new ObjectManager($this); $this->criteria = $objectManager->getObject(Sample::class); } /** * Run test addField method * * @param string|array $field * @param string|null $alias * @param array $result * @return void * */ #[DataProvider('dataProviderAddField')] public function testAddField($field, $alias, array $result) { $this->criteria->addField($field, $alias); $this->assertEquals($result, $this->criteria->toArray()[CriteriaInterface::PART_FIELDS]['list']); } /** * Run test addFilter method * * @param string $name * @param string|array $field * @param string|int|array $condition * @param string $type * @param array $result * @return void * */ #[DataProvider('dataProviderAddFilter')] public function testAddFilter($name, $field, $condition, $type, array $result) { $objectManager = new ObjectManager($this); $result = [ 'test-filter-name' => $objectManager->getObject( DataObject::class, ['data' => $result] ), ]; $this->criteria->addFilter($name, $field, $condition, $type); $this->assertEquals($result, $this->criteria->toArray()[CriteriaInterface::PART_FILTERS]['list']); } /** * Run test addOrder method * * @param string $field * @param string $direction * @param bool $unShift * @param array $result * @return void * */ #[DataProvider('dataProviderAddOrder')] public function testAddOrder($field, $direction, $unShift, array $result) { $this->criteria->addOrder($field, $direction, $unShift); $this->assertEquals($result, $this->criteria->toArray()[CriteriaInterface::PART_ORDERS]['list']); } /** * Run test setLimit method * * @param int $offset * @param int $size * @param array $result * @return void * */ #[DataProvider('dataProviderSetLimit')] public function testSetLimit($offset, $size, array $result) { $this->criteria->setLimit($offset, $size); $this->assertEquals($result, $this->criteria->toArray()[CriteriaInterface::PART_LIMIT]); } /** * Run test removeField method * * @param array $actualField * @param string|null $field * @param bool $isAlias Alias identifier * @param array $result * @return void * */ #[DataProvider('dataProviderRemoveField')] public function testRemoveField(array $actualField, $field, $isAlias, array $result) { list($name, $alias) = $actualField; $this->criteria->addField($name, $alias); $this->criteria->removeField($field, $isAlias); $this->assertEquals($result, $this->criteria->toArray()[CriteriaInterface::PART_FIELDS]['list']); } /** * Run test removeAllFields method * * @param array $actualField * @param array $result * @return void * */ #[DataProvider('dataProviderRemoveAllFields')] public function testRemoveAllFields(array $actualField, array $result) { list($name, $alias) = $actualField; $this->criteria->addField($name, $alias); $this->criteria->removeAllFields(); $this->assertEquals($result, $this->criteria->toArray()[CriteriaInterface::PART_FIELDS]['list']); } /** * Run test removeFilter method * * @param array $actualField * @param string $name * @param array $result * @return void * */ #[DataProvider('dataProviderRemoveFilter')] public function testRemoveFilter(array $actualField, $name, array $result) { list($filterName, $field, $condition, $type) = $actualField; $this->criteria->addFilter($filterName, $field, $condition, $type); $this->criteria->removeFilter($name); $this->assertEquals($result, $this->criteria->toArray()[CriteriaInterface::PART_FILTERS]['list']); } /** * Run test removeAllFilters method * * @param array $actualField * @param array $result * @return void * */ #[DataProvider('dataProviderRemoveAllFilters')] public function testRemoveAllFilters(array $actualField, array $result) { list($filterName, $field, $condition, $type) = $actualField; $this->criteria->addFilter($filterName, $field, $condition, $type); $this->criteria->removeAllFilters(); $this->assertEquals($result, $this->criteria->toArray()[CriteriaInterface::PART_FILTERS]['list']); } /** * Run test reset method * * @param array $result * @return void * */ #[DataProvider('dataProviderReset')] public function testReset(array $result) { $this->criteria->reset(); $this->assertEquals($result, $this->criteria->toArray()); } /** * Data provider for reset method * * @return array */ public static function dataProviderReset() { return [ [ 'result' => [ 'fields' => [ 'list' => [], ], 'filters' => [ 'list' => [], ], 'orders' => [ 'list' => [], ], 'criteria_list' => [ 'list' => [], ], ], ] ]; } /** * Data provider for removeAllFilters method * * @return array */ public static function dataProviderRemoveAllFilters() { return [ [ 'actualField' => [ 'test-filter-name', 'test-field-name', 'test-condition', 'test-type', ], 'result' => [], ] ]; } /** * Data provider for removeFilter method * * @return array */ public static function dataProviderRemoveFilter() { return [ [ 'actualField' => [ 'test-filter-name', 'test-field-name', 'test-condition', 'test-type', ], 'name' => 'test-filter-name', 'result' => [], ] ]; } /** * Data provider for removeAllFields method * * @return array */ public static function dataProviderRemoveAllFields() { return [ [ 'actualField' => [ 'test-field-name', 'test-field-alias', ], 'result' => [], ] ]; } /** * Data provider for removeField method * * @return array */ public static function dataProviderRemoveField() { return [ [ 'actualField' => [ 'test-field-name', null, ], 'field' => 'test-field-name', 'isAlias' => false, 'result' => [], ], [ 'actualField' => [ '*', null, ], 'field' => '*', 'isAlias' => false, 'result' => [] ], [ 'actualField' => [ 'test-field-name', 'test-field-alias', ], 'field' => 'test-field-alias', 'isAlias' => true, 'result' => [] ] ]; } /** * Data provider for setLimit method * * @return array */ public static function dataProviderSetLimit() { return [ [ 'offset' => 99, 'size' => 30, 'result' => [99, 30], ] ]; } /** * Data provider for addOrder method * * @return array */ public static function dataProviderAddOrder() { return [ [ 'field' => 'test-field-name', 'direction' => 'desc', 'unShift' => false, 'result' => [ 'test-field-name' => 'DESC', ], ], [ 'field' => 'test-field-name', 'direction' => 'asc', 'unShift' => false, 'result' => [ 'test-field-name' => 'ASC', ] ], [ 'field' => 'test-field-name', 'direction' => 'fail', 'unShift' => false, 'result' => [ 'test-field-name' => 'DESC', ] ] ]; } /** * Data provider for addFilter * * @return array */ public static function dataProviderAddFilter() { return [ [ 'name' => 'test-filter-name', 'field' => 'test-field-name', 'condition' => 'test-condition', 'type' => 'test-type', 'result' => [ 'name' => 'test-filter-name', 'field' => 'test-field-name', 'condition' => 'test-condition', 'type' => 'test-type', ], ] ]; } /** * Data provider for addField * * @return array */ public static function dataProviderAddField() { return [ [ 'field' => 'test-field-name', 'alias' => null, 'result' => [ 'test-field-name' => 'test-field-name', ], ], [ 'field' => '*', 'alias' => null, 'result' => [ '*', ], ], [ 'field' => [ 'test-field-name-1', 'test-field-name-2', 'test-field-name-3', ], 'alias' => null, 'result' => [ 'test-field-name-1' => 'test-field-name-1', 'test-field-name-2' => 'test-field-name-2', 'test-field-name-3' => 'test-field-name-3', ] ], [ 'field' => 'test-field-name', 'alias' => 'alias-test', 'result' => [ 'alias-test' => 'test-field-name', ] ], [ 'field' => '*', 'alias' => null, 'result' => [ '*', ] ], [ 'field' => [ 'alias-1' => 'test-field-name', 'alias-2' => 'test-field-name', 'alias-3' => 'test-field-name', ], 'alias' => null, 'result' => [ 'alias-1' => 'test-field-name', 'alias-2' => 'test-field-name', 'alias-3' => 'test-field-name', ] ] ]; } }