From f8fe4cad033b1bd38b3b1bafeeb4697a855f2167 Mon Sep 17 00:00:00 2001 From: Susann Sgorzaly Date: Fri, 23 Feb 2018 10:37:12 +0100 Subject: [PATCH] change accessibility of parse_file and parse_string --- src/Csv.php | 6 +++--- tests/methods/ParseTest.php | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Csv.php b/src/Csv.php index 129fe77..5fe15be 100644 --- a/src/Csv.php +++ b/src/Csv.php @@ -408,7 +408,7 @@ class Csv { if (strlen($input) <= PHP_MAXPATHLEN && is_readable($input)) { $this->file = $input; - $this->data = $this->parse_file($input); + $this->data = $this->parse_file(); } else { $this->file = null; @@ -569,7 +569,7 @@ class Csv { * * @return array|bool */ - public function parse_file($file = null) { + protected function parse_file($file = null) { if (is_null($file)) { $file = $this->file; } @@ -592,7 +592,7 @@ class Csv { * * @return array|false - 2D array with CSV data, or false on failure */ - public function parse_string($data = null) { + protected function parse_string($data = null) { if (empty($data)) { if ($this->_check_data()) { $data = &$this->file_data; diff --git a/tests/methods/ParseTest.php b/tests/methods/ParseTest.php index 9566499..6bf683c 100644 --- a/tests/methods/ParseTest.php +++ b/tests/methods/ParseTest.php @@ -89,7 +89,8 @@ class ParseTest extends TestCase $this->csv->enclosure = '"'; $sInput = "86545235689,a\r\n34365587654,b\r\n13469874576,\"c\r\nd\""; $expected_data = [86545235689, 34365587654, 13469874576]; - $actual_data = $this->csv->parse_string($sInput); + + $actual_data = $this->invokeMethod($this->csv, 'parse_string', array($sInput)); $actual_column = array_map('reset', $actual_data); $this->assertEquals($expected_data, $actual_column); $this->assertEquals([ @@ -198,4 +199,22 @@ class ParseTest extends TestCase $this->assertArrayHasKey('column1', $csv->data[0], 'Data parsed incorrectly with enclosure ' . $enclosure); $this->assertEquals('value1', $csv->data[0]['column1'], 'Data parsed incorrectly with enclosure ' . $enclosure); } + + /** + * Call protected/private method of a class. + * + * @param object &$object Instantiated object that we will run method on. + * @param string $methodName Method name to call + * @param array $parameters Array of parameters to pass into method. + * + * @return mixed Method return. + */ + private function invokeMethod(&$object, $methodName, array $parameters = array()) + { + $reflection = new \ReflectionClass(get_class($object)); + $method = $reflection->getMethod($methodName); + $method->setAccessible(true); + + return $method->invokeArgs($object, $parameters); + } }