Skip to content

Commit

Permalink
Update test layout to better match source layout
Browse files Browse the repository at this point in the history
  • Loading branch information
timw4mail committed Jan 19, 2018
1 parent 369ca6e commit 4df07b6
Show file tree
Hide file tree
Showing 20 changed files with 346 additions and 295 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"phploc/phploc": "^4.0",
"phpmd/phpmd": "^2.4",
"phpstan/phpstan": "^0.9.1",
"phpunit/phpunit": "^5.5",
"phpunit/phpunit": "^6.5",
"sebastian/phpcpd": "^2.0",
"simpletest/simpletest": "^1.1",
"squizlabs/php_codesniffer": "^3.0.0"
Expand All @@ -50,7 +50,7 @@
"scripts": {
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
"phpstan": "phpstan analyse -l 3 -c phpstan.neon src tests",
"test": "phpunit -c build"
"test": "phpunit -c build --no-coverage"
},
"scripts-descriptions": {
"coverage": "Generate test coverage report",
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
parameters:
autoload_files:
- %rootDir%/../../../tests/bootstrap.php
- %rootDir%/../../../tests/databases/mysql/MySQLTest.php
- %rootDir%/../../../tests/databases/mysql/MySQLQBTest.php
- %rootDir%/../../../tests/databases/pgsql/PgSQLTest.php
- %rootDir%/../../../tests/databases/pgsql/PgSQLQBTest.php
- %rootDir%/../../../tests/databases/sqlite/SQLiteTest.php
- %rootDir%/../../../tests/databases/sqlite/SQLiteQBTest.php
ignoreErrors:
- '#Access to an undefined property Aviat\\\Ion\\\Friend::\$[a-zA-Z0-9_]+#'
- '#Call to an undefined method Aviat\\\Ion\\\Friend::[a-zA-Z0-9_]+\(\)#'
6 changes: 3 additions & 3 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function __call(string $name, array $params)
{
if (method_exists($object, $methodName))
{
return call_user_func_array([$object, $methodName], $params);
return \call_user_func_array([$object, $methodName], $params);
}
}

Expand Down Expand Up @@ -645,12 +645,12 @@ public function get($table='', $limit=FALSE, $offset=FALSE): PDOStatement
}

// Set the limit, if it exists
if (is_int($limit))
if (\is_int($limit))
{
$this->limit($limit, $offset);
}

return $this->_run("get", $table);
return $this->_run('get', $table);
}

/**
Expand Down
31 changes: 18 additions & 13 deletions src/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
*/


use Query\ConnectionManager;
use Query\{
ConnectionManager,
QueryBuilderInterface
};

require __DIR__ . '/../vendor/autoload.php';

Expand All @@ -34,7 +37,7 @@
*/
function mb_trim(string $string): string
{
return preg_replace("/(^\s+)|(\s+$)/us", "", $string);
return preg_replace('/(^\s+)|(\s+$)/u', '', $string);
}
}

Expand Down Expand Up @@ -73,9 +76,10 @@ function db_filter(array $array, $index): array
function to_camel_case(string $snakeCase): string
{
$pieces = explode('_', $snakeCase);
$numPieces = count($pieces);

$pieces[0] = mb_strtolower($pieces[0]);
for($i = 1; $i < count($pieces); $i++)
for($i = 1; $i < $numPieces; $i++)
{
$pieces[$i] = ucfirst(mb_strtolower($pieces[$i]));
}
Expand Down Expand Up @@ -161,26 +165,27 @@ function regex_in_array(array $array, string $pattern): bool
* connection created.
*
* @param string|object|array $params
* @return Query\QueryBuilder|null
* @return QueryBuilderInterface|null
*/
function Query($params = '')
function Query($params = ''): ?QueryBuilderInterface
{
$manager = ConnectionManager::getInstance();

if ($params === NULL)
{
return NULL;
}

// If you are getting a previously created connection
if (is_scalar($params))
{
return $manager->getConnection($params);
}
elseif ( ! is_scalar($params) && ! is_null($params))
{
$paramsObject = (object) $params;

// Otherwise, return a new connection
return $manager->connect($paramsObject);
}
$paramsObject = (object) $params;

return NULL;
// Otherwise, return a new connection
return $manager->connect($paramsObject);
}
}
// End of common.php
// End of common.php
8 changes: 6 additions & 2 deletions tests/core/base_db_test.php → tests/BaseDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
* @link https://git.timshomepage.net/aviat4ion/Query
*/

namespace Query\Tests;

// --------------------------------------------------------------------------

