From 2c061a439a02142a6c565f3c9da3708a386c4446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Benoist?= Date: Fri, 6 Jun 2014 11:26:02 +0200 Subject: [PATCH] Allows to display arguments in story tests cases with array/object single argument When using when/then with an array as single argument after action, there was an error triggered. --- PHPUnit/Extensions/Story/Step.php | 6 ++++- Tests/StepTest.php | 37 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Tests/StepTest.php diff --git a/PHPUnit/Extensions/Story/Step.php b/PHPUnit/Extensions/Story/Step.php index 08b5d48..dd736da 100644 --- a/PHPUnit/Extensions/Story/Step.php +++ b/PHPUnit/Extensions/Story/Step.php @@ -108,7 +108,11 @@ public function getArguments($asString = FALSE) break; case 1: { - return $this->arguments[0]; + $arguments = $this->arguments[0]; + if (!is_scalar($arguments)) { + $arguments = var_export($arguments, TRUE); + } + return $arguments; } break; diff --git a/Tests/StepTest.php b/Tests/StepTest.php new file mode 100644 index 0000000..9fe9293 --- /dev/null +++ b/Tests/StepTest.php @@ -0,0 +1,37 @@ +assertEquals($expected, $Step->getArguments(true)); + } + + public function testGetArgumentsAsStringWithSingleArrayAsArgumentDisplayElementAsString() { + $Step = new PHPUnit_Extensions_Story_Then(array('action', array('single element'))); + $expected = "array (\n 0 => 'single element',\n)"; + $this->assertEquals($expected, $Step->getArguments(true)); + } + + public function testGetArgumentsAsStringWithObjectAsArgumentDisplayElementAsString() { + $Step = new PHPUnit_Extensions_Story_Then(array('action', new PHPUnit_Extensions_Story_Then(array('action', array('single element'))))); + $expected = "PHPUnit_Extensions_Story_Then::__set_state(array(" + . "\n 'action' => 'action'," + . "\n 'arguments' => " + . "\n array (" + . "\n 0 => " + . "\n array (" + . "\n 0 => 'single element'," + . "\n )," + . "\n )," + . "\n))"; + $this->assertEquals($expected, $Step->getArguments(true)); + } +}