Skip to content

Commit

Permalink
Merge d339007 into dcc3e51
Browse files Browse the repository at this point in the history
  • Loading branch information
othercorey authored May 11, 2020
2 parents dcc3e51 + d339007 commit 51b2b8f
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 286 deletions.
7 changes: 1 addition & 6 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ clone_folder: C:\projects\phinx
clone_depth: 10

environment:
TESTS_PHINX_DB_ADAPTER_SQLSRV_ENABLED: true
TESTS_PHINX_DB_ADAPTER_SQLSRV_HOST: localhost
TESTS_PHINX_DB_ADAPTER_SQLSRV_USERNAME: sa
TESTS_PHINX_DB_ADAPTER_SQLSRV_PASSWORD: Password12!
TESTS_PHINX_DB_ADAPTER_SQLSRV_DATABASE: phinxtesting
TESTS_PHINX_DB_ADAPTER_SQLSRV_PORT: 1433
SQLSRV_DSN: 'sqlsrv://sa:Password12!@localhost:1433/phinxtesting'

services:
- mssql2012sp1
Expand Down
2 changes: 2 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage_clover: clover.xml
json_path: coveralls-upload.json
7 changes: 1 addition & 6 deletions .github/workflows/mysql8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,5 @@ jobs:

- name: Run PHPUnit
env:
TESTS_PHINX_DB_ADAPTER_MYSQL_ENABLED: "true"
TESTS_PHINX_DB_ADAPTER_MYSQL_HOST: "127.0.0.1"
TESTS_PHINX_DB_ADAPTER_MYSQL_USERNAME: "root"
TESTS_PHINX_DB_ADAPTER_MYSQL_PASSWORD: ""
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE: "phinx_testing"
TESTS_PHINX_DB_ADAPTER_MYSQL_PORT: "3306"
MYSQL_DSN='mysql://root@127.0.0.1/phinx_testing'
run: vendor/bin/phpunit --verbose --no-configuration --bootstrap tests/phpunit-bootstrap.php tests/
53 changes: 36 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,67 @@
language: php

addons:
postgresql: "9.6"
dist: xenial

services:
- postgresql
- mysql

addons:
postgresql: "9.6"

php:
- 7.2
- 7.4

env:
global:
- DEFAULT=1
- CODECOVERAGE=1
matrix:
- PGSQL_DSN='pgsql://postgres@127.0.0.1/phinx_testing'
- MYSQL_DSN='mysql://root@127.0.0.1/phinx_testing' MYSQL_UNIX_SOCKET='/var/run/mysqld/mysqld.sock'
- SQLITE_DSN='sqlite:///phinx_testing'

matrix:
include:
- php: 7.2
env: PREFER_LOWEST=1
env: PREFER_LOWEST=1 CODECOVERAGE=0

- php: 7.4
env: CHECKS=1 DEFAULT=0
env: CHECKS=1 CODECOVERAGE=0

before_install:
- if [[ $DEFAULT != 1 ]]; then phpenv config-rm xdebug.ini; fi
- if [[ -v $MYSQL_DSN ]]; then mysql -e 'create database phinx_testing;'; fi
- if [[ -v $PGSQL_DSN ]]; then psql -c 'create database phinx_testing;' -U postgres; fi
- if [[ -v $PGSQL_DSN ]]; then psql -c 'create extension if not exists citext;' -U postgres; fi

- |
if [[ $CODECOVERAGE == 1 ]]; then
pecl channel-update pecl.php.net
pecl install pcov
fi
before_script:
- if [[ $PREFER_LOWEST != 1 ]]; then travis_retry composer update --no-interaction --prefer-stable; fi
- if [[ $PREFER_LOWEST == 1 ]]; then travis_retry composer update --no-interaction --prefer-stable --prefer-lowest; fi
- phpenv config-rm xdebug.ini

