Completed
Push — master ( de1ee7...d92e41 )
by Jacob
04:21
created

MysqlPostRepositoryTest::newExtendedPdo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Blog;
4
5
use Aura\Sql\ConnectionLocator;
6
use Aura\Sql\ExtendedPdo;
7
8
class MysqlPostRepositoryTest extends \PHPUnit_Framework_TestCase
9
{
10
11
    protected $connections;
12
13
    public function __construct()
14
    {
15
        $extendedPdo = $this->newExtendedPdo();
16
        $this->connections = new ConnectionLocator(function () use ($extendedPdo) {
17
            return $extendedPdo;
18
        });
19
    }
20
21
    protected function newExtendedPdo()
22
    {
23
        $extendedPdo = new ExtendedPdo('sqlite::memory:');
24
        $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`');
25
        $extendedPdo->exec("
26
            CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` (
27
              `id` integer PRIMARY KEY AUTOINCREMENT,
28
              `title` varchar(60) NOT NULL,
29
              `path` varchar(60) NOT NULL,
30
              `category` varchar(20) NOT NULL,
31
              `date` date NOT NULL,
32
              `body` text NOT NULL,
33
              `display` integer NOT NULL
34
            )"
35
        );
36
        return $extendedPdo;
37
    }
38
39
    public function newMysqlPostRepository()
40
    {
41
        return new MysqlPostRepository($this->connections);
42
    }
43
44
    public function testFindByUri()
45
    {
46
        $test_post = [
47
            'title' => 'test title',
48
            'path' => 'test-uri',
49
            'category' => 'test',
50
            'date' => date('Y-m-d H:i:s'),
51
            'body' => 'test content',
52
            'display' => 1,
53
        ];
54
55
        $this->connections->getDefault()->perform("
56
            INSERT INTO jpemeric_blog.post
57
                (title, path, category, date, body, display)
58
            VALUES
59
                (:title, :path, :category, :date, :body, :display)",
60
            $test_post);
61
62
        $post = $this->newMysqlPostRepository()->findByUri($test_post['path']);
63
        $this->assertSame($test_post['path'], $post['path']);
64
    }
65
66
    public function testIsInstanceOfPostRepository()
67
    {
68
        $this->assertInstanceOf(
69
            'Jacobemerick\Web\Domain\Blog\PostRepository',
70
            $this->newMysqlPostRepository()
71
        );
72
    }
73
74
    public static function tearDownAfterClass()
75
    {
76
//        $this->connections->getDefault()->disconnect();
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
        unlink('jpemeric_blog.db');
78
    }
79
}
80