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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.