From f702ca93fe16f27190163641c88afc696709c9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bl=C3=A4ul?= Date: Sun, 18 Feb 2018 19:00:24 +0100 Subject: [PATCH 1/5] Float regex: Don't allow double dot; do allow 'e' for exponentials --- extensions/DatatypeTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/DatatypeTrait.php b/extensions/DatatypeTrait.php index 6a242b1..7d5359f 100644 --- a/extensions/DatatypeTrait.php +++ b/extensions/DatatypeTrait.php @@ -36,7 +36,7 @@ trait DatatypeTrait { return 'integer'; } - if (preg_match('/^[+-]?([0-9]*[.])?([0-9]|[.][0-9])+$/', $value)) { + if (preg_match('/(^[+-]?$)|(^[+-]?[0-9]+([,.][0-9])?[0-9]*(e[+-]?[0-9]+)?$)/', $value)) { return 'float'; } From 736bc489e64e58ed205d2d1e60411a4b54b005c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bl=C3=A4ul?= Date: Sun, 18 Feb 2018 19:01:47 +0100 Subject: [PATCH 2/5] getDatatypes: throw more meaningful exception if no data is present --- extensions/DatatypeTrait.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/DatatypeTrait.php b/extensions/DatatypeTrait.php index 7d5359f..cf48489 100644 --- a/extensions/DatatypeTrait.php +++ b/extensions/DatatypeTrait.php @@ -74,12 +74,17 @@ trait DatatypeTrait { * * @access public * + * @uses getDatatypeFromString + * * @return array|bool */ public function getDatatypes() { if (empty($this->data)) { $this->data = $this->parse_string(); } + if (!is_array($this->data)) { + throw new \Exception('No data set yet.'); + } $result = []; foreach ($this->titles as $cName) { From 9551862a95a563b6f4a59fcafe857cde70d868a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bl=C3=A4ul?= Date: Sun, 18 Feb 2018 19:02:37 +0100 Subject: [PATCH 3/5] Allow current working dir to be different when running tests ...By using an absolute path --- tests/methods/ParseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/methods/ParseTest.php b/tests/methods/ParseTest.php index 291f81e..ddbdc5e 100644 --- a/tests/methods/ParseTest.php +++ b/tests/methods/ParseTest.php @@ -132,7 +132,7 @@ class ParseTest extends PHPUnit\Framework\TestCase { * @depends testSepRowAutoDetection */ public function testGetColumnDatatypes() { - $this->csv->auto('tests/methods/fixtures/datatype.csv'); + $this->csv->auto(__DIR__ . '/fixtures/datatype.csv'); $this->csv->getDatatypes(); $expected = [ 'title' => 'string', From 2b17f01a0a8064135d89213189823c7a7eb9d822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bl=C3=A4ul?= Date: Sun, 18 Feb 2018 19:03:23 +0100 Subject: [PATCH 4/5] Removed additional column to make expected data fit to fixture --- tests/methods/fixtures/datatype.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/methods/fixtures/datatype.csv b/tests/methods/fixtures/datatype.csv index ef367b0..83e6019 100644 --- a/tests/methods/fixtures/datatype.csv +++ b/tests/methods/fixtures/datatype.csv @@ -1,5 +1,5 @@ sep=; -title;isbn;publishedAt;published;count;price; +title;isbn;publishedAt;published;count;price Красивая кулинария;5454-5587-3210;21.05.2011;true;1;10.99 The Wine Connoisseurs;2547-8548-2541;12.12.2011;TRUE;;20,33 Weißwein;1313-4545-8875;23.02.2012;false;10;10 From d4f9c9f020018e3c74edb619e95a531af34e3f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bl=C3=A4ul?= Date: Sun, 18 Feb 2018 19:04:16 +0100 Subject: [PATCH 5/5] Updated worthless_test to allow for more fields --- tests/properties/worthless_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/properties/worthless_test.php b/tests/properties/worthless_test.php index 5459b59..32e94d7 100644 --- a/tests/properties/worthless_test.php +++ b/tests/properties/worthless_test.php @@ -65,7 +65,7 @@ class worthless_properties_Test extends PHPUnit\Framework\TestCase { * @access public */ public function test_propertiesCount() { - $this->assertCount(28, $this->properties); + $this->assertCount(29, $this->properties); } /**