Skip to content

Commit

Permalink
added some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedevin committed Oct 30, 2015
1 parent 9f8281c commit 75aaba9
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/Tipsy/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Request {
private $_properties;
private $_rawRequest;
private $_content;
private $_headers = [];

public function __construct($args = []) {
$this->_properties = [];
Expand Down Expand Up @@ -158,4 +159,4 @@ public function headers() {
}
return $this->_headers;
}
}
}
55 changes: 55 additions & 0 deletions tests/DependencyInjectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

class DependencyInjectorTest extends Tipsy_Test {

public function setUp() {
$this->tip = new Tipsy\Tipsy;
$this->useOb = true; // for debug use

$this->tip->config('tests/config.ini');

$env = getenv('TRAVIS') ? 'travis' : 'local';

$this->tip->config('tests/config.db.'.$env.'.ini');
}

public function testBaseInjectors() {
$_REQUEST['__url'] = 'router/basic';
$this->ob();

$this->tip->router()
->when('router/basic', function($Db, $Route, $Headers, $Params, $Tipsy, $View, $Scope, $Request, $RootScope) {
foreach (func_get_args() as $k => $arg) {
if ((!$arg && $k != 2) || ($k == 2 && !is_array($arg))) {
$fail = true;
echo 'no argument #'.$k."\n";
}
}
if (!$fail) {
echo 'YAY';
}
});
$this->tip->start();

$check = $this->ob(false);
$this->assertEquals('YAY', $check);
}

public function testEmptyInjector() {
$_REQUEST['__url'] = 'router/basic';
$this->ob();

$this->tip->router()
->when('router/basic', function($Empty) {
if ($Empty) {
echo 'FAIL';
} else {
echo 'YAY';
}
});
$this->tip->start();

$check = $this->ob(false);
$this->assertEquals('YAY', $check);
}
}
45 changes: 37 additions & 8 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ protected function test() {
}
}

class TestModelStaticFail extends Tipsy\Model {

}



class ModelTest extends Tipsy_Test {

public function setUp() {
$this->tip = new Tipsy\Tipsy;
$this->useOb = true; // for debug use

$this->tip->config('tests/config.ini');
}

public function testModelBasic() {

$this->tip->service('TestModel', [
Expand Down Expand Up @@ -59,7 +64,7 @@ public function testModelCustomExtend() {
];
return $model;
});

$model = $this->tip->service('TestModel');
$this->assertEquals('TWO', $model->test());
}
Expand All @@ -75,7 +80,7 @@ public function testModelCustomExtendCall() {
$model = $this->tip->service('TestModel');
$this->assertEquals('ONE', $model->test());
}

public function testModelController() {
$this->tip->service('TestModel', function() {
$model = [
Expand All @@ -85,17 +90,41 @@ public function testModelController() {
];
return $model;
});

$this->ob();

$this->tip->router()
->otherwise(function($TestModel) {
echo $TestModel->test();
});
$this->tip->start();

$res = $this->ob(false);

$this->assertEquals('YESM', $res);
}

public function testIsset() {
$test = new Tipsy\Model;
$test->test = 'test';
$this->assertTrue(isset($test->test));
}

public function testExports() {
$test = new Tipsy\Model;
$test->test = 'test';
$test->tester = function(){};

$this->assertEquals($test->exports(), ['test' => 'test']);
}

public function testStaticFail() {
try {
TestModelStaticFail::test();
} catch (Exception $e) {
$catch = $e->getMessage();
}

$this->assertEquals('Could not call static test on TestModelStaticFail', $catch);
}
}
17 changes: 17 additions & 0 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,23 @@ public function testInvalidArrayRoute() {
$this->assertEquals('Invalid route specified.', $catch);
}

public function testInvalidControllerClass() {
$_REQUEST['__url'] = 'fail';

$this->tip->router()
->when('fail','ClassFail');

$this->ob();
try {
$this->tip->start();
} catch (Exception $e) {
echo $e->getMessage();
}
$check = $this->ob(false);

$this->assertEquals('No controller attached to route.', $check);
}


/*
public function testRouterViewController() {
Expand Down

0 comments on commit 75aaba9

Please sign in to comment.