0
私はテストに問題があります。TableGateway ZF2/ZF3を使ったクラスのテストを書く
データベーステーブルのすべての行をカウントする関数をクラス内に作成しました。データベースにアクセスするには、Zend Frameworks TableGateway classを使用します。私の問題は、私は関数のテストを書く方法を知らないということです。
これを調べる1つの方法は、機能が非常に単純でテストを必要としないことですが、どのように機能させるかを知っているといいでしょう。
AbstractTableGatewayに内部変数$ adapterを設定できる関数はありません。保護された変数$ adapterをどのように設定できますか?
public function testCount()
{
$sql = "SELECT COUNT(*) AS Count FROM DbTable";
$result = $this->prophesize(Result::class);
$result->current()->willReturn(["Count" => 10]);
$statement = $this->prophesize(Statement::class);
$statement->execute()->willReturn($result);
$adapter = $this->prophesize(Adapter::class);
$adapter->query($sql)->willReturn($statement);
$this->tableGateway->adapter = $adapter;
$this->assertSame(10, $this->DbTable->count());
}