Skip to content
Permalink
Browse files

Adds potential repository test setup

  • Loading branch information...
jacobemerick committed Nov 28, 2015
1 parent de1ee7d commit d92e4165e5174685c19780f0aef8dcf811eb5897
Showing with 86 additions and 1 deletion.
  1. +1 −1 phpunit.xml
  2. +6 −0 tests/bootstrap.php
  3. +79 −0 tests/unit/domain/blog/MysqlPostRepositoryTest.php
@@ -1,4 +1,4 @@
<phpunit bootstrap="bootstrap.php">
<phpunit bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="unit">
<directory>tests/unit</directory>
@@ -0,0 +1,6 @@
<?php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');
require_once 'vendor/autoload.php';
@@ -0,0 +1,79 @@
<?php
namespace Jacobemerick\Web\Domain\Blog;
use Aura\Sql\ConnectionLocator;
use Aura\Sql\ExtendedPdo;
class MysqlPostRepositoryTest extends \PHPUnit_Framework_TestCase
{
protected $connections;
public function __construct()
{
$extendedPdo = $this->newExtendedPdo();
$this->connections = new ConnectionLocator(function () use ($extendedPdo) {
return $extendedPdo;
});
}
protected function newExtendedPdo()
{
$extendedPdo = new ExtendedPdo('sqlite::memory:');
$extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`');
$extendedPdo->exec("
CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` (
`id` integer PRIMARY KEY AUTOINCREMENT,
`title` varchar(60) NOT NULL,
`path` varchar(60) NOT NULL,
`category` varchar(20) NOT NULL,
`date` date NOT NULL,
`body` text NOT NULL,
`display` integer NOT NULL
)"
);
return $extendedPdo;
}
public function newMysqlPostRepository()
{
return new MysqlPostRepository($this->connections);
}
public function testFindByUri()
{
$test_post = [
'title' => 'test title',
'path' => 'test-uri',
'category' => 'test',
'date' => date('Y-m-d H:i:s'),
'body' => 'test content',
'display' => 1,
];
$this->connections->getDefault()->perform("
INSERT INTO jpemeric_blog.post
(title, path, category, date, body, display)
VALUES
(:title, :path, :category, :date, :body, :display)",
$test_post);
$post = $this->newMysqlPostRepository()->findByUri($test_post['path']);
$this->assertSame($test_post['path'], $post['path']);
}
public function testIsInstanceOfPostRepository()
{
$this->assertInstanceOf(
'Jacobemerick\Web\Domain\Blog\PostRepository',
$this->newMysqlPostRepository()
);
}
public static function tearDownAfterClass()
{
// $this->connections->getDefault()->disconnect();
unlink('jpemeric_blog.db');
}
}

0 comments on commit d92e416

Please sign in to comment.
You can’t perform that action at this time.