Skip to content
This repository was archived by the owner on Nov 24, 2017. It is now read-only.

array/object single argument display in stories #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion PHPUnit/Extensions/Story/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
37 changes: 37 additions & 0 deletions Tests/StepTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

require_once 'PHPUnit/Extensions/Story/TestCase.php';
require_once 'PHPUnit/Extensions/Story/Then.php';

class StepTest extends PHPUnit_Framework_TestCase {
protected function setUp() {
parent::setUp();
}

public function testGetArgumentsAsStringWithStringAsArgumentDisplayElementAsString() {
$Step = new PHPUnit_Extensions_Story_Then(array('action', 'keep behavior with string'));
$expected = "keep behavior with string";
$this->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));
}
}