Skip to content

Instantly share code, notes, and snippets.

@koriym
Created May 16, 2019
Embed
What would you like to do?
SQLテストテンプレート
<?php
use Aura\Sql\ExtendedPdoInterface;
use BEAR\Package\AppInjector;
use Koriym\QueryLocator\QueryLocatorInterface;
use PHPUnit\Framework\TestCase;
use Ray\Di\InjectorInterface;
use Ray\Query\RowInterface;
/**
* SQL test template
*
* 複雑なSQLはResourceObjectに組み込む前に単体でテストを行います。
* 生PDO(PdoInterface), Aura.Sql(ExtendedPdoInterface)、Ray.Queryの3つの方法があります。
*
* @see https://github.com/koriym/Koriym.QueryLocator
*/
class SqlTest extends TestCase
{
/**
* @var ExtendedPdoInterface
*/
private $pdo;
/**
* SQL QueryLocator
*
* @var string
*/
private $sql;
/**
* @var InjectorInterface
*/
private $injector;
protected function setUp() : void
{
$this->injector = (new AppInjector('MyVendor\Api', 'test-hal-api-app'));
$this->pdo = $this->injector->getInstance(ExtendedPdoInterface::class);
$sqlDir = dirname(__DIR__, 2) . '/var/sql';
$this->sql = new QueryLocator($sqlDir);
}
public function testAuraSqlSample()
{
$result = $this->pdo->fetchAssoc($this->sql['sql_name'], ['param' => '0']);
$this->assertSame([], $result);
}
 public function testQuerySample()
{
$row = $this->injector->getInstance(RowInterface::class, 'sql_name');
$result = $row(['param0' => '0']);
$this->assertSame([], $result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment