Skip to content

Commit

Permalink
Merge pull request #75 from PhpGt/74-schema
Browse files Browse the repository at this point in the history
Terminology "database" to "schema"
  • Loading branch information
g105b authored Nov 10, 2017
2 parents d1870cc + ce671e6 commit 0d7891b
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/Connection/DefaultSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DefaultSettings implements SettingsInterface {

const DEFAULT_NAME = "default";
const DEFAULT_DATASOURCE = Settings::DRIVER_SQLITE;
const DEFAULT_DATABASE = Settings::DATABASE_IN_MEMORY;
const DEFAULT_SCHEMA = Settings::SCHEMA_IN_MEMORY;
const DEFAULT_HOST = "localhost";
const DEFAULT_PORT = [
Settings::DRIVER_MYSQL => 3306,
Expand Down Expand Up @@ -38,8 +38,8 @@ public function getDataSource():string {
return self::DEFAULT_DATASOURCE;
}

public function getDatabase():string {
return self::DEFAULT_DATABASE;
public function getSchema():string {
return self::DEFAULT_SCHEMA;
}

public function getHost():string {
Expand Down Expand Up @@ -75,7 +75,7 @@ public function getConnectionSettings():array {
"driver" => $this->getDataSource(),
"host" => $this->getHost(),
"port" => $this->getPort(),
"database" => $this->getDatabase(),
"database" => $this->getSchema(),
"username" => $this->getUsername(),
"password" => $this->getPassword(),
"charset" => self::CHARSET,
Expand All @@ -87,7 +87,7 @@ public function getConnectionSettings():array {
public function getConnectionString():string {
return implode(":", [
$this->getDataSource(),
$this->getDatabase(),
$this->getSchema(),
]);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Connection/Driver.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
namespace Gt\Database\Connection;

use Gt\Database\Connection\SettingsInterface;
use PDO;

class Driver {

/** @var SettingsInterface */
protected $settings;
/** @var PDO */
/** @var Connection */
protected $connection;

public function __construct(SettingsInterface $settings) {
Expand Down
18 changes: 9 additions & 9 deletions src/Connection/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class Settings implements SettingsInterface {
const DRIVER_SQLITE = "sqlite";
const DRIVER_SQLSERVER = "dblib";

const DATABASE_IN_MEMORY = ":memory:";
const SCHEMA_IN_MEMORY = ":memory:";

/** @var string */
protected $baseDirectory;
/** @var string */
protected $dataSource;
/** @var string */
protected $database;
protected $schema;
/** @var string */
protected $host;
/** @var int */
Expand All @@ -37,7 +37,7 @@ class Settings implements SettingsInterface {
public function __construct(
string $baseDirectory,
string $dataSource,
string $database = null,
string $schema = null,
string $host = DefaultSettings::DEFAULT_HOST,
int $port = null,
string $username = DefaultSettings::DEFAULT_USERNAME,
Expand All @@ -51,7 +51,7 @@ public function __construct(

$this->baseDirectory = $baseDirectory;
$this->dataSource = $dataSource;
$this->database = $database;
$this->schema = $schema;
$this->host = $host;
$this->port = $port;
$this->username = $username;
Expand All @@ -72,8 +72,8 @@ public function getDataSource():string {
return $this->dataSource;
}

public function getDatabase():string {
return $this->database;
public function getSchema():string {
return $this->schema;
}

public function getHost():string {
Expand Down Expand Up @@ -104,7 +104,7 @@ public function getConnectionSettings():array {
$currentSettings = [
"driver" => $this->getDataSource(),
"host" => $this->getHost(),
"database" => $this->getDatabase(),
"schema" => $this->getSchema(),
"port" => $this->getPort(),
"username" => $this->getUsername(),
"password" => $this->getPassword(),
Expand All @@ -126,12 +126,12 @@ public function getConnectionString():string {

switch($source) {
case self::DRIVER_SQLITE:
$connectionString .= $this->getDatabase();
$connectionString .= $this->getSchema();
break;

default:
$connectionString .= "host=" . $this->getHost();
$connectionString .= ";dbname=" . $this->getDatabase();
$connectionString .= ";dbname=" . $this->getSchema();
$connectionString .= ";charset=" . self::CHARSET;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/SettingsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface SettingsInterface {

public function getBaseDirectory():string;
public function getDataSource():string;
public function getDatabase():string;
public function getSchema():string;
public function getHost():string;
public function getPort():int;
public function getUsername():string;
Expand Down
2 changes: 1 addition & 1 deletion src/Migration/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
string $tableName,
bool $forced
) {
$this->schema = $settings->getDatabase();
$this->schema = $settings->getSchema();
$this->path = $path;
$this->tableName = $tableName;

Expand Down
4 changes: 2 additions & 2 deletions test/unit/Client.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testQueryCollectionPathExists(string $name, string $path) {
$settings = new Settings(
$basePath,
Settings::DRIVER_SQLITE,
Settings::DATABASE_IN_MEMORY
Settings::SCHEMA_IN_MEMORY
);
$db = new Client($settings);

Expand All @@ -38,7 +38,7 @@ public function testQueryCollectionPathNotExists(string $name, string $path) {
$settings = new Settings(
$basePath,
Settings::DRIVER_SQLITE,
Settings::DATABASE_IN_MEMORY
Settings::SCHEMA_IN_MEMORY
);
$db = new Client($settings);
$db->queryCollection($name);
Expand Down
6 changes: 3 additions & 3 deletions test/unit/Connection/DefaultSettings.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public function testDefaults() {
$settings->getDataSource()
);
static::assertEquals(
DefaultSettings::DEFAULT_DATABASE,
$settings->getDatabase()
DefaultSettings::DEFAULT_SCHEMA,
$settings->getSchema()
);
static::assertEquals(
DefaultSettings::DEFAULT_PORT[DefaultSettings::DEFAULT_DATASOURCE],
Expand Down Expand Up @@ -53,7 +53,7 @@ public function testDefaultPort(string $dsn, int $port) {
"driver" => $dsn,
"host" => DefaultSettings::DEFAULT_HOST,
"port" => $port,
"database" => "test-database",
"schema" => "test-database",
"username" => DefaultSettings::DEFAULT_USERNAME,
"password" => DefaultSettings::DEFAULT_PASSWORD,
"charset" => DefaultSettings::CHARSET,
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Connection/Settings.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testPropertiesSet() {

static::assertEquals($this->properties["baseDirectory"], $settings->getBaseDirectory());
static::assertEquals($this->properties["dataSource"], $settings->getDataSource());
static::assertEquals($this->properties["database"], $settings->getDatabase());
static::assertEquals($this->properties["database"], $settings->getSchema());
static::assertEquals($this->properties["host"], $settings->getHost());
static::assertEquals($this->properties["port"], $settings->getPort());
static::assertEquals($this->properties["username"], $settings->getUsername());
Expand Down Expand Up @@ -85,7 +85,7 @@ public function testGetConnectionSettings() {
"driver" => $this->properties["dataSource"],
"host" => $this->properties["host"],
"port" => $this->properties["port"],
"database" => $this->properties["database"],
"schema" => $this->properties["database"],
"username" => $this->properties["username"],
"password" => $this->properties["password"],
"charset" => Settings::CHARSET,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Integration.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function settingsSingleton():Settings {
$this->settings = new Settings(
$this->queryBase,
Settings::DRIVER_SQLITE,
Settings::DATABASE_IN_MEMORY,
Settings::SCHEMA_IN_MEMORY,
"localhost"
);
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Query/QueryCollectionFactory.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testCurrentWorkingDirectoryDefault() {
$driver = new Driver(new Settings(
$baseDir,
Settings::DRIVER_SQLITE,
Settings::DATABASE_IN_MEMORY)
Settings::SCHEMA_IN_MEMORY)
);

$queryCollectionFactory = new QueryCollectionFactory($driver);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Query/SqlQuery.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private function driverSingleton():Driver {
$settings = new Settings(
Helper::getTmpDir(),
Settings::DRIVER_SQLITE,
Settings::DATABASE_IN_MEMORY
Settings::SCHEMA_IN_MEMORY
);
$this->driver = new Driver($settings);
}
Expand Down

0 comments on commit 0d7891b

Please sign in to comment.