Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed May 19, 2017
1 parent 727d47c commit d5d185e
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 14 deletions.
42 changes: 42 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
build: off
cache:
- c:\php -> appveyor.yml
- '%LOCALAPPDATA%\Composer\files -> appveyor.yml'

clone_folder: c:\projects\orm

services:
- mssql2016

init:
- SET PATH=c:\php;%PATH%
- SET PHP=1
- SET ANSICON=121x90 (121x90)

install:
# Install PHP
- IF EXIST c:\php (SET PHP=0) ELSE (mkdir c:\php)
- IF %PHP%==1 cd c:\php
- IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/releases/archives/php-7.1.0-Win32-VC14-x64.zip
- IF %PHP%==1 7z x php-7.1.0-Win32-VC14-x64.zip >nul
- IF %PHP%==1 echo extension_dir=ext >> php.ini
- IF %PHP%==1 echo extension=php_openssl.dll >> php.ini
- IF %PHP%==1 echo extension=php_sqlsrv_ts.dll >> php.ini
- IF %PHP%==1 appveyor DownloadFile https://github.com/Microsoft/msphpsql/releases/download/4.1.4-Windows/7.1.zip
- IF %PHP%==1 7z x 7.1.zip >nul
- IF %PHP%==1 copy 7.1\x64\php_sqlsrv_71_ts.dll ext\php_sqlsrv_ts.dll
- IF %PHP%==1 del /Q *.zip
- cd c:\projects\orm

# Install Nette Tester
- appveyor DownloadFile https://getcomposer.org/composer.phar
- php composer.phar install --prefer-dist --no-interaction --no-progress

# Create sections.ini, config.mssql.neon & php.ini
- copy tests\sections.appveyor.ini tests\sections.ini
- copy tests\config.mssql.sample.neon tests\config.mssql.neon
- copy tests\php-win.ini tests\php.ini

test_script:
- sqlcmd -S ".\SQL2016" -U sa -P Password12! -Q "CREATE DATABASE nextras_orm_test" -d "master"
- vendor\bin\tester -p php -c tests\php.ini --setup tests\inc\setup.php tests\cases
16 changes: 16 additions & 0 deletions tests/config.mssql.sample.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extensions:
nextras.dbal: Nextras\Dbal\Bridges\NetteDI\DbalExtension
nextras.orm: Nextras\Orm\Bridges\NetteDI\OrmExtension

nextras.dbal:
driver: sqlsrv
host: "(local)\\SQL2016"
username: sa
password: "Password12!"
database: nextras_orm_test

nextras.orm:
model: NextrasTests\Orm\Model

services:
- Nextras\Orm\TestHelper\EntityCreator
Empty file added tests/db/mssql-data.sql
Empty file.
127 changes: 127 additions & 0 deletions tests/db/mssql-init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
CREATE TABLE authors (
id int NOT NULL IDENTITY(1,1),
name varchar(50) NOT NULL,
web varchar(100) NOT NULL,
born date DEFAULT NULL,
favorite_author_id int,
PRIMARY KEY(id),
CONSTRAINT authors_favorite_author FOREIGN KEY (favorite_author_id) REFERENCES authors (id)
);


CREATE TABLE publishers (
publisher_id int NOT NULL IDENTITY(1,1),
name varchar(50) NOT NULL,
PRIMARY KEY(publisher_id)
);


CREATE TABLE tags (
id int NOT NULL IDENTITY(1,1),
name varchar(50) NOT NULL,
is_global char(1) NOT NULL,
PRIMARY KEY (id)
);

CREATE TABLE eans (
id int NOT NULL IDENTITY(1,1),
code varchar(50) NOT NULL,
PRIMARY KEY(id)
);

CREATE TABLE books (
id int NOT NULL IDENTITY(1,1),
author_id int NOT NULL,
translator_id int,
title varchar(50) NOT NULL,
next_part int,
publisher_id int NOT NULL,
published_at datetimeoffset NOT NULL,
printed_at datetimeoffset,
ean_id int,
PRIMARY KEY (id),
CONSTRAINT books_authors FOREIGN KEY (author_id) REFERENCES authors (id),
CONSTRAINT books_translator FOREIGN KEY (translator_id) REFERENCES authors (id),
CONSTRAINT books_next_part FOREIGN KEY (next_part) REFERENCES books (id),
CONSTRAINT books_publisher FOREIGN KEY (publisher_id) REFERENCES publishers (publisher_id),
CONSTRAINT books_ena FOREIGN KEY (ean_id) REFERENCES eans (id)
);

CREATE INDEX book_title ON books (title);


CREATE TABLE books_x_tags (
book_id int NOT NULL,
tag_id int NOT NULL,
PRIMARY KEY (book_id, tag_id),
CONSTRAINT books_x_tags_tag FOREIGN KEY (tag_id) REFERENCES tags (id),
CONSTRAINT books_x_tags_book FOREIGN KEY (book_id) REFERENCES books (id) ON DELETE CASCADE
);


CREATE TABLE tag_followers (
tag_id int NOT NULL,
author_id int NOT NULL,
created_at datetimeoffset NOT NULL,
PRIMARY KEY (tag_id, author_id),
CONSTRAINT tag_followers_tag FOREIGN KEY (tag_id) REFERENCES tags (id) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT tag_followers_author FOREIGN KEY (author_id) REFERENCES authors (id) ON DELETE CASCADE ON UPDATE CASCADE
);


