Skip to content

Instantly share code, notes, and snippets.

@koriym
Created May 16, 2019 03:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koriym/b82ff7956693afd6a4da8e6bf545ad1e to your computer and use it in GitHub Desktop.
Save koriym/b82ff7956693afd6a4da8e6bf545ad1e to your computer and use it in GitHub Desktop.
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