Open Journal Systems  3.3.0
TestSuiteTestCaseTrait.php
1 <?php
2 /*
3  * citeproc-php
4  *
5  * @link http://github.com/seboettg/citeproc-php for the source repository
6  * @copyright Copyright (c) 2016 Sebastian Böttger.
7  * @license https://opensource.org/licenses/MIT
8  */
9 
10 namespace Seboettg\CiteProc;
11 
12 use PHPUnit\Framework\ExpectationFailedException;
13 use \PHPUnit_Framework_ExpectationFailedException;
15 
17 {
18 
20  static $FILTER = [
21  ];
22 
23 
24  public function _testRenderTestSuite($filterTests, $ignore = null)
25  {
26  $testFiles = loadFixtures($filterTests, $ignore);
27  $i = 0;
28  $failures = [];
29  $success = [];
30  $exceptions = [];
31  foreach ($testFiles as $testFile) {
32 
33  if (in_array($testFile, self::$FILTER)) {
34  continue; //stop testing filtered tests
35  }
36 
37  $testData = json_decode(file_get_contents(PHPUNIT_FIXTURES."/$testFile"));
38  $mode = $testData->mode;
39  if ($mode !== "bibliography" && $mode !== "citation") {
40  continue;
41  }
42 
43  $expected = $testData->result;
44  $citeProc = new CiteProc($testData->csl);
45  ++$i;
46  $echo = sprintf("%03d (%s / %s): ", $i, $testFile, $mode);
47  try {
48  $citationItems = [];
49  if (!empty($testData->citation_items)) {
50  $citationItems = $testData->citation_items;
51  }
52  $actual = $citeProc->render($testData->input, $mode, $citationItems);
53  $this->assertEquals($expected, $actual, "Test case \"$testFile\" ($i) has failed.");
54  //echo "succeeded.\n\n\n";
55  $success[] = $echo . "\n$actual";
56  } catch (ExpectationFailedException $e) {
57  echo "failed\n";
58  $str = $e->getMessage() . "\n" . $e->getComparisonFailure()->getDiff() . "\n\n\n";
59  $failures[] = "$echo\n$str";
60  echo $actual;
61  echo $str;
62  } catch (CiteProcException $e) {
63  //$failures[] =
64  $exceptions[] = "$echo\nCiteProc Exception in $testFile\n".$e->getFile()."\n".$e->getMessage()."\n";
65  } catch (\RuntimeException $e) {
66  //$failures[] = $e->getMessage();
67  $exceptions[] = "$echo\nRuntime Exception in $testFile\n".$e->getFile()." on line ".$e->getLine()."\n".$e->getMessage()."\n";
68  } catch (\Exception $e) {
69  //$failures[] = $e->getMessage();
70  $exceptions[] = "$echo\nException in $testFile\n".$e->getFile()." on line ".$e->getLine()."\n".$e->getMessage()."\n";
71  }
72  }
73  if (!empty($success)) {
74  print count($success)." assertions were succeeded:\n\t".implode("\n\t", $success);
75  }
76 
77  if (!empty($failures)) {
78  print "\n\n".count($failures)." assertions failed:\n\t".implode("\n\t", $failures);
79  throw new ExpectationFailedException(count($failures)." assertions failed:\n\t".implode("\n\t", $failures));
80  }
81 
82  if (!empty($exceptions)) {
83  print "\n\n".count($exceptions)." assertions have caused an exception :\n\t".implode("\n\t", $exceptions);
84  }
85 
86  print "\n\nSummary: ".count($success)."/".count($failures)."/".count($exceptions);
87  print "\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n";
88  }
89 }
Seboettg\CiteProc\TestSuiteTestCaseTrait
trait TestSuiteTestCaseTrait
Definition: TestSuiteTestCaseTrait.php:17
Seboettg\CiteProc
Definition: CiteProc.php:10
Seboettg\CiteProc\_testRenderTestSuite
_testRenderTestSuite($filterTests, $ignore=null)
Definition: TestSuiteTestCaseTrait.php:27
Seboettg\CiteProc\CiteProc
Definition: CiteProc.php:32
Seboettg\Collection\count
count()
Definition: ArrayListTrait.php:253
Seboettg\CiteProc\Exception\CiteProcException
Definition: CiteProcException.php:20