From c12b6ba6713bf8aa5104a15944fcde207658bb95 Mon Sep 17 00:00:00 2001 From: Fonata Date: Mon, 6 Jan 2020 18:07:42 +0100 Subject: [PATCH] Added test for the case of objects as cells I encountered this in Drupal 8, where cells implemented the MarkupInterface. It was objects that, when cast to a string, returned the translated string. Before 5ca540daa74d1a0325d8d720b41014d726dfa81a, this new test would fail. --- tests/methods/HasToString.php | 9 --------- tests/methods/ObjectThatHasToStringMethod.php | 13 +++++++++++++ tests/methods/UnparseTest.php | 12 ++++++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) delete mode 100644 tests/methods/HasToString.php create mode 100644 tests/methods/ObjectThatHasToStringMethod.php diff --git a/tests/methods/HasToString.php b/tests/methods/HasToString.php deleted file mode 100644 index 9c17166..0000000 --- a/tests/methods/HasToString.php +++ /dev/null @@ -1,9 +0,0 @@ -unparseAndCompare($expected); } + public function testObjectCells() { + $this->csv->data = [ + [ + 'column1' => new ObjectThatHasToStringMethod(), + 'column2' => 'boring', + ], + ]; + $this->csv->linefeed = "\n"; + $expected = "column1,column2\nsome value,boring\n"; + $this->unparseAndCompare($expected); + } + private function unparseAndCompare($expected, $fields = array()) { $str = $this->csv->unparse($this->csv->data, $fields); $this->assertEquals($expected, $str);