Skip to content

Commit

Permalink
Cleaned code and moved testing configs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptorn committed Oct 16, 2017
1 parent e5cb071 commit ab98a0a
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 32 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -44,6 +44,14 @@ Now we need a table in the database to store the users. In `/config/sql/setup.sq
### Views
The last step is to copy the views from `/vendor/ptorn/user/bth-anax-user/view/user/` into `/view/`

### Autoload Namespace
Add this to your composer.json
`"autoload": {
"psr-4": {
"Peto16\\": "src/",
"testing\\": "test/src/"
}`

Usage
------------------
Once installation is done there will be some new routes available.
Expand Down
1 change: 0 additions & 1 deletion composer.json
Expand Up @@ -21,7 +21,6 @@
"Anax\\": "src/",
"Peto16\\": "src/",
"testing\\": "test/src/"

}
},
"require": {
Expand Down
File renamed without changes.
24 changes: 18 additions & 6 deletions config/testDi.php → test/config/testDi.php
Expand Up @@ -18,7 +18,7 @@
"response" => [
"shared" => true,
"callback" => function () {
$obj = new \testing\User\Helper();
$obj = new \testing\User\MockingClass();
return $obj;
}
],
Expand Down Expand Up @@ -49,7 +49,7 @@
"view" => [
"shared" => true,
"callback" => function () {
$view = new \testing\User\Helper();
$view = new \testing\User\MockingClass();
return $view;
}
],
Expand All @@ -66,7 +66,7 @@
"active" => true,
"callback" => function () {
$session = new \Anax\Session\SessionConfigurable();
$session->configure("testSession.php");
$session->configure(ANAX_APP_PATH . "/test/config/testSession.php");
$session->start();
return $session;
}
Expand Down Expand Up @@ -102,15 +102,27 @@
"pageRender" => [
"shared" => true,
"callback" => function () {
$obj = new \testing\User\Helper();
$obj = new \testing\User\MockingClass();
return $obj;
}
],
"db" => [
"shared" => true,
"callback" => function () {
$obj = new \Anax\Database\DatabaseQueryBuilder();
$obj->configure("testDatabase.php");
$obj->configure([
"dsn" => "sqlite::memory:",
"username" => null,
"password" => null,
"driver_options" => null,
"fetch_mode" => \PDO::FETCH_OBJ,
"table_prefix" => null,
"session_key" => "Anax\Database",
// True to be very verbose during development
"verbose" => true,
// True to be verbose on connection failed
"debug_connect" => true,
]);
$obj->connect();

$sql = '
Expand Down Expand Up @@ -139,7 +151,7 @@
"utils" => [
"shared" => true,
"callback" => function () {
$utils = new \testing\User\Helper();
$utils = new \testing\User\MockingClass();
return $utils;
}
],
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion test/src/User/HTMLForm/CreateUserFormTest.php
Expand Up @@ -19,7 +19,8 @@ class CreateUserFormTest extends TestCase
*/
public static function setUpBeforeClass()
{
self::$di = new \Anax\DI\DIFactoryConfig("testDi.php");
self::$di = new \Anax\DI\DIFactoryConfig();
self::$di->configure(ANAX_APP_PATH . "/test/config/testDi.php");
}


Expand Down
3 changes: 2 additions & 1 deletion test/src/User/HTMLForm/DeleteUserFormTest.php
Expand Up @@ -19,7 +19,8 @@ class DeleteUserFormTest extends TestCase
*/
public static function setUpBeforeClass()
{
self::$di = new \Anax\DI\DIFactoryConfig("testDi.php");
self::$di = new \Anax\DI\DIFactoryConfig();
self::$di->configure(ANAX_APP_PATH . "/test/config/testDi.php");
self::$session = self::$di->get("session");
$user = new \Peto16\User\User();
$user->username = "admin";
Expand Down
3 changes: 2 additions & 1 deletion test/src/User/HTMLForm/UpdateUserFormTest.php
Expand Up @@ -20,7 +20,8 @@ class UpdateUserFormTest extends TestCase
*/
public static function setUpBeforeClass()
{
self::$di = new \Anax\DI\DIFactoryConfig("testDi.php");
self::$di = new \Anax\DI\DIFactoryConfig();
self::$di->configure(ANAX_APP_PATH . "/test/config/testDi.php");
self::$session = self::$di->get("session");
$user = new \Peto16\User\User();
$user->username = "admin";
Expand Down
3 changes: 2 additions & 1 deletion test/src/User/HTMLForm/UserLoginFormTest.php
Expand Up @@ -19,7 +19,8 @@ class UserLoginFormTest extends TestCase
*/
public static function setUpBeforeClass()
{
self::$di = new \Anax\DI\DIFactoryConfig("testDi.php");
self::$di = new \Anax\DI\DIFactoryConfig();
self::$di->configure(ANAX_APP_PATH . "/test/config/testDi.php");
}


Expand Down
Expand Up @@ -5,7 +5,7 @@
/**
* Helper class to mock methods.
*/
class Helper
class MockingClass
{

/**
Expand Down
54 changes: 35 additions & 19 deletions test/src/User/UserControllerTest.php
Expand Up @@ -15,28 +15,14 @@ class UserControllerTest extends TestCase
protected static $userController;


// /**
// * Setup before testing class.
// */
// public static function setUpBeforeClass()
// {
// self::$di = new \Anax\DI\DIFactoryConfig("testDi.php");
// self::$userController = new UserController();
// self::$userController->setDi(self::$di);
// self::$userController->init();
// self::$session = self::$di->get("session");
// $user = new User();
// $user->id = 2;
// $user->username = "admin";
// $user->administrator = true;
// $user->enabled = true;
//
// self::$session->set("user", $user);
// }

/**
* Setup testing environment
*/
public function setUp()
{
self::$di = new \Anax\DI\DIFactoryConfig("testDi.php");
self::$di = new \Anax\DI\DIFactoryConfig();
self::$di->configure(ANAX_APP_PATH . "/test/config/testDi.php");
self::$userController = new UserController();
self::$userController->setDi(self::$di);
self::$userController->init();
Expand All @@ -50,6 +36,8 @@ public function setUp()
self::$session->set("user", $admin);
}



/**
* Initiate the controller test.
*/
Expand All @@ -59,6 +47,7 @@ public function testInit()
}



/**
* Create an object.
*/
Expand All @@ -67,6 +56,10 @@ public function testCreate()
$userController = new UserController();
$this->assertInstanceOf("Peto16\User\UserController", $userController);
}




/**
* Inject $di.
*/
Expand All @@ -79,20 +72,33 @@ public function testInjectDi()
}



/**
* Test the login process
* @return void
*/
public function testGetPostLogin()
{
self::$userController->getPostLogin();
}



/**
* Test create user.
* @return void
*/
public function testGetPostCreateUser()
{
self::$userController->getPostCreateUser();
}



/**
* Test update user.
* @return void
*/
public function testGetPostUpdateUser()
{
self::$userController->getPostUpdateUser(1);
Expand All @@ -112,6 +118,10 @@ public function testGetPostUpdateUser()



/**
* Test delete user.
* @return void
*/
public function testGetPostDeleteUser()
{
self::$userController->getPostDeleteUser(1);
Expand All @@ -131,8 +141,14 @@ public function testGetPostDeleteUser()



/**
* Test logout.
* @return void
*/
public function testLogout()
{
$this->assertTrue(self::$session->has("user"));
self::$userController->logout();
$this->assertFalse(self::$session->has("user"));
}
}
3 changes: 2 additions & 1 deletion test/src/User/UserServiceTest.php
Expand Up @@ -17,7 +17,8 @@ class UserServiceTest extends TestCase
*/
public function setUp()
{
self::$di = new \Anax\DI\DIFactoryConfig("testDi.php");
self::$di = new \Anax\DI\DIFactoryConfig();
self::$di->configure(ANAX_APP_PATH . "/test/config/testDi.php");
self::$session = self::$di->get("session");
self::$userService = new UserService(self::$di);
$admin = new User();
Expand Down

0 comments on commit ab98a0a

Please sign in to comment.