- if [[ $DEFAULT == 1 ]]; then mysql -e 'create database phinx_testing;'; fi
- if [[ $DEFAULT == 1 ]]; then psql -c 'create database phinx_testing;' -U postgres; fi
- if [[ $DEFAULT == 1 ]]; then psql -c 'create extension if not exists citext;' -U postgres; fi
install:
- if [[ $PREFER_LOWEST != 1 ]]; then travis_retry composer update --no-interaction --prefer-stable; fi
- if [[ $PREFER_LOWEST == 1 ]]; then travis_retry composer update --no-interaction --prefer-stable --prefer-lowest; fi

- if [[ $CHECKS == 1 ]]; then composer require --dev phpstan/phpstan:^0.12; fi
- if [[ $CHECKS == 1 ]]; then composer require --dev phpstan/phpstan:^0.12; fi

script:
- if [[ $DEFAULT == 1 ]]; then vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover; fi
- if [[ $CHECKS == 1 ]]; then composer stan; fi
- if [[ $CHECKS == 1 ]]; then composer cs-check; fi
- if [[ $CODECOVERAGE == 1 ]]; then vendor/bin/phpunit --verbose --coverage-clover=clover.xml; fi
- if [[ $PREFER_LOWEST == 1 ]]; then vendor/bin/phpunit --verbose; fi

- if [[ $CHECKS == 1 ]]; then composer stan; fi
- if [[ $CHECKS == 1 ]]; then composer cs-check; fi

after_success:
- if [[ $DEFAULT = 1 ]]; then bash <(curl -s https://codecov.io/bash); fi
- |
if [[ $CODECOVERAGE == 1 ]]; then
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
chmod +x php-coveralls.phar
./php-coveralls.phar
fi
cache:
directories:
Expand Down
39 changes: 12 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,18 @@
* repository.
-->
<php>
<!-- SqlServer -->
<env name="TESTS_PHINX_DB_ADAPTER_SQLSRV_ENABLED" value="false"/>
<env name="TESTS_PHINX_DB_ADAPTER_SQLSRV_HOST" value="localhost"/>
<env name="TESTS_PHINX_DB_ADAPTER_SQLSRV_USERNAME" value="vagrant"/>
<env name="TESTS_PHINX_DB_ADAPTER_SQLSRV_PASSWORD" value="vagrant"/>
<env name="TESTS_PHINX_DB_ADAPTER_SQLSRV_DATABASE" value="test"/>
<env name="TESTS_PHINX_DB_ADAPTER_SQLSRV_PORT" value="1433"/>
<!-- MySQL -->
<env name="TESTS_PHINX_DB_ADAPTER_MYSQL_ENABLED" value="true"/>
<env name="TESTS_PHINX_DB_ADAPTER_MYSQL_HOST" value="127.0.0.1"/>
<env name="TESTS_PHINX_DB_ADAPTER_MYSQL_USERNAME" value="root"/>
<env name="TESTS_PHINX_DB_ADAPTER_MYSQL_PASSWORD" value=""/>
<env name="TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE" value="phinx_testing"/>
<env name="TESTS_PHINX_DB_ADAPTER_MYSQL_PORT" value="3306"/>
<!-- PostgreSQL -->
<env name="TESTS_PHINX_DB_ADAPTER_POSTGRES_ENABLED" value="true"/>
<env name="TESTS_PHINX_DB_ADAPTER_POSTGRES_HOST" value="127.0.0.1"/>
<env name="TESTS_PHINX_DB_ADAPTER_POSTGRES_USERNAME" value="postgres"/>
<env name="TESTS_PHINX_DB_ADAPTER_POSTGRES_PASSWORD" value=""/>
<env name="TESTS_PHINX_DB_ADAPTER_POSTGRES_DATABASE" value="phinx_testing"/>
<env name="TESTS_PHINX_DB_ADAPTER_POSTGRES_DATABASE_SCHEMA" value="public"/>
<env name="TESTS_PHINX_DB_ADAPTER_POSTGRES_PORT" value="5432"/>
<!-- SQLite -->
<env name="TESTS_PHINX_DB_ADAPTER_SQLITE_ENABLED" value="true"/>
<env name="TESTS_PHINX_DB_ADAPTER_SQLITE_DATABASE" value="phinx_testing"/>
<env name="TESTS_PHINX_DB_ADAPTER_SQLITE_SUFFIX" value=".sqlite3"/>
<env name="TESTS_PHINX_DB_ADAPTER_SQLITE_MEMORY" value="false"/>
<!-- SqlServer
<env name="SQLSRV_DSN" value="sqlsrv://user:pass@localhost/test"/>
-->
<!-- MySQL
<env name="MYSQL_DSN" value="mysql://root@127.0.0.1/test"/>
-->
<!-- PostgreSQL
<env name="PGSQL_DSN" value="pgsql://postgres@127.0.0.1/test"/>
-->
<!-- SQLite
<env name="SQLITE_DSN" value="sqlite:///:memory:"/>
-->
</php>

<testsuite name="phinx">
Expand Down
6 changes: 3 additions & 3 deletions src/Phinx/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function connect()
}
}

