phpspec で非常に単純なクラスをテストしようとしています。
テストする必要のあるクラスのメソッド
/**
* @param Store $session
*/
function __construct(Store $session)
{
$this->session = $session;
}
/**
* @param Store $session
*/
function __construct(Store $session)
{
$this->session = $session;
}
/**
* Set the current order id
*
* @param $orderId
*/
public function setCurrentOrderId($orderId)
{
$this->session->set($this->sessionVariableName, $orderId);
return $this;
}
/**
* Get the current order id
*
* @return mixed
*/
public function getCurrentOrderId()
{
return $this->session->get($this->sessionVariableName);
}
そしてテストの一部
use Illuminate\Session\Store;
class CheckoutSpec extends ObjectBehavior
{
function let(Store $session)
{
$this->beConstructedWith($session);
}
function it_is_initializable()
{
$this->shouldHaveType('Spatie\Checkout\Checkout');
}
function it_stores_an_orderId()
{
$this->setCurrentOrderId('testvalue');
$this->getCurrentOrderId()->shouldReturn('testvalue');
}
}
残念ながら、テストはit_stores_an_orderId
このエラーで失敗しますexpected "testvalue", but got null.
メソッドsetCurrentOrderId
とgetCurrentOrderId
が職人の手直しで使用される場合、それらは問題なく機能します。
私のテスト環境では、セッションのセットアップに問題があるようです。
この問題はどのように解決できますか?