summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavey Shafik <me@daveyshafik.com>2020-08-11 06:29:00 +0000
committerDavey Shafik <me@daveyshafik.com>2020-08-11 06:29:00 +0000
commit50fbf688b444818334d40dc32c0302e3001d7442 (patch)
tree3901ae07af2f91089364187b5593b3d5b703f559 /tests
parent4b796ffef0834a7b167f9e8536f6d164933ff6ae (diff)
downloadphp7-mysql-shim-50fbf688b444818334d40dc32c0302e3001d7442.zip
php7-mysql-shim-50fbf688b444818334d40dc32c0302e3001d7442.tar.gz
php7-mysql-shim-50fbf688b444818334d40dc32c0302e3001d7442.tar.bz2
Try to fix tests
Diffstat (limited to 'tests')
-rw-r--r--tests/MySqlShimTest.php85
-rw-r--r--tests/bootstrap.php14
2 files changed, 16 insertions, 83 deletions
diff --git a/tests/MySqlShimTest.php b/tests/MySqlShimTest.php
index a7264be..eec82e6 100644
--- a/tests/MySqlShimTest.php
+++ b/tests/MySqlShimTest.php
@@ -9,7 +9,7 @@
*/
namespace Dshafik\MySQL\Tests;
-class MySqlShimTest extends \PHPUnit_Framework_TestCase
+class MySqlShimTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string MySQL Host
@@ -19,11 +19,6 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase
public static $password = null;
/**
- * @var string Docker container
- */
- protected static $container;
-
- /**
* @var array Location of binaries
*/
protected static $bin = array();
@@ -40,6 +35,18 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase
public function __construct($name = null, array $data = array(), $dataName = '')
{
+ if (getenv('MYSQL_HOST') !== '') {
+ static::$host = getenv('MYSQL_HOST');
+ }
+
+ if (getenv('MYSQL_USERNAME') !== '') {
+ static::$username = getenv('MYSQL_USERNAME');
+ }
+
+ if (getenv('MYSQL_PASSWORD') !== '') {
+ static::$password = getenv('MYSQL_PASSWORD');
+ }
+
parent::__construct($name, $data, $dataName);
$this->runtime = new \SebastianBergmann\Environment\Runtime();
}
@@ -950,75 +957,13 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('information_schema', mysql_db_name($dbs, 0));
}
- public function tearDown()
+ public function tearDown(): void
{
@mysql_close();
}
- public static function setUpBeforeClass()
- {
- error_reporting(E_ALL & ~E_DEPRECATED);
- if (getenv('TRAVIS') === false && getenv('APPVEYOR') === false) {
- fwrite(STDERR, "=> Finding binaries\n");
- static::$bin['docker'] = $docker = exec('/usr/bin/env which docker');
- if (empty($docker)) {
- static::markTestSkipped('Docker is required to run these tests');
- }
-
- 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, static::$container . "\n");
-
- 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");
- sleep(3);
-
- fwrite(STDERR, "=> Docker Container Running\n\n");
-
- return;
- }
-
-
- static::$host = '0.0.0.0';
- if (getenv('APPVEYOR') !== false) {
- static::$host = static::$hostname;
- static::$password = 'Password12!';
- }
- }
-
- public static function tearDownAfterClass()
+ public static function tearDownAfterClass(): void
{
- if (getenv('TRAVIS') === false && getenv('APPVEYOR') === 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");
-
- return;
- }
-
mysql_connect(static::$host, static::$username, static::$password);
foreach (self::$dbs as $db) {
mysql_query("DROP DATABASE IF EXISTS `$db`");
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index f8d1391..d5e8404 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -8,16 +8,4 @@
* @link https://github.com/dshafik/php7-mysql-shim
*/
-require_once __DIR__ . '/../vendor/autoload.php';
-
-if (getenv('MYSQL_HOST') !== '') {
- Dshafik\MySQL\Tests\MySqlShimTest::$host = getenv('MYSQL_HOST');
-}
-
-if (getenv('MYSQL_USERNAME') !== '') {
- Dshafik\MySQL\Tests\MySqlShimTest::$username = getenv('MYSQL_USERNAME');
-}
-
-if (getenv('MYSQL_PASSWORD') !== '') {
- Dshafik\MySQL\Tests\MySqlShimTest::$password = getenv('MYSQL_PASSWORD');
-} \ No newline at end of file
+require_once __DIR__ . '/../vendor/autoload.php'; \ No newline at end of file