$db = $this->createPdoConnection($dsn, $options['user'], $options['pass'], $driverOptions);
$db = $this->createPdoConnection($dsn, $options['user'] ?? null, $options['pass'] ?? null, $driverOptions);

$this->setConnection($db);
}
Expand Down Expand Up @@ -1398,8 +1398,8 @@ public function getDecoratedConnection()
{
$options = $this->getOptions();
$options = [
'username' => $options['user'],
'password' => $options['pass'],
'username' => $options['user'] ?? null,
'password' => $options['pass'] ?? null,
'database' => $options['name'],
'quoteIdentifiers' => true,
] + $options;
Expand Down
6 changes: 3 additions & 3 deletions src/Phinx/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function connect()
$driverOptions[PDO::ATTR_DEFAULT_FETCH_MODE] = constant('\PDO::FETCH_' . strtoupper($options['fetch_mode']));
}

$db = $this->createPdoConnection($dsn, $options['user'], $options['pass'], $driverOptions);
$db = $this->createPdoConnection($dsn, $options['user'] ?? null, $options['pass'] ?? null, $driverOptions);

try {
if (isset($options['schema'])) {
Expand Down Expand Up @@ -1446,8 +1446,8 @@ public function getDecoratedConnection()
{
$options = $this->getOptions();
$options = [
'username' => $options['user'],
'password' => $options['pass'],
'username' => $options['user'] ?? null,
'password' => $options['pass'] ?? null,
'database' => $options['name'],
'quoteIdentifiers' => true,
] + $options;
Expand Down
70 changes: 23 additions & 47 deletions tests/Phinx/Db/Adapter/MysqlAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,15 @@ class MysqlAdapterTest extends TestCase

public function setUp(): void
{
if (!TESTS_PHINX_DB_ADAPTER_MYSQL_ENABLED) {
$this->markTestSkipped('Mysql tests disabled. See TESTS_PHINX_DB_ADAPTER_MYSQL_ENABLED constant.');
if (!defined('MYSQL_DB_CONFIG')) {
$this->markTestSkipped('Mysql tests disabled.');
}

$options = [
'host' => TESTS_PHINX_DB_ADAPTER_MYSQL_HOST,
'name' => TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE,
'user' => TESTS_PHINX_DB_ADAPTER_MYSQL_USERNAME,
'pass' => TESTS_PHINX_DB_ADAPTER_MYSQL_PASSWORD,
'port' => TESTS_PHINX_DB_ADAPTER_MYSQL_PORT,
];
$this->adapter = new MysqlAdapter($options, new ArrayInput([]), new NullOutput());
$this->adapter = new MysqlAdapter(MYSQL_DB_CONFIG, new ArrayInput([]), new NullOutput());

// ensure the database is empty for each test
$this->adapter->dropDatabase($options['name']);
$this->adapter->createDatabase($options['name']);
$this->adapter->dropDatabase(MYSQL_DB_CONFIG['name']);
$this->adapter->createDatabase(MYSQL_DB_CONFIG['name']);

// leave the adapter in a disconnected state for each test
$this->adapter->disconnect();
Expand Down Expand Up @@ -78,13 +71,7 @@ public function testConnectionWithoutPort()

public function testConnectionWithInvalidCredentials()
{
$options = [
'host' => TESTS_PHINX_DB_ADAPTER_MYSQL_HOST,
'name' => TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE,
'port' => TESTS_PHINX_DB_ADAPTER_MYSQL_PORT,
'user' => 'invaliduser',
'pass' => 'invalidpass',
];
$options = ['user' => 'invalid', 'pass' => 'invalid'] + MYSQL_DB_CONFIG;

try {
$adapter = new MysqlAdapter($options, new ArrayInput([]), new NullOutput());
Expand All @@ -102,18 +89,12 @@ public function testConnectionWithInvalidCredentials()

public function testConnectionWithSocketConnection()
{
if (!TESTS_PHINX_DB_ADAPTER_MYSQL_UNIX_SOCKET) {
$this->markTestSkipped('MySQL socket connection skipped. See TESTS_PHINX_DB_ADAPTER_MYSQL_UNIX_SOCKET constant.');
if (!getenv('MYSQL_UNIX_SOCKET')) {
$this->markTestSkipped('MySQL socket connection skipped.');
}

$options = [
'name' => TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE,
'user' => TESTS_PHINX_DB_ADAPTER_MYSQL_USERNAME,
'pass' => TESTS_PHINX_DB_ADAPTER_MYSQL_PASSWORD,
'unix_socket' => TESTS_PHINX_DB_ADAPTER_MYSQL_UNIX_SOCKET,
];

$adapter = new MysqlAdapter($options, new ArrayInput([]), new NullOutput());
$options = ['unix_socket' => getenv('MYSQL_UNIX_SOCKET')] + MYSQL_DB_CONFIG;
$adapter = new MysqlAdapter(MYSQL_DB_CONFIG, new ArrayInput([]), new NullOutput());
$adapter->connect();

$this->assertInstanceOf('\PDO', $this->adapter->getConnection());
Expand Down Expand Up @@ -189,7 +170,7 @@ public function testCreateTableWithComment()

$rows = $this->adapter->fetchAll(sprintf(
"SELECT TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='%s' AND TABLE_NAME='ntable'",
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE
MYSQL_DB_CONFIG['name']
));
$comment = $rows[0];

Expand Down Expand Up @@ -217,7 +198,7 @@ public function testCreateTableWithForeignKeys()
"SELECT table_name, column_name, referenced_table_name, referenced_column_name
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE table_schema='%s' AND REFERENCED_TABLE_NAME='ntable_tag'",
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE
MYSQL_DB_CONFIG['name']
));
$foreignKey = $rows[0];

Expand Down Expand Up @@ -410,12 +391,7 @@ public function testCreateTableWithMyISAMEngine()

public function testCreateTableAndInheritDefaultCollation()
{
$options = [
'host' => TESTS_PHINX_DB_ADAPTER_MYSQL_HOST,
'name' => TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE,
'user' => TESTS_PHINX_DB_ADAPTER_MYSQL_USERNAME,
'pass' => TESTS_PHINX_DB_ADAPTER_MYSQL_PASSWORD,
'port' => TESTS_PHINX_DB_ADAPTER_MYSQL_PORT,
$options = MYSQL_DB_CONFIG + [
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
];
Expand Down Expand Up @@ -551,7 +527,7 @@ public function testAddComment()
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='%s'
AND TABLE_NAME='%s'",
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE,
MYSQL_DB_CONFIG['name'],
'table1'
)
);
Expand All @@ -573,7 +549,7 @@ public function testChangeComment()
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='%s'
AND TABLE_NAME='%s'",
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE,
MYSQL_DB_CONFIG['name'],
'table1'
)
);
Expand All @@ -595,7 +571,7 @@ public function testDropComment()
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='%s'
AND TABLE_NAME='%s'",
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE,
MYSQL_DB_CONFIG['name'],
'table1'
)
);
Expand Down Expand Up @@ -1135,7 +1111,7 @@ public function testDescribeTable()

$this->assertContains($described['TABLE_TYPE'], ['VIEW', 'BASE TABLE']);
$this->assertEquals($described['TABLE_NAME'], 't');
$this->assertEquals($described['TABLE_SCHEMA'], TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE);
$this->assertEquals($described['TABLE_SCHEMA'], MYSQL_DB_CONFIG['name']);
$this->assertEquals($described['TABLE_ROWS'], 0);
}

Expand Down Expand Up @@ -1190,7 +1166,7 @@ public function testAddIndexWithLimit()
$this->assertTrue($table->hasIndex('email'));
$index_data = $this->adapter->query(sprintf(
'SELECT SUB_PART FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = "%s" AND TABLE_NAME = "table1" AND INDEX_NAME = "email"',
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE
MYSQL_DB_CONFIG['name']
))->fetch(\PDO::FETCH_ASSOC);
$expected_limit = $index_data['SUB_PART'];
$this->assertEquals($expected_limit, 50);
Expand All @@ -1208,13 +1184,13 @@ public function testAddMultiIndexesWithLimitSpecifier()
$this->assertTrue($table->hasIndex(['email', 'username']));
$index_data = $this->adapter->query(sprintf(
'SELECT SUB_PART FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = "%s" AND TABLE_NAME = "table1" AND INDEX_NAME = "email" AND COLUMN_NAME = "email"',
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE
MYSQL_DB_CONFIG['name']
))->fetch(\PDO::FETCH_ASSOC);
$expected_limit = $index_data['SUB_PART'];
$this->assertEquals($expected_limit, 3);
$index_data = $this->adapter->query(sprintf(
'SELECT SUB_PART FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = "%s" AND TABLE_NAME = "table1" AND INDEX_NAME = "email" AND COLUMN_NAME = "username"',
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE
MYSQL_DB_CONFIG['name']
))->fetch(\PDO::FETCH_ASSOC);
$expected_limit = $index_data['SUB_PART'];
$this->assertEquals($expected_limit, 2);
Expand All @@ -1232,7 +1208,7 @@ public function testAddSingleIndexesWithLimitSpecifier()
$this->assertTrue($table->hasIndex('email'));
$index_data = $this->adapter->query(sprintf(
'SELECT SUB_PART FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = "%s" AND TABLE_NAME = "table1" AND INDEX_NAME = "email" AND COLUMN_NAME = "email"',
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE
MYSQL_DB_CONFIG['name']
))->fetch(\PDO::FETCH_ASSOC);
$expected_limit = $index_data['SUB_PART'];
$this->assertEquals($expected_limit, 3);
Expand Down Expand Up @@ -1467,7 +1443,7 @@ public function testsHasForeignKeyWithSchemaDotTableName()
public function testHasDatabase()
{
$this->assertFalse($this->adapter->hasDatabase('fake_database_name'));
$this->assertTrue($this->adapter->hasDatabase(TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE));
$this->assertTrue($this->adapter->hasDatabase(MYSQL_DB_CONFIG['name']));
}

public function testDropDatabase()
Expand All @@ -1489,7 +1465,7 @@ public function testAddColumnWithComment()
FROM information_schema.columns
WHERE TABLE_SCHEMA='%s' AND TABLE_NAME='table1'
ORDER BY ORDINAL_POSITION",
TESTS_PHINX_DB_ADAPTER_MYSQL_DATABASE
MYSQL_DB_CONFIG['name']
));
$columnWithComment = $rows[1];

Expand Down
Loading

0 comments on commit 51b2b8f

Please sign in to comment.