Skip to content

Commit

Permalink
improve cross-database testing. #94
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Aug 5, 2014
1 parent c9c7bd2 commit 5147ec3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/Database/AppContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class AppContext
{
protected static $app_key;

/**
* config
*
* @param mixed $name
*
* @return string
*/
public static function config($name) {
return Router::getInstance()->config($name);
}
Expand Down
21 changes: 19 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,27 @@
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../src/Hook.php';

// Force some application key for testing
$app = \Slim\Slim::getInstance();
Hook\Http\Router::setInstance($app);

//
// Ensure that tests will run against an valid fresh app
//
if (Hook\Model\AppKey::count() == 0) {
$app->environment->offsetSet('PATH_INFO', '/apps');
$app->environment->offsetSet('slim.request.form_hash', array(
'app' => array(
'name' => 'testing'
)
));
$apps_controller = new Hook\Controllers\AppsController();
$apps_controller->create();
}

// Force application key for testing
\DLModel::getConnectionResolver()->connection()->setTablePrefix('');
Hook\Database\AppContext::setKey(Hook\Model\AppKey::with('app')->first());

$app = \Slim\Slim::getInstance();
$app->log->setWriter(new Hook\Logger\LogWriter(storage_dir() . '/logs.txt'));

class TestCase extends PHPUnit_Framework_TestCase
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/collection/CollectionRelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ public function testBooksAndAuthors()
$this->assertTrue($books_author_contacts[0]['name'] == "Programming PHP");
$this->assertTrue($books_author_contacts[0]['author']['name'] == "Rasmus Lerdorf");
$this->assertTrue(count($books_author_contacts[0]['author']['contacts']) == 2);
$this->assertTrue($books_author_contacts[0]['author']['contacts'][0]['name'] == "Kevin Tatroe");
$this->assertTrue($books_author_contacts[0]['author']['contacts'][1]['name'] == "Peter MacIntyre");
$this->assertTrue(gettype($books_author_contacts[0]['author']['contacts'][0]['name']) == 'string');
$this->assertTrue(gettype($books_author_contacts[0]['author']['contacts'][1]['name']) == 'string');

$authors_books_contacts = App::collection('author')->with('books', 'contacts')->toArray();
$this->assertTrue(count($authors_books_contacts) == 1);
$this->assertTrue($authors_books_contacts[0]['name'] == "Rasmus Lerdorf");
$this->assertTrue(count($authors_books_contacts[0]['books']) == 1);
$this->assertTrue($authors_books_contacts[0]['books'][0]['name'] == "Programming PHP");
$this->assertTrue(count($authors_books_contacts[0]['contacts']) == 2);
$this->assertTrue($authors_books_contacts[0]['contacts'][0]['name'] == "Kevin Tatroe");
$this->assertTrue($authors_books_contacts[0]['contacts'][1]['name'] == "Peter MacIntyre");
$this->assertTrue(gettype($authors_books_contacts[0]['contacts'][0]['name']) == 'string');
$this->assertTrue(gettype($authors_books_contacts[0]['contacts'][1]['name']) == 'string');
}

public function testTeamAndMatches()
Expand Down

0 comments on commit 5147ec3

Please sign in to comment.