CREATE TABLE contents (
id int NOT NULL,
type varchar(10) NOT NULL,
parent_id int,
PRIMARY KEY (id),
CONSTRAINT contents_parent_id FOREIGN KEY (parent_id) REFERENCES contents (id) ON DELETE NO ACTION ON UPDATE NO ACTIOn
);


CREATE TABLE book_collections (
id int NOT NULL IDENTITY(1,1),
name varchar(255) NOT NULL,
updated_at datetimeoffset NULL,
PRIMARY KEY (id)
);


CREATE TABLE users (
id int NOT NULL IDENTITY(1,1),
PRIMARY KEY(id)
);


CREATE TABLE users_x_users (
my_friends_id int NOT NULL,
friends_with_me_id int NOT NULL,
PRIMARY KEY (my_friends_id, friends_with_me_id),
CONSTRAINT my_friends_key FOREIGN KEY (my_friends_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT friends_with_me_key FOREIGN KEY (friends_with_me_id) REFERENCES users (id) ON DELETE NO ACTION ON UPDATE NO ACTION
);


-- CREATE TRIGGER `book_collections_bu_trigger` BEFORE UPDATE ON `book_collections`
-- FOR EACH ROW SET NEW.updated_at = NOW();
--
-- CREATE TRIGGER `book_collections_bi_trigger` BEFORE INSERT ON `book_collections`
-- FOR EACH ROW SET NEW.updated_at = NOW();


CREATE TABLE photo_albums (
id int NOT NULL IDENTITY(1,1),
title varchar(255) NOT NULL,
preview_id int NULL,
PRIMARY KEY(id)
);

CREATE TABLE photos (
id int NOT NULL IDENTITY(1,1),
title varchar(255) NOT NULL,
album_id int NOT NULL,
PRIMARY KEY(id),
CONSTRAINT photos_album_id FOREIGN KEY (album_id) REFERENCES photo_albums (id) ON DELETE CASCADE ON UPDATE CASCADE
);

ALTER TABLE photo_albums
ADD CONSTRAINT photo_albums_preview_id FOREIGN KEY (preview_id) REFERENCES photos (id) ON DELETE NO ACTION ON UPDATE NO ACTION;
8 changes: 8 additions & 0 deletions tests/db/mssql-reset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types = 1);

use Nextras\Dbal\Connection;

return function (Connection $connection, $dbname) {
// $connection->query('DROP SCHEMA IF EXISTS nextras');
// $connection->query('CREATE SCHEMA nextras');
};
1 change: 1 addition & 0 deletions tests/inc/DataTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protected function setUp()
switch ($this->section) {
case Helper::SECTION_MYSQL:
case Helper::SECTION_PGSQL:
case Helper::SECTION_MSSQL:
$connection = $this->container->getByType(Connection::class);
FileImporter::executeFile($connection, __DIR__ . "/../db/$this->section-data.sql");
break;
Expand Down
20 changes: 9 additions & 11 deletions tests/inc/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

class Helper
{
const SECTION_MSSQL = 'mssql';
const SECTION_MYSQL = 'mysql';
const SECTION_PGSQL = 'pgsql';
const SECTION_ARRAY = 'array';
Expand All @@ -33,20 +34,17 @@ public static function check()

public static function getSection()
{
if (self::isRunByRunner()) {
if (self::isRunForListingMethods()) {
return self::SECTION_ARRAY;
}

if (self::isRunByRunner() && !self::isRunForListingMethods()) {
$tmp = preg_filter('#--dataprovider=(.*)#Ai', '$1', $_SERVER['argv']);
list($query) = explode('|', (string) reset($tmp), 2);
return $query ?: self::SECTION_ARRAY;

} else {
$sections = parse_ini_file(__DIR__ . '/../sections.ini', true);
$sections = array_keys($sections);
return $sections[0];
if ($query) {
return $query;
}
}

$sections = parse_ini_file(__DIR__ . '/../sections.ini', true);
$sections = array_keys($sections);
return $sections[0];
}


Expand Down
8 changes: 5 additions & 3 deletions tests/inc/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Nextras\Dbal\Connection;
use Nextras\Dbal\Utils\FileImporter;
use Nextras\Orm\InvalidStateException;
use NextrasTests\Orm\Helper;


if (@!include __DIR__ . '/../../vendor/autoload.php') {
Expand All @@ -30,8 +31,9 @@
$config = Neon::decode(file_get_contents(__DIR__ . "/../config.$section.neon", true));

switch ($section) {
case 'mysql':
case 'pgsql':
case Helper::SECTION_MYSQL:
case Helper::SECTION_PGSQL:
case Helper::SECTION_MSSQL:
$connection = new Connection($config['nextras.dbal']);

/** @var callable $resetFunction */
Expand All @@ -41,7 +43,7 @@
FileImporter::executeFile($connection, __DIR__ . "/../db/{$section}-init.sql");
break;

case 'array':
case Helper::SECTION_ARRAY:
break;

default:
Expand Down
1 change: 1 addition & 0 deletions tests/php-win.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
extension_dir = "./ext"
extension=php_mysqli.dll
extension=php_pgsql.dll
extension=php_sqlsrv_ts.dll
1 change: 1 addition & 0 deletions tests/sections.appveyor.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[mssql]

0 comments on commit d5d185e

Please sign in to comment.