我正在尝试使用 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
用于工匠的修补匠时,它们工作得很好。
似乎在我的测试环境中,会话设置有问题。
如何解决这个问题?