Skip to content

Commit

Permalink
Added base tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusakov Nikita committed Apr 21, 2014
1 parent d4f6937 commit 4d2c661
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: php

before_script:
- composer install --dev --prefer-source

script: vendor/bin/phpunit

php:
- 5.4
- 5.5
- 5.6
- hhvm

matrix:
allow_failures:
- php: hhvm
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"php": "~5.4",
"ext-pdo": ">1.0.3"
},
"require-dev": {
"phpunit/phpunit": "4.0.*"
},
"autoload": {
"psr-4": {
"Flame\\": "src"
Expand Down
27 changes: 27 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Flame Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
</logging>
</phpunit>
8 changes: 4 additions & 4 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Connection extends \PDO
{
const PLACEHOLDER_REGEX = '~([sbnilf]{0,1}):(\w+)~';
protected static $typeMap = [
's' => \PDO::PARAM_STR,
'' => \PDO::PARAM_STR, // string by default
's' => \PDO::PARAM_STR,
'i' => \PDO::PARAM_INT,
'f' => \PDO::PARAM_STR,
'b' => \PDO::PARAM_BOOL,
'n' => \PDO::PARAM_NULL,
'i' => \PDO::PARAM_INT,
'l' => \PDO::PARAM_LOB,
'f' => \PDO::PARAM_STR
'l' => \PDO::PARAM_LOB
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Statement extends \PDOStatement
*/
private $types;

private function __construct(&$placeholders, &$types)
private function __construct($placeholders, $types)
{
$this->placeholders = $placeholders;
$this->types = $types;
Expand Down
47 changes: 47 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Flame\Test;

use Flame\Connection;

class ConnectionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Connection
*/
private $connection;

protected function setUp()
{
$this->connection = new Connection('sqlite::memory:');
$this->connection->query('CREATE TABLE users (id INT PRIMARY KEY, username CHAR(50), sex BOOL)');
}

public function testFluent()
{
$this->assertSame($this->connection, $this->connection->beginTransaction());
$this->connection->query("INSERT INTO users(username) VALUES('John Doe')");
$this->assertSame($this->connection, $this->connection->rollback());
$this->assertEmpty($this->connection->query('SELECT * FROM users')->fetchAll());
}

public function testParser()
{
$stmt = $this->connection->prepare('SELECT * FROM users WHERE id IN(:default, s:string, i:int, f:float, b:bool, n:null, l:lob)');

$this->assertSame('SELECT * FROM users WHERE id IN(?, ?, ?, ?, ?, ?, ?)', $stmt->queryString);
$this->assertSame(
array('default', 'string', 'int', 'float', 'bool', 'null', 'lob'),
$this->getObjectAttribute($stmt, 'placeholders')
);
$this->assertSame(array(
'default' => \PDO::PARAM_STR,
'string' => \PDO::PARAM_STR,
'int' => \PDO::PARAM_INT,
'float' => \PDO::PARAM_STR,
'bool' => \PDO::PARAM_BOOL,
'null' => \PDO::PARAM_NULL,
'lob' => \PDO::PARAM_LOB
), $this->getObjectAttribute($stmt, 'types'));
}
}

0 comments on commit 4d2c661

Please sign in to comment.