diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000000..eb8e63b57e --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1 @@ +src_dir: . diff --git a/.travis.yml b/.travis.yml index 7bb9738240..cd3884df53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,7 @@ php: - 5.5 install: - - composer install \ No newline at end of file + - composer install + +after_script: + - php vendor/bin/coveralls \ No newline at end of file diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 931c033400..4fcfb8d87c 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -20,15 +20,13 @@ class UserController extends BaseController public function postLogin() { - if (!$this->user->auth()) { - $rememberMe = Input::get('remember_me') == '1'; - $data = [ - 'email' => Input::get('email'), - 'password' => Input::get('password') - ]; - if (Auth::attempt($data, $rememberMe)) { - return Redirect::route('index'); - } + $rememberMe = Input::get('remember_me') == '1'; + $data = [ + 'email' => Input::get('email'), + 'password' => Input::get('password') + ]; + if (Auth::attempt($data, $rememberMe)) { + return Redirect::route('index'); } Session::flash('error', 'No good!'); return View::make('user.login'); @@ -47,7 +45,7 @@ class UserController extends BaseController if (Config::get('auth.allow_register') !== true) { return App::abort(404); } - $user = $this->user->register(); + $user = $this->user->register(Input::all()); if ($user) { if (Config::get('auth.verify_mail') === true) { $this->email->sendVerificationMail($user); @@ -95,6 +93,7 @@ class UserController extends BaseController } return View::make('error')->with('message', 'Yo no hablo verification code!'); } + public function reset($reset) { $user = $this->user->findByReset($reset); @@ -105,4 +104,4 @@ class UserController extends BaseController return View::make('error')->with('message', 'Yo no hablo reset code!'); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/app/lib/Firefly/Storage/User/EloquentUserRepository.php b/app/lib/Firefly/Storage/User/EloquentUserRepository.php index 492d232416..b5d3b4ed0a 100644 --- a/app/lib/Firefly/Storage/User/EloquentUserRepository.php +++ b/app/lib/Firefly/Storage/User/EloquentUserRepository.php @@ -9,10 +9,10 @@ class EloquentUserRepository implements UserRepositoryInterface { } - public function register() + public function register($array) { $user = new \User; - $user->email = \Input::get('email'); + $user->email = $array['emai']; $user->migrated = 0; $user->verification = \Str::random(32); $user->password = \Hash::make(\Str::random(12)); @@ -26,11 +26,11 @@ class EloquentUserRepository implements UserRepositoryInterface return $user; } - public function auth() + public function auth($array) { - $user = \User::where('email', \Input::get('email'))->first(); + $user = \User::where('email', $array['email'])->first(); if (!is_null($user)) { - if (\Hash::check(\Input::get('password'), $user->password)) { + if (\Hash::check($array['password'], $user->password)) { } } return false; @@ -45,6 +45,7 @@ class EloquentUserRepository implements UserRepositoryInterface { return \User::where('reset', $reset)->first(); } + public function findByEmail($email) { return \User::where('email', $email)->first(); diff --git a/app/lib/Firefly/Storage/User/UserRepositoryInterface.php b/app/lib/Firefly/Storage/User/UserRepositoryInterface.php index b369e5f852..4490249d99 100644 --- a/app/lib/Firefly/Storage/User/UserRepositoryInterface.php +++ b/app/lib/Firefly/Storage/User/UserRepositoryInterface.php @@ -6,9 +6,9 @@ namespace Firefly\Storage\User; interface UserRepositoryInterface { - public function register(); + public function register($array); - public function auth(); + public function auth($array); public function findByVerification($verification); public function findByReset($reset); diff --git a/app/tests/controllers/UserControllerTest.php b/app/tests/controllers/UserControllerTest.php new file mode 100644 index 0000000000..e8df87031e --- /dev/null +++ b/app/tests/controllers/UserControllerTest.php @@ -0,0 +1,40 @@ +mock = $this->mock('Firefly\Storage\User\UserRepositoryInterface'); + } + + public function mock($class) + { + $mock = Mockery::mock($class); + + $this->app->instance($class, $mock); + + return $mock; + } + + public function testLogin() + { + View::shouldReceive('make')->with('user.login'); + $this->call('GET', '/login'); + } + + public function testPostLogin() + { + $data = ['email' => 'bla@bla.nl', 'password' => 'xxxx','remember_me' => '1']; + Auth::shouldReceive('attempt')->once()->andReturn(true); + $this->call('POST', '/login', $data); + } + + public function tearDown() + { + Mockery::close(); + } + +} \ No newline at end of file diff --git a/build/logs/clover.xml b/build/logs/clover.xml new file mode 100644 index 0000000000..d5879bf29c --- /dev/null +++ b/build/logs/clover.xml @@ -0,0 +1,297 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/composer.json b/composer.json index 175c347c1d..60943d18da 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ }, "require-dev": { "barryvdh/laravel-debugbar": "1.*", - "barryvdh/laravel-ide-helper": "1.*" + "barryvdh/laravel-ide-helper": "1.*", + "mockery/mockery": "dev-master" }, "autoload": { "classmap": [