1

I'm using phpspec to test my zend 2 module and having issues with testing pass-by-reference. I've read other topics about this that state it's bad design if you are having to do this. I disagree that this a blanket statement.

I need to represent a two-way relationship between classes where two classes have references two each other.

Is there a way for me to get phpspec to test this or is there a better design I need to consider.

Jeremiah
  • 751
  • 9
  • 21

1 Answers1

0

I want to ensure that Class A can return Class B and vice versa.

This is not really a behaviour, but state verification. PhpSpec focuses on behaviour, but what you need to do is still possible:

class ASpec extends ObjectBehavior
{
    function it_exposes_B(B $b)
    {
        $this->beConstructedWith($b); // or $this->setB($b);

        $this->getB()->shouldReturn($b);
    }
}

The BSpec would look similar:

class BSpec extends ObjectBehavior
{
    function it_exposes_A(A $a)
    {
        $this->beConstructedWith($a); // or $this->setA($a);

        $this->getA()->shouldReturn($a);
    }
}
Jakub Zalas
  • 35,761
  • 9
  • 93
  • 125