Using setters

49 views
Skip to first unread message

Alan Michel Willms Quinot

unread,
Jul 10, 2013, 11:58:34 AM7/10/13
to phpsp...@googlegroups.com
Hello guys!

How can I set a property in my specified class?

For example, if I do this:

function it_does_something()
{
    $this->my_attribute = 'Value I must set';
    $this->somethingWhichShouldChange()->shouldBe(42);
}

It throws the following exception:

error: Argument 1 passed to PhpSpec\Wrapper\Unwrapper::unwrapAll() must be of the type array, string given, called in
      /xxxxxx/vendor/phpspec/phpspec/src/PhpSpec/Wrapper/Subject.php on line 128 and defined in
      /xxxxxx/vendor/phpspec/phpspec/src/PhpSpec/Wrapper/Unwrapper.php line 10


I can't figure out what is happening.

Can someone help me?

Luis Cordova

unread,
Jul 16, 2013, 12:34:23 AM7/16/13
to phpsp...@googlegroups.com
could you please provide a gist with line numbers?


--
You received this message because you are subscribed to the Google Groups "PHPSpec - Behavior Driven Design (BDD) for PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phpspec-dev...@googlegroups.com.
To post to this group, send email to phpsp...@googlegroups.com.
Visit this group at http://groups.google.com/group/phpspec-dev.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Marco Lopes

unread,
Jul 16, 2013, 2:57:09 AM7/16/13
to phpsp...@googlegroups.com
Hi,

Is the property declared on your class, and is it public?
Any special reason to access the property directly instead of using a setter?

Cheers,
Marco Lopes


--

Cheers,
Marco Lopes

Alan Willms

unread,
Jul 16, 2013, 12:12:34 PM7/16/13
to phpsp...@googlegroups.com
It is a virtual attribute of an ActiveRecord model. There is no actual attribute, it uses magical method __set to defined something like $this->_attributes['my_attribute']


2013/7/16 Marco Lopes <marco.pa...@gmail.com>

Konstantin Kudryashov

unread,
Jul 16, 2013, 2:35:32 PM7/16/13
to phpsp...@googlegroups.com

Prophecy doesn't allow magic to be treated as part of public API. Because it isn't


Konstantin Kudryashov
--- PHP developer, BDD evangelist, Scrum master

a: http://about.me/everzet
b: http://everzet.com
c: https://github.com/everzet
Reply all
Reply to author
Forward
0 new messages