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/8] 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/8] 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/8] 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/8] 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/8] 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); } /** From 92653c99c5fb709505e2e31567f1fa4e346b6fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bl=C3=A4ul?= Date: Sun, 18 Feb 2018 19:31:24 +0100 Subject: [PATCH 6/8] Force predictable working dir; create autoloader file if it doesn't exist --- tests/Bootstrap.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index eb6dd93..88df893 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -1,4 +1,9 @@ Date: Sun, 18 Feb 2018 19:34:06 +0100 Subject: [PATCH 7/8] Absolute path in require do stop PhpStorm from nagging (PhpStorm couldn't find the file) --- tests/Bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 88df893..797e5b4 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -4,7 +4,7 @@ if (!file_exists('vendor/autoload.php')) { `composer dump-autoload`; } -require './vendor/autoload.php'; +require __DIR__ . '/../vendor/autoload.php'; if (!class_exists('PHPUnit\Framework\TestCase')) { // we run on an older PHPUnit version without namespaces. From af7368378c12cdd1a70e6dc64cb090349b0718de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bl=C3=A4ul?= Date: Sun, 18 Feb 2018 19:40:21 +0100 Subject: [PATCH 8/8] Changed tests to work now that we have a namespace --- tests/properties/default_values_test.php | 4 ++-- tests/properties/worthless_test.php | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/properties/default_values_test.php b/tests/properties/default_values_test.php index 74077ca..ab803b9 100644 --- a/tests/properties/default_values_test.php +++ b/tests/properties/default_values_test.php @@ -11,7 +11,7 @@ class default_values_properties_Test extends TestCase { * The parseCSV object * * @access protected - * @var [parseCSV] + * @var Csv */ protected $csv = null; @@ -23,7 +23,7 @@ class default_values_properties_Test extends TestCase { */ public function setUp() { //setup parse CSV - $this->csv = new parseCSV(); + $this->csv = new Csv(); } /** diff --git a/tests/properties/worthless_test.php b/tests/properties/worthless_test.php index 7a9b993..36f036b 100644 --- a/tests/properties/worthless_test.php +++ b/tests/properties/worthless_test.php @@ -11,7 +11,7 @@ class DefaultValuesTest extends TestCase { * The parseCSV object * * @access protected - * @var [parseCSV] + * @var Csv */ protected $csv = null; @@ -20,7 +20,7 @@ class DefaultValuesTest extends TestCase { * The reflection class object * * @access protected - * @var [ReflectionClass] + * @var \ReflectionClass */ protected $reflection = null; @@ -28,6 +28,7 @@ class DefaultValuesTest extends TestCase { * Reflection Properties * The reflected class properties * + * @var \ReflectionProperty[] * @access protected */ protected $properties = null; @@ -43,7 +44,7 @@ class DefaultValuesTest extends TestCase { $this->csv = new Csv(); //setup the reflection class - $this->reflection = new ReflectionClass($this->csv); + $this->reflection = new \ReflectionClass($this->csv); //setup the reflected class properties $this->properties = $this->reflection->getProperties(); @@ -116,7 +117,7 @@ class DefaultValuesTest extends TestCase { ); // Find our real properties - $real_properties = array_map(function (ReflectionProperty $property) { + $real_properties = array_map(function (\ReflectionProperty $property) { return $property->getName(); }, $this->properties);