Created
May 16, 2019 03:31
-
-
Save koriym/b82ff7956693afd6a4da8e6bf545ad1e to your computer and use it in GitHub Desktop.
SQLテストテンプレート
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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