From 668070ed0d52b3b4a43937251529cafdb5473d53 Mon Sep 17 00:00:00 2001 From: wriver4 Date: Thu, 9 Jun 2016 00:44:12 -0400 Subject: [PATCH] adjustments --- Activerecord/Config.php | 45 ++++++++++++++++++--------------- Test/Adapters/SqliteTest.php | 1 + Test/Helpers/DatabaseLoader.php | 5 ++-- Test/Helpers/DatabaseTest.php | 6 ++--- Test/Unit/CacheTest.php | 33 +++++------------------- Test/bootstrap.php | 2 +- 6 files changed, 38 insertions(+), 54 deletions(-) diff --git a/Activerecord/Config.php b/Activerecord/Config.php index db93701..9133a44 100644 --- a/Activerecord/Config.php +++ b/Activerecord/Config.php @@ -6,10 +6,10 @@ namespace Activerecord; use Activerecord\Cache; -use Activerecord\Exceptions\ExceptionConfig; +use Activerecord\Singleton; use Activerecord\Reflections; use Activerecord\Serializers\AbstractSerialize; -use Activerecord\Singleton; +use Activerecord\Exceptions\ExceptionConfig; /** * Manages configuration options for Activerecord. @@ -210,31 +210,34 @@ public function setDefaultConnection($name) * @param string $dir Directory path containing your models * @return void */ - public function setModelDirectory($dir) - { - $this->model_directory = $dir; - } - + /* + public function setModelDirectory($dir) + { + $this->model_directory = $dir; + } + */ /** * Returns the model directory. * * @return string * @throws Config if specified directory was not found */ - public function getModelDirectory() - { - - foreach (\glob("$this->model_directory/*.php") as $filename) - { - require_once $filename; - } - if ($this->model_directory && !\file_exists($this->model_directory)) - { - throw new ExceptionConfig('Invalid or non-existent directory: '.$this->model_directory); - } - - return $this->model_directory; - } + /* + public function getModelDirectory() + { + + foreach (\glob("$this->model_directory/*.php") as $filename) + { + require_once $filename; + } + if ($this->model_directory && !\file_exists($this->model_directory)) + { + throw new ExceptionConfig('Invalid or non-existent directory: '.$this->model_directory); + } + + return $this->model_directory; + } + */ /** * Turn on/off logging diff --git a/Test/Adapters/SqliteTest.php b/Test/Adapters/SqliteTest.php index 03d337c..010d593 100644 --- a/Test/Adapters/SqliteTest.php +++ b/Test/Adapters/SqliteTest.php @@ -2,6 +2,7 @@ namespace Test\Adapters; +use Activerecord\Adapters\Sqlite; use Activerecord\Connection; use Activerecord\Exceptions\ExceptionDatabase; use Test\Helpers\DatabaseTest; diff --git a/Test/Helpers/DatabaseLoader.php b/Test/Helpers/DatabaseLoader.php index 096882a..279c5a1 100644 --- a/Test/Helpers/DatabaseLoader.php +++ b/Test/Helpers/DatabaseLoader.php @@ -3,6 +3,7 @@ namespace Test\Helpers; class DatabaseLoader +// extends \PHPUnit_Framework_TestCase { private $db; @@ -84,7 +85,7 @@ public function dropTables() } } - public function execSqlScript($file) + public function testExecSqlScript($file) { foreach (\explode(';', $this->getSql($file)) as $sql) { @@ -108,7 +109,7 @@ public function getFixtureTables() return $tables; } - public function getSql($file) + public function testGetSql($file) { $file = __DIR__."/../sql/$file.sql"; diff --git a/Test/Helpers/DatabaseTest.php b/Test/Helpers/DatabaseTest.php index 707aad5..90cf74a 100644 --- a/Test/Helpers/DatabaseTest.php +++ b/Test/Helpers/DatabaseTest.php @@ -69,7 +69,7 @@ public function tearDown() } } - public function assertExceptionMessageContains($contains, $closure) + public function testAssertExceptionMessageContains($contains, $closure) { $message = ""; @@ -91,7 +91,7 @@ public function assertExceptionMessageContains($contains, $closure) * Takes database specific quotes into account by removing them. So, this won't * work if you have actual quotes in your strings. */ - public function assertSqlHas($needle, $haystack) + public function testAssertSqlHas($needle, $haystack) { $needle = \str_replace([ '"', @@ -102,7 +102,7 @@ public function assertSqlHas($needle, $haystack) return $this->assertContains($needle, $haystack); } - public function assertSqlDoesNotContain($needle, $haystack) + public function testAssertSqlDoesNotContain($needle, $haystack) { $needle = \str_replace([ '"', diff --git a/Test/Unit/CacheTest.php b/Test/Unit/CacheTest.php index dea0995..7e36d0f 100644 --- a/Test/Unit/CacheTest.php +++ b/Test/Unit/CacheTest.php @@ -4,7 +4,6 @@ use Activerecord\Cache; use Activerecord\Config; -use Activerecord\Test\Models\Author; class CacheTest extends \PHPUnit_Framework_TestCase @@ -22,6 +21,7 @@ public function setUp() // Cache::initialize('memcache://localhost'); Config::instance()->setCache('memcache://127.0.0.1'); Cache::initialize('memcache://127.0.0.1'); + Cache::set("1337", "abcd"); } public function tearDown() @@ -82,23 +82,6 @@ public function testGetWorksWithoutCachingEnabled() $this->assertEquals("abcd", $this->cacheGet()); } - public function testCacheExpire() - { - Cache::$options['expire'] = 1; - $this->cacheGet(); - sleep(2); - - $this->assertSame(false, Cache::$adapter->read("1337")); - } - - public function testExplicitDefaultExpire() - { - Config::instance()->setCache('memcache://localhost', - array( - 'expire' => 1)); - $this->assertEquals(1, Cache::$options['expire']); - } - public function testNamespaceIsSetProperly() { Cache::$options['namespace'] = 'myapp'; @@ -111,14 +94,10 @@ public function testDefaultExpire() $this->assertEquals(30, Cache::$options['expire']); } - /* - public function testCachesColumnMetaData() - { - Author::first(); + public function testSetCachetExpire() + { + Config::instance()->setCache('memcache://localhost', ['expire' => 1]); + $this->assertEquals(1, Cache::$options['expire']); + } - $table_name = Author::table()->getFullyQualifiedTableName(!($this->conn instanceof Pgsql)); - $value = Cache::$adapter->read("get_meta_data-$table_name"); - $this->assertTrue(\is_array($value)); - } - */ } \ No newline at end of file diff --git a/Test/bootstrap.php b/Test/bootstrap.php index 734f489..a50903f 100644 --- a/Test/bootstrap.php +++ b/Test/bootstrap.php @@ -13,7 +13,7 @@ Activerecord\Config::initialize(function($cfg) { - $cfg->setModelDirectory(\realpath('Models')); + //$cfg->setModelDirectory(\realpath('Models')); $cfg->setConnections(array( 'mysql' => \getenv('PHPAR_MYSQL') ? : 'mysql://root:root@127.0.0.1/Activerecord_Test', 'pgsql' => \getenv('PHPAR_PGSQL') ? : 'pgsql://test:test@127.0.0.1/test',