0

Say you have a method that receives an array as a parameter. That method does some manipulation with that array and then outputs a different array.

public function createArrayForX(array $myArray){
  return $modifiedArray;
}

In order for me to test that the output has some values I need to create some sample cases for my input. It is a tedious work to create arrays manually, especially big ones.

public function testCreateArrayForX(){
  $myArray = []; // **how do I easily create myArray here**
  $this->assertContains("String that I want", $this->sampleClass->createArrayForX($myArray));
}

I tried something like var_dumping my array in the program, copying the result from var_dump and transforming it back to array (Convert var_dump of array back to array variable) and then edit it to make different tests. Is there a simple way or am I doing things wrong if I need this?

So my question is how do you easily create a skeleton for you sample input that you can then change to test different scenarios?

Community
  • 1
  • 1
Claudiu Creanga
  • 8,031
  • 10
  • 71
  • 110

1 Answers1

0
print(var_export($myArray, true)); 

in the program gave me what I need.

Claudiu Creanga
  • 8,031
  • 10
  • 71
  • 110