Is it possible to set properties in a Mock Object in Simpletest

I usually use the getter and setter methods for my objects, and I'm fine with testing them as a mock of objects in SimpleTest, manipulating them with code, for example:

Mock::generate('MyObj');
$MockMyObj->setReturnValue('getPropName', 'value')

However, I recently started using magic interceptors (__set () __get ()) and gained access to the following properties:

$MyObj->propName = 'blah';

But I am having difficulty creating a mock object that has a specific property that is accessible using this technique.

So there is a special way to set properties in MockObjects.

I tried to do:

 $MockMyObj->propName = 'test Value';

but this does not seem to work. Not sure if this is my Subject, Mock, magic Interceptors or SimpleTest test, which causes the property to be inaccessible.

So in short:

, . Mock Object Simpletest?

.

+3
1

...

, mocks , , - , .

SimpleTest. :

class MyObj 
   {

   public function __set($name, $value)
    {
    $props[$name] = $value;
    }

   public function __get($name)
    {
    return $props[$name] = $value;
    }

   }

( )

$MyObj->propName = 'blah';
echo $MyObj->propName; //prints blah

Mock::generate('MyObj');
$MockMyObj = new MockMyObj();
$MockMyObj->setReturnValue('__get', 'test property value', array('propName'));

//...later on...
echo $MockMyObj->propName; //prints "test property value"

P.S. :  http://www.simpletest.org/en/mock_objects_documentation.html

P.P.S

, .

+3

Source: https://habr.com/ru/post/1742436/


All Articles