0

So I don't know if anyone has asked this but...

For unit testing, I want to create a mock object that behaves like an array. Not returns an array. I can't just use an array, because the array needs to be of type 'test'.

So somehow...I want the mocked type test object to be set as array('blah', 'blah');

The reason I want to do this is because I am passing the object into a type 'test' restricted parameter of another object.

theamycode
  • 219
  • 3
  • 10

1 Answers1

1

You could use an ArrayObject.

class Test extends ArrayObject or build a Mock class which extends ArrayObject.

This gives you an object of type test with array functionality.

When you use ArrayObject::STD_PROP_LIST you can work with it, like with an normal array.

$a = new Test(array(), ArrayObject::STD_PROP_LIST);
$a['blah'] = 'blah';

See here for STD_PROP_LIST example: https://stackoverflow.com/a/16619183/1163786

Community
  • 1
  • 1
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141