Permalink
Browse files

Added some tests + fixed some bugs.

  • Loading branch information...
1 parent 6425d0e commit 60ba391dc511e7b24dc03e533d33fe419e3e3565 @assertchris assertchris committed Mar 13, 2014
@@ -34,10 +34,11 @@ protected function registerGithub()
$this->app['github'] = $this->app->share(function ($app) {
$provider = $app['github.provider'];
- $users = $app->make('Tricks\Repositories\UserRepositoryInterface');
- $profiles = $app->make('Tricks\Repositories\ProfileRepositoryInterface');
+ $config = $app['config'];
+ $users = $app['Tricks\Repositories\UserRepositoryInterface'];
+ $profiles = $app['Tricks\Repositories\ProfileRepositoryInterface'];
- return new Github($provider, $users, $profiles);
+ return new Github($provider, $config, $users, $profiles);
});
}
@@ -137,7 +137,7 @@ public function testStoreViewedTrick()
$storeMock
->shouldReceive('put')
->atLeast()->once()
- ->with('viewed_tricks.' . $id, time())
+ ->with('viewed_tricks.' . $id, Mockery::type('int'))
->andReturn('mocked');
$viewTrickHandlerMock = Mockery::mock('Tricks\Events\ViewTrickHandler[storeViewedTrick]', [
@@ -0,0 +1,40 @@
+<?php
+
+namespace Tricks\Providers;
+
+use App;
+use Mockery;
+use TestCase;
+
+class EventServiceProviderTest
+extends TestCase
+{
+ public function tearDown()
+ {
+ Mockery::close();
+ }
+
+ public function testRegister()
+ {
+ $dispatcherMock = Mockery::mock('Illuminate\Events\Dispatcher');
+
+ $dispatcherMock
+ ->shouldReceive('listen')
+ ->atLeast()->once()
+ ->with('trick.view', 'Tricks\Events\ViewTrickHandler');
+
+ $applicationMock = Mockery::mock('Illuminate\Foundation\Application');
+
+ $applicationMock
+ ->shouldReceive('offsetGet')
+ ->atLeast()->once()
+ ->with('events')
+ ->andReturn($dispatcherMock);
+
+ $provider = new EventServiceProvider(
+ $applicationMock
+ );
+
+ App::register($provider, [], true);
+ }
+}
@@ -0,0 +1,60 @@
+<?php
+
+namespace Tricks\Providers;
+
+use App;
+use Mockery;
+use TestCase;
+
+class NavigationServiceProviderTest
+extends TestCase
+{
+ public function tearDown()
+ {
+ Mockery::close();
+ }
+
+ public function testRegister()
+ {
+ $mock = Mockery::mock('Illuminate\Foundation\Application');
+
+ $mock
+ ->shouldReceive('share')
+ ->atLeast()->once()
+ ->with(Mockery::on(function($callback) {
+ $mock = Mockery::mock('Illuminate\Foundation\Application');
+
+ $mock
+ ->shouldReceive('offsetGet')
+ ->atLeast()->once()
+ ->with('config')
+ ->andReturn(
+ Mockery::mock('Illuminate\Config\Repository')
+ );
+
+ $mock
+ ->shouldReceive('offsetGet')
+ ->atLeast()->once()
+ ->with('auth')
+ ->andReturn(
+ Mockery::mock('Illuminate\Auth\AuthManager')
+ );
+
+ $this->assertInstanceOf('Tricks\Services\Navigation\Builder', $callback($mock));
+
+ return true;
+ }))
+ ->andReturn('mocked');
+
+ $mock
+ ->shouldReceive('offsetSet')
+ ->atLeast()->once()
+ ->with('navigation.builder', 'mocked');
+
+ $provider = new NavigationServiceProvider(
+ $mock
+ );
+
+ App::register($provider, [], true);
+ }
+}
@@ -0,0 +1,67 @@
+<?php
+
+namespace Tricks\Providers;
+
+use App;
+use Mockery;
+use TestCase;
+
+class RepositoryServiceProviderTest
+extends TestCase
+{
+ public function tearDown()
+ {
+ Mockery::close();
+ }
+
+ public function testRegister()
+ {
+ $mock = Mockery::mock('Illuminate\Foundation\Application');
+
+ $mock
+ ->shouldReceive('bind')
+ ->atLeast()->once()
+ ->with(
+ 'Tricks\Repositories\UserRepositoryInterface',
+ 'Tricks\Repositories\Eloquent\UserRepository'
+ );
+
+ $mock
+ ->shouldReceive('bind')
+ ->atLeast()->once()
+ ->with(
+ 'Tricks\Repositories\ProfileRepositoryInterface',
+ 'Tricks\Repositories\Eloquent\ProfileRepository'
+ );
+
+ $mock
+ ->shouldReceive('bind')
+ ->atLeast()->once()
+ ->with(
+ 'Tricks\Repositories\TrickRepositoryInterface',
+ 'Tricks\Repositories\Eloquent\TrickRepository'
+ );
+
+ $mock
+ ->shouldReceive('bind')
+ ->atLeast()->once()
+ ->with(
+ 'Tricks\Repositories\TagRepositoryInterface',
+ 'Tricks\Repositories\Eloquent\TagRepository'
+ );
+
+ $mock
+ ->shouldReceive('bind')
+ ->atLeast()->once()
+ ->with(
+ 'Tricks\Repositories\CategoryRepositoryInterface',
+ 'Tricks\Repositories\Eloquent\CategoryRepository'
+ );
+
+ $provider = new RepositoryServiceProvider(
+ $mock
+ );
+
+ App::register($provider, [], true);
+ }
+}
@@ -0,0 +1,32 @@
+<?php
+
+namespace Tricks\Providers;
+
+use App;
+use Mockery;
+use TestCase;
+
+class SitemapServiceProviderTest
+extends TestCase
+{
+ public function tearDown()
+ {
+ Mockery::close();
+ }
+
+ public function testRegister()
+ {
+ $mock = Mockery::mock('Illuminate\Foundation\Application');
+
+ $mock
+ ->shouldReceive('alias')
+ ->atLeast()->once()
+ ->with('sitemap', 'Roumen\Sitemap\Sitemap');
+
+ $provider = new SitemapServiceProvider(
+ $mock
+ );
+
+ App::register($provider, [], true);
+ }
+}
@@ -0,0 +1,159 @@
+<?php
+
+namespace Tricks\Providers;
+
+use Mockery;
+use TestCase;
+
+class SocialServiceProviderTest
+extends TestCase
+{
+ public function tearDown()
+ {
+ Mockery::close();
+ }
+
+ public function testRegister()
+ {
+ $mock = Mockery::mock('Tricks\Providers\SocialServiceProvider[registerGithub,registerDisqus]', [
+ Mockery::mock('Illuminate\Foundation\Application')
+ ])->shouldAllowMockingProtectedMethods();
+
+ $mock
+ ->shouldReceive('registerGithub')
+ ->atLeast()->once();
+
+ $mock
+ ->shouldReceive('registerDisqus')
+ ->atLeast()->once();
+
+ $mock->register();
+ }
+
+ public function testRegisterGithub()
+ {
+ $applicationMock = Mockery::mock('Illuminate\Foundation\Application');
+
+ $applicationMock
+ ->shouldReceive('offsetSet')
+ ->atLeast()->once()
+ ->with('github.provider', 'mocked');
+
+ $repositoryMock = Mockery::mock('Illuminate\Config\Repository');
+
+ $repositoryMock
+ ->shouldReceive('get')
+ ->atLeast()->once()
+ ->with('social.github')
+ ->andReturn([]);
+
+ $applicationMock
+ ->shouldReceive('offsetGet')
+ ->atLeast()->once()
+ ->with('config')
+ ->andReturn(
+ $repositoryMock
+ );
+
+ $applicationMock
+ ->shouldReceive('share')
+ ->atLeast()->once()
+ ->with(
+ Mockery::on(function($callback) use ($applicationMock) {
+ $callback($applicationMock);
+
+ return true;
+ })
+ )
+ ->andReturn('mocked');
+
+ $applicationMock
+ ->shouldReceive('offsetSet')
+ ->atLeast()->once()
+ ->with('github', 'mocked');
+
+ $applicationMock
+ ->shouldReceive('offsetGet')
+ ->atLeast()->once()
+ ->with('github.provider')
+ ->andReturn(
+ Mockery::mock('League\OAuth2\Client\Provider\Github')
+ );
+
+ $applicationMock
+ ->shouldReceive('offsetGet')
+ ->atLeast()->once()
+ ->with('Tricks\Repositories\UserRepositoryInterface')
+ ->andReturn(
+ Mockery::mock('Tricks\Repositories\UserRepositoryInterface')
+ );
+
+ $applicationMock
+ ->shouldReceive('offsetGet')
+ ->atLeast()->once()
+ ->with('Tricks\Repositories\ProfileRepositoryInterface')
+ ->andReturn(
+ Mockery::mock('Tricks\Repositories\ProfileRepositoryInterface')
+ );
+
+ $socialServiceProviderMock = Mockery::mock('Tricks\Providers\SocialServiceProvider[registerGithub]', [
+ $applicationMock
+ ])->shouldAllowMockingProtectedMethods();
+
+ $socialServiceProviderMock
+ ->shouldReceive('registerGithub')
+ ->atLeast()->once()
+ ->passthru();
+
+ $socialServiceProviderMock->registerGithub();
+ }
+
+ public function testRegisterDisqus()
+ {
+ $applicationMock = Mockery::mock('Illuminate\Foundation\Application');
+
+ $applicationMock
+ ->shouldReceive('offsetSet')
+ ->atLeast()->once()
+ ->with('disqus', 'mocked');
+
+ $repositoryMock = Mockery::mock('Illuminate\Config\Repository');
+
+ $repositoryMock
+ ->shouldReceive('get')
+ ->atLeast()->once()
+ ->with('social.disqus.requestUrl')
+ ->andReturn('mocked');
+
+ $applicationMock
+ ->shouldReceive('offsetGet')
+ ->atLeast()->once()
+ ->with('config')
+ ->andReturn(
+ $repositoryMock
+ );
+
+ $applicationMock
+ ->shouldReceive('share')
+ ->atLeast()->once()
+ ->with(
+ Mockery::on(function($callback) use ($applicationMock) {
+ $callback($applicationMock);
+
+ return true;
+ })
+ )
+ ->andReturn('mocked');
+
+ $socialServiceProviderMock = Mockery::mock('Tricks\Providers\SocialServiceProvider[registerDisqus]', [
+ $applicationMock
+ ])->shouldAllowMockingProtectedMethods();
+
+ $socialServiceProviderMock
+ ->shouldReceive('registerDisqus')
+ ->atLeast()->once()
+ ->passthru();
+
+ $socialServiceProviderMock->registerDisqus();
+ }
+}
Oops, something went wrong.

0 comments on commit 60ba391

Please sign in to comment.