/**
* Parent Database Test Class
*/
abstract class DBTest extends Query_TestCase {
abstract class BaseDriverTest extends TestCase {

protected static $db = NULL;
/**
* @var \Query\QueryBuilder
*/
protected static $db;

abstract public function testConnection();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
* @link https://git.timshomepage.net/aviat4ion/Query
*/

namespace Query\Tests;

use PDO;

/**
* Query builder parent test class
*/
abstract class QBTest extends Query_TestCase {
abstract class BaseQueryBuilderTest extends TestCase {

protected static $db;

Expand All @@ -41,7 +45,7 @@ public function testInvalidConnectionName()
{
$this->expectException('InvalidArgumentException');

$db = Query('foo');
Query('foo');
}

public function testFunctionGet()
Expand Down Expand Up @@ -506,7 +510,7 @@ public function testJoinWithMultipleWhereValues()

$this->assertIsA($query, 'PDOStatement');
}

// ! DB update tests
public function testInsert()
{
Expand All @@ -521,10 +525,10 @@ public function testInsert()
public function testInsertArray()
{
$query = self::$db->insert('test', array(
'id' => 587,
'key' => 1,
'val' => 2,
));
'id' => 587,
'key' => 1,
'val' => 2,
));

$this->assertIsA($query, 'PDOStatement');
}
Expand Down Expand Up @@ -662,7 +666,7 @@ public function testGetCompiledUpdate()
'val' => 'baz'
))->getCompiledUpdate('test');

$this->assertTrue(is_string($sql));
$this->assertTrue(\is_string($sql));
}

public function testGetCompiledInsert()
Expand All @@ -673,15 +677,15 @@ public function testGetCompiledInsert()
'val' => 'baz'
))->getCompiledInsert('test');

$this->assertTrue(is_string($sql));
$this->assertTrue(\is_string($sql));
}

public function testGetCompiledDelete()
{
$sql = self::$db->where('id', 4)
->getCompiledDelete('test');

$this->assertTrue(is_string($sql));
$this->assertTrue(\is_string($sql));
}
// ! Error tests
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
*
* PHP version 7
*
* @package Query
* @author Timothy J. Warren <tim@timshomepage.net>
* @package Query
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2012 - 2016 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://git.timshomepage.net/aviat4ion/Query
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://git.timshomepage.net/aviat4ion/Query
*/

namespace Query\Tests;

class Connection_Manager_Test extends Query_TestCase {
use DomainException;
use Query\{ConnectionManager, QueryBuilderInterface};

protected static $instance = NULL;
class ConnectionManagerTest extends TestCase {

protected static $instance;

public static function setUpBeforeClass()
{
self::$instance = Query\ConnectionManager::getInstance();
self::$instance = ConnectionManager::getInstance();
}

// --------------------------------------------------------------------------
Expand All @@ -30,25 +34,29 @@ public function testNoClone()
$this->expectException('DomainException');
$this->expectExceptionMessage("Can't clone singleton");
$clone = clone self::$instance;
$this->assertNull($clone);
}

// --------------------------------------------------------------------------

public function testNoSerialize()
{
$this->setExpectedException('DomainException', "No serializing of singleton");
$string = serialize(self::$instance);
$this->expectException(DomainException::class);
$this->expectExceptionMessage('No serializing of singleton');
serialize(self::$instance);

$this->setExpectedException('DomainException', "No serializing of singleton");
$string = self::$instance->__sleep();
$this->expectException(DomainException::class);
$this->expectExceptionMessage('No serializing of singleton');
self::$instance->__sleep();
}

// --------------------------------------------------------------------------

public function testNoUnserialize()
{
$this->setExpectedException('DomainException', "Can't unserialize singleton");
$obj = self::$instance->__wakeup();
$this->expectException(DomainException::class);
$this->expectExceptionMessage("Can't unserialize singleton");
self::$instance->__wakeup();
}

// --------------------------------------------------------------------------
Expand Down Expand Up @@ -87,7 +95,7 @@ public function testConnect()
);

$conn = self::$instance->connect($params);
$this->assertInstanceOf('Query\\QueryBuilder', $conn);
$this->assertInstanceOf(QueryBuilderInterface::class, $conn);


// Check that the connection just made is returned from the get_connection method
Expand All @@ -109,9 +117,9 @@ public function testGetConnection()
);

$conn = self::$instance->connect($params);
$this->assertInstanceOf('Query\\QueryBuilder', $conn);
$this->assertInstanceOf(QueryBuilderInterface::class, $conn);

$this->assertEqual($conn, self::$instance->getConnection('conn_manager'));
}
}
// End of connection_manager_test.php
// End of connection_manager_test.php
13 changes: 8 additions & 5 deletions tests/core/core_test.php → tests/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* @link https://git.timshomepage.net/aviat4ion/Query
*/

namespace Query\Tests;


// --------------------------------------------------------------------------

Expand All @@ -21,7 +23,7 @@
*
* @extends UnitTestCase
*/
class CoreTest extends Query_TestCase {
class CoreTest extends TestCase {

/**
* TestPHPVersion function.
Expand All @@ -31,7 +33,8 @@ class CoreTest extends Query_TestCase {
*/
public function testPHPVersion()
{
$this->assertTrue(version_compare(PHP_VERSION, "5.3", "ge"));
//$this->assertTrue(version_compare(PHP_VERSION, '7.1', 'ge'));
$this->assertTrue(PHP_VERSION_ID >= 70000);
}

// --------------------------------------------------------------------------
Expand All @@ -49,15 +52,15 @@ public function testHasPDO()


// Make sure at least one of the supported drivers is enabled
$supported = array(
$supported = [
'firebird',
'mysql',
'pgsql',
'odbc',
'sqlite',
);
];

$drivers = PDO::getAvailableDrivers();
$drivers = \PDO::getAvailableDrivers();

$numSupported = count(array_intersect($drivers, $supported));

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 4df07b6

Please sign in to comment.