Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AggregateInvoker.php
Go to the documentation of this file.
1 <?php
7 
13 {
17  protected $_testCase;
18 
26  protected $_options = ['verbose' => false];
27 
32  public function __construct($testCase, array $options = [])
33  {
34  $this->_testCase = $testCase;
35  $this->_options = $options + $this->_options;
36  }
37 
46  public function __invoke(callable $callback, array $dataSource)
47  {
48  $results = [
49  \PHPUnit\Framework\IncompleteTestError::class => [],
50  \PHPUnit\Framework\SkippedTestError::class => [],
51  \PHPUnit\Framework\AssertionFailedError::class => [],
52  ];
53  $passed = 0;
54  foreach ($dataSource as $dataSetName => $dataSet) {
55  try {
56  call_user_func_array($callback, $dataSet);
57  $passed++;
58  } catch (\PHPUnit\Framework\IncompleteTestError $exception) {
59  $results[get_class($exception)][] = $this->prepareMessage($exception, $dataSetName, $dataSet);
60  } catch (\PHPUnit\Framework\SkippedTestError $exception) {
61  $results[get_class($exception)][] = $this->prepareMessage($exception, $dataSetName, $dataSet);
62  } catch (\PHPUnit\Framework\AssertionFailedError $exception) {
63  $results[\PHPUnit\Framework\AssertionFailedError::class][] = $this->prepareMessage(
64  $exception,
65  $dataSetName,
66  $dataSet
67  );
68  }
69  }
70  $this->processResults($results, $passed);
71  }
72 
79  protected function prepareMessage(\Exception $exception, $dataSetName, $dataSet)
80  {
81  if (!is_string($dataSetName)) {
82  $dataSetName = var_export($dataSet, true);
83  }
84  if ($exception instanceof \PHPUnit\Framework\AssertionFailedError
85  && !$exception instanceof \PHPUnit\Framework\IncompleteTestError
86  && !$exception instanceof \PHPUnit\Framework\SkippedTestError
87  || $this->_options['verbose']) {
88  $dataSetName = 'Data set: ' . $dataSetName . PHP_EOL;
89  } else {
90  $dataSetName = '';
91  }
92  return $dataSetName . $exception->getMessage() . PHP_EOL
93  . \PHPUnit\Util\Filter::getFilteredStacktrace($exception);
94  }
95 
103  protected function processResults(array $results, $passed)
104  {
105  $totalCountsMessage = sprintf(
106  'Passed: %d, Failed: %d, Incomplete: %d, Skipped: %d.',
107  $passed,
108  count($results[\PHPUnit\Framework\AssertionFailedError::class]),
109  count($results[\PHPUnit\Framework\IncompleteTestError::class]),
110  count($results[\PHPUnit\Framework\SkippedTestError::class])
111  );
112  if ($results[\PHPUnit\Framework\AssertionFailedError::class]) {
113  $this->_testCase->fail(
114  $totalCountsMessage . PHP_EOL .
115  implode(PHP_EOL, $results[\PHPUnit\Framework\AssertionFailedError::class])
116  );
117  }
118  if (!$results[\PHPUnit\Framework\IncompleteTestError::class] &&
119  !$results[\PHPUnit\Framework\SkippedTestError::class]) {
120  return;
121  }
122  $message = $totalCountsMessage . PHP_EOL . implode(
123  PHP_EOL,
124  $results[\PHPUnit\Framework\IncompleteTestError::class]
125  ) . PHP_EOL . implode(
126  PHP_EOL,
127  $results[\PHPUnit\Framework\SkippedTestError::class]
128  );
129  if ($results[\PHPUnit\Framework\IncompleteTestError::class]) {
130  $this->_testCase->markTestIncomplete($message);
131  } elseif ($results[\PHPUnit\Framework\SkippedTestError::class]) {
132  $this->_testCase->markTestSkipped($message);
133  }
134  }
135 }
$results
Definition: popup.phtml:13
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$message
__invoke(callable $callback, array $dataSource)
prepareMessage(\Exception $exception, $dataSetName, $dataSet)