Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractCollectorPositionsTest.php
Go to the documentation of this file.
1 <?php
11 
12 abstract class AbstractCollectorPositionsTest extends \PHPUnit\Framework\TestCase
13 {
22  public function testCollectorPosition($collectorCode, $configType, array $before, array $after)
23  {
24  $allCollectors = self::_getConfigCollectors($configType);
25  $collectorCodes = array_keys($allCollectors);
26  $collectorPos = array_search($collectorCode, $collectorCodes);
27  $this->assertNotSame(false, $collectorPos, "'{$collectorCode}' total collector is not found");
28 
29  foreach ($before as $compareWithCode) {
30  $compareWithPos = array_search($compareWithCode, $collectorCodes);
31  if ($compareWithPos === false) {
32  continue;
33  }
34  $this->assertLessThan(
35  $compareWithPos,
36  $collectorPos,
37  "The '{$collectorCode}' collector must go before '{$compareWithCode}'"
38  );
39  }
40 
41  foreach ($after as $compareWithCode) {
42  $compareWithPos = array_search($compareWithCode, $collectorCodes);
43  if ($compareWithPos === false) {
44  continue;
45  }
46  $this->assertGreaterThan(
47  $compareWithPos,
48  $collectorPos,
49  "The '{$collectorCode}' collector must go after '{$compareWithCode}'"
50  );
51  }
52  }
53 
61  protected static function _getConfigCollectors($configType)
62  {
63  switch ($configType) {
64  case 'quote':
65  $configClass = \Magento\Quote\Model\Quote\Address\Total\Collector::class;
66  $methodGetCollectors = 'getCollectors';
67  break;
68  case 'invoice':
69  $configClass = \Magento\Sales\Model\Order\Invoice\Config::class;
70  $methodGetCollectors = 'getTotalModels';
71  break;
72  case 'creditmemo':
73  $configClass = \Magento\Sales\Model\Order\Creditmemo\Config::class;
74  $methodGetCollectors = 'getTotalModels';
75  break;
76  default:
77  throw new \InvalidArgumentException('Unknown config type: ' . $configType);
78  }
80  return $config->{$methodGetCollectors}();
81  }
82 
88  abstract public function collectorPositionDataProvider();
89 }
$config
Definition: fraud_order.php:17
testCollectorPosition($collectorCode, $configType, array $before, array $after)