1. Go to this page and download the library: Download tarantool/phpunit-extras library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tarantool / phpunit-extras example snippets
use Tarantool\Client\Client;
use Tarantool\PhpUnit\TestCase;
final class MyTest extends TestCase
{
protected function getClient() : Client
{
// TODO: Implement getClient() method.
}
// ...
}
/**
* @lua tube:put('kick_me')
* @lua tube:bury(0)
*/
public function testKickReleasesBuriedTask() : void
{
// ...
}
/**
* @sql DROP TABLE IF EXISTS foobar
* @sql CREATE TABLE foobar (id INTEGER PRIMARY KEY, name VARCHAR(50))
* @sql INSERT INTO foobar VALUES (1, 'A'), (2, 'B')
*/
public function testExecuteQueryFetchesAllRows() : void
{
// ...
}
use PHPUnit\Framework\TestCase;
use PHPUnitExtras\Expectation\Expectations as BaseExpectations;
use Tarantool\Client\Client;
use Tarantool\PhpUnit\Expectation\RequestExpectations;
final class MyTest extends TestCase
{
use BaseExpectations;
use RequestExpectations;
protected function getClient() : Client
{
// TODO: Implement getClient() method.
}
/**
* @after
*/
protected function verifyTestCaseExpectations() : void
{
$this->verifyExpectations();
}
// ...
}
public function testGetSpaceIsCached() : void
{
$this->client->flushSpaces();
$this->expectSelectRequestToBeCalledOnce();
$this->client->getSpace('test_space');
$this->client->getSpace('test_space');
}
public function testCloseDeallocatesPreparedStatement() : void
{
$stmt = $this->client->prepare('SELECT ?');
$this->expectPreparedStatementToBeDeallocatedOnce();
$stmt->close();
}
use PHPUnit\Framework\TestCase;
use Tarantool\PhpUnit\Client\TestDoubleClient;
final class MyTest extends TestCase
{
use TestDoubleClient;
// ...
}
public function testFoo() : void
{
$dummyClient = $this->createDummyClient();
// ...
}
use Tarantool\Client\Request\PingRequest;
use Tarantool\PhpUnit\TestCase;
final class MyTest extends TestCase
{
public function testFoo() : void
{
$mockClient = $this->getTestDoubleClientBuilder()
->shouldSend(new PingRequest())
->build();
// ...
}
// ...
}
use Tarantool\Client\RequestTypes;
use Tarantool\PhpUnit\Client\TestDoubleFactory;
use Tarantool\PhpUnit\TestCase;
final class MyTest extends TestCase
{
public function testFoo() : void
{
$mockClient = $this->getTestDoubleClientBuilder()
->shouldSend(
RequestTypes::EVALUATE,
RequestTypes::EVALUATE
)->willReceive(
TestDoubleFactory::createResponseFromData([2]),
TestDoubleFactory::createResponseFromData([3])
)->build();
// ...
}
// ...
}