Skip to content

Commit

Permalink
adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
wriver4 committed Jun 9, 2016
1 parent fcad30a commit 668070e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 54 deletions.
45 changes: 24 additions & 21 deletions Activerecord/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Test/Adapters/SqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Test\Adapters;

use Activerecord\Adapters\Sqlite;
use Activerecord\Connection;
use Activerecord\Exceptions\ExceptionDatabase;
use Test\Helpers\DatabaseTest;
Expand Down
5 changes: 3 additions & 2 deletions Test/Helpers/DatabaseLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Test\Helpers;

class DatabaseLoader
// extends \PHPUnit_Framework_TestCase
{

private $db;
Expand Down Expand Up @@ -84,7 +85,7 @@ public function dropTables()
}
}

public function execSqlScript($file)
public function testExecSqlScript($file)
{
foreach (\explode(';', $this->getSql($file)) as $sql)
{
Expand All @@ -108,7 +109,7 @@ public function getFixtureTables()
return $tables;
}

public function getSql($file)
public function testGetSql($file)
{
$file = __DIR__."/../sql/$file.sql";

Expand Down
6 changes: 3 additions & 3 deletions Test/Helpers/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function tearDown()
}
}

public function assertExceptionMessageContains($contains, $closure)
public function testAssertExceptionMessageContains($contains, $closure)
{
$message = "";

Expand All @@ -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([
'"',
Expand All @@ -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([
'"',
Expand Down
33 changes: 6 additions & 27 deletions Test/Unit/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Activerecord\Cache;
use Activerecord\Config;
use Activerecord\Test\Models\Author;

class CacheTest
extends \PHPUnit_Framework_TestCase
Expand All @@ -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()
Expand Down Expand Up @@ -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';
Expand All @@ -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));
}
*/
}
2 changes: 1 addition & 1 deletion Test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]/Activerecord_Test',
'pgsql' => \getenv('PHPAR_PGSQL') ? : 'pgsql://test:[email protected]/test',
Expand Down

0 comments on commit 668070e

Please sign in to comment.