From cfa057f3baf2a45771419ab6ffd2f78e78441624 Mon Sep 17 00:00:00 2001 From: Xavier Roussel Date: Tue, 17 Jul 2018 17:51:30 +0200 Subject: [PATCH] Keep only the most complete data --- src/Models/Journal.php | 3 +++ src/Models/Model.php | 2 +- tests/Integration/RegressionTest.php | 29 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/Integration/RegressionTest.php diff --git a/src/Models/Journal.php b/src/Models/Journal.php index 1d4a973..808502c 100644 --- a/src/Models/Journal.php +++ b/src/Models/Journal.php @@ -21,6 +21,9 @@ public function add(array $journal): array { foreach ($journal as $key => $value) { if ($this->shouldKeepAttribute($key, $value)) { + if (is_array($value)) { + $value = array_unique($value); + } $this->list[$key] = $value; } } diff --git a/src/Models/Model.php b/src/Models/Model.php index 4a910ad..f3c9bfc 100644 --- a/src/Models/Model.php +++ b/src/Models/Model.php @@ -80,7 +80,7 @@ protected function shouldKeepAttribute(string $key, $value): bool return true; } - return $function($this->list[$key]) > $function($value); + return $function($this->list[$key]) < $function($value); } /** diff --git a/tests/Integration/RegressionTest.php b/tests/Integration/RegressionTest.php new file mode 100644 index 0000000..d9484d8 --- /dev/null +++ b/tests/Integration/RegressionTest.php @@ -0,0 +1,29 @@ +handle()); + + $output = $dataFetcher->fetch(); + + $this->assertArrayIsValid($output->getData()); + + $issnIdentifiers = array_filter($output->getData()['identifiers'], function ($identifier) { + return 'issn' === $identifier['type']; + }); + + $this->assertCount(1, $issnIdentifiers); + $this->assertTrue('John Wiley & Sons, Inc.' === $output->getData()['journal']['publisher']); + $this->assertCount(1, $output->getData()['journal']['issn']); + } +}