From 418d40a4eca04d28e9f079bd0942c0c2ec02e9c4 Mon Sep 17 00:00:00 2001 From: Davey Shafik Date: Sun, 6 Dec 2015 01:56:46 -0500 Subject: Add travis integration --- .travis.yml | 16 ++++++ composer.json | 3 -- composer.lock | 16 +++--- tests/MySqlShimTest.php | 129 ++++++++++++++++++++++++++---------------------- 4 files changed, 94 insertions(+), 70 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3112539 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: php +services: + - mysql +php: + - 5.6 + - 7.0 + - hhvm +matrix: + allow_failures: + - php: hhvm +sudo: false +before_install: + - composer self-update +install: travis_retry composer install --no-interaction --prefer-source +script: phpunit +after_script: wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/coverage/coverage.clover diff --git a/composer.json b/composer.json index 4330c57..329eef4 100644 --- a/composer.json +++ b/composer.json @@ -9,9 +9,6 @@ "homepage": "https://daveyshafik.com" } ], - "require": { - "php": ">= 7.0" - }, "require-dev": { "phpunit/phpunit": "~5.1" }, diff --git a/composer.lock b/composer.lock index 83d5a1e..4ca167d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "d013d162a236a506068e204c5cb14353", + "hash": "a879f677a37578594990cd73798b4f84", "packages": [], "packages-dev": [ { @@ -867,16 +867,16 @@ }, { "name": "sebastian/recursion-context", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "994d4a811bafe801fb06dccbee797863ba2792ba" + "reference": "913401df809e99e4f47b27cdd781f4a258d58791" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba", - "reference": "994d4a811bafe801fb06dccbee797863ba2792ba", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791", + "reference": "913401df809e99e4f47b27cdd781f4a258d58791", "shasum": "" }, "require": { @@ -916,7 +916,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-06-21 08:04:50" + "time": "2015-11-11 19:50:13" }, { "name": "sebastian/resource-operations", @@ -1050,8 +1050,6 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": { - "php": "~5.6" - }, + "platform": [], "platform-dev": [] } diff --git a/tests/MySqlShimTest.php b/tests/MySqlShimTest.php index 928edb4..24abe5a 100644 --- a/tests/MySqlShimTest.php +++ b/tests/MySqlShimTest.php @@ -25,11 +25,11 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase /** * @expectedException \PHPUnit_Framework_Error_Warning - * @expectedExceptionMessageRegExp /^mysql(i?)_connect\(\): (\(HY000\/1045\): )?Access denied for user ''@'(.*?)' \(using password: NO\)$/ + * @expectedExceptionMessageRegExp /^mysql(i?)_connect\(\): (\(HY000\/1045\): )?Access denied for user 'baduser'@'(.*?)' \(using password: YES\)$/ */ public function test_mysql_connect_fail() { - $mysql = \mysql_connect(static::$host); + $mysql = \mysql_connect(static::$host, "baduser", "badpass"); } /** @@ -50,11 +50,11 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase /** * @expectedException \PHPUnit_Framework_Error_Warning - * @expectedExceptionMessageRegExp /^mysql((i_real)?)_connect\(\): (\(HY000\/1045\): )?Access denied for user ''@'(.*?)' \(using password: NO\)$/ + * @expectedExceptionMessageRegExp /^mysql((i_real)?)_connect\(\): (\(HY000\/1045\): )?Access denied for user 'baduser'@'(.*?)' \(using password: YES\)$/ */ public function test_mysql_connect_options_fail() { - \mysql_connect(static::$host, null, null, false, MYSQL_CLIENT_COMPRESS); + \mysql_connect(static::$host, "baduser", "badpass", false, MYSQL_CLIENT_COMPRESS); } public function test_mysql_connect_multi() @@ -87,7 +87,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase public function test_mysql_query_ddl() { $conn = \mysql_connect(static::$host, 'root'); - $result = \mysql_query("CREATE DATABASE shim_test;"); + $result = \mysql_query("CREATE DATABASE shim_test CHARACTER SET latin1;"); $this->assertTrue($result); $result = \mysql_select_db('shim_test'); $this->assertTrue($result); @@ -112,7 +112,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase INDEX seven_eight_idx (seven, eight), UNIQUE INDEX seven_eight_unq (seven, eight), PRIMARY KEY (id) - );" + ) CHARACTER SET latin1;" ); $this->assertTrue($result, \mysql_error()); } @@ -438,77 +438,88 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase public static function setUpBeforeClass() { - fwrite(STDERR, "=> Finding binaries\n"); - static::$bin['dm'] = $dm = exec('/usr/bin/env which docker-machine'); - static::$bin['docker'] = $docker = exec('/usr/bin/env which docker'); - if (empty($dm) && empty($docker)) { - static::markTestSkipped('Docker is required to run these tests'); - } - - if (!empty($dm)) { - fwrite(STDERR, "=> Starting Docker Machine\n"); - exec($dm . ' create -d virtualbox mysql-shim'); - exec($dm . ' start mysql-shim'); + error_reporting(E_ALL & ~E_DEPRECATED); + if (getenv('TRAVIS') === false) { + fwrite(STDERR, "=> Finding binaries\n"); + static::$bin['dm'] = $dm = exec('/usr/bin/env which docker-machine'); + static::$bin['docker'] = $docker = exec('/usr/bin/env which docker'); + if (empty($dm) && empty($docker)) { + static::markTestSkipped('Docker is required to run these tests'); + } - $env = ''; - exec($dm . ' env mysql-shim', $env); - foreach ($env as $line) { - if ($line{0} !== '#') { - putenv(str_replace(["export ", '"'], "", $line)); + if (!empty($dm)) { + fwrite(STDERR, "=> Starting Docker Machine\n"); + exec($dm . ' create -d virtualbox mysql-shim'); + exec($dm . ' start mysql-shim'); + + $env = ''; + exec($dm . ' env mysql-shim', $env); + foreach ($env as $line) { + if ($line{0} !== '#') { + putenv(str_replace(["export ", '"'], "", $line)); + } } } - } - - fwrite(STDERR, "=> Running Docker Container: "); - static::$container = exec($docker . ' run -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -P -d mysql/mysql-server:5.7'); - if (empty(static::$container)) { - static::markTestSkipped("Unable to start docker container"); - } + fwrite(STDERR, "=> Running Docker Container: "); + static::$container = exec($docker . ' run -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -P -d mysql/mysql-server:5.7'); - fwrite(STDERR, static::$container . "\n"); + if (empty(static::$container)) { + static::markTestSkipped("Unable to start docker container"); + } - fwrite(STDERR, "=> Finding MySQL Host: "); - static::$host = exec($docker . ' port ' . self::$container . ' 3306'); - fwrite(STDERR, static::$host . "\n"); + fwrite(STDERR, static::$container . "\n"); - if (!empty($dm)) { - fwrite(STDERR, "=> Using Docker Machine IP: "); - $info = explode(':', static::$host); - $port = array_pop($info); - static::$host = exec($dm . ' ip mysql-shim') . ':' . $port; + fwrite(STDERR, "=> Finding MySQL Host: "); + static::$host = exec($docker . ' port ' . self::$container . ' 3306'); fwrite(STDERR, static::$host . "\n"); - } - fwrite(STDERR, "=> Waiting on mysqld to start:"); - $out = ''; - while (trim($out) != 'mysqld') { - $out = exec(static::$bin['docker'] . ' exec ' . static::$container . ' ps ax | awk \'/mysqld/ {print $NF}\''); - } - fwrite(STDERR, " started\n"); + if (!empty($dm)) { + fwrite(STDERR, "=> Using Docker Machine IP: "); + $info = explode(':', static::$host); + $port = array_pop($info); + static::$host = exec($dm . ' ip mysql-shim') . ':' . $port; + fwrite(STDERR, static::$host . "\n"); + } - fwrite(STDERR, "=> Docker Container Running\n\n"); + fwrite(STDERR, "=> Waiting on mysqld to start:"); + $out = ''; + while (trim($out) != 'mysqld') { + $out = exec(static::$bin['docker'] . ' exec ' . static::$container . ' ps ax | awk \'/mysqld/ {print $NF}\''); + } + fwrite(STDERR, " started\n"); + sleep(3); - error_reporting(E_ALL & ~E_DEPRECATED); + fwrite(STDERR, "=> Docker Container Running\n\n"); + + return; + } - sleep(3); + static::$host = 'localhost'; } public static function tearDownAfterClass() { - fwrite(STDERR, "\n\nStopping Docker Container: "); - $output = exec(static::$bin['docker'] . ' stop ' .static::$container); - if (trim($output) !== static::$container) { - fwrite(STDERR, " Failed to stop container!\n"); - return; - } + if (getenv('TRAVIS') === false) { + fwrite(STDERR, "\n\nStopping Docker Container: "); + $output = exec(static::$bin['docker'] . ' stop ' . static::$container); + if (trim($output) !== static::$container) { + fwrite(STDERR, " Failed to stop container!\n"); + return; + } + + $output = exec(static::$bin['docker'] . ' rm ' . static::$container); + if (trim($output) !== static::$container) { + fwrite(STDERR, " Failed to remove container!\n"); + return; + } + fwrite(STDERR, "Done\n"); - $output = exec(static::$bin['docker'] . ' rm ' .static::$container); - if (trim($output) !== static::$container) { - fwrite(STDERR, " Failed to remove container!\n"); return; } - fwrite(STDERR, "Done\n"); + + \mysql_connect(static::$host, "root"); + \mysql_query("DROP DATABASE shim_test"); } public function mysql_fetch_DataProvider() @@ -578,6 +589,8 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $mysql = \mysql_connect(static::$host, 'root'); $this->assertConnection($mysql); + \mysql_query("SET NAMES latin1"); + if ($db !== null) { $this->assertTrue(\mysql_select_db($db)); } -- cgit v1.1