Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added phpunit, mockery + a ton of tests.
- Loading branch information
1 parent
9011230
commit 14f1c30
Showing
13 changed files
with
675 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/bootstrap/compiled.php | ||
/vendor | ||
/report | ||
composer.phar | ||
composer.lock | ||
.DS_Store | ||
Thumbs.db | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Tricks; | ||
|
||
use Mockery; | ||
use TestCase; | ||
|
||
class CategoryTest | ||
extends TestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
Mockery::close(); | ||
} | ||
|
||
public function testTricks() | ||
{ | ||
$mock = Mockery::mock('Tricks\Category[belongsToMany]'); | ||
|
||
$mock | ||
->shouldReceive('belongsToMany') | ||
->atLeast()->once() | ||
->with('Tricks\Trick') | ||
->andReturn('mocked'); | ||
|
||
$this->assertEquals('mocked', $mock->tricks()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?php | ||
|
||
namespace Tricks\Events; | ||
|
||
use Mockery; | ||
use PHPUnit_Framework_Assert as Assert; | ||
use TestCase; | ||
|
||
class ViewTrickHandlerTest | ||
extends TestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
Mockery::close(); | ||
} | ||
|
||
public function testConstructor() | ||
{ | ||
$trickRepositoryMock = Mockery::mock('Tricks\Repositories\TrickRepositoryInterface'); | ||
|
||
$storeMock = Mockery::mock('Illuminate\Session\Store'); | ||
|
||
$viewTrickHandler = new ViewTrickHandler( | ||
$trickRepositoryMock, | ||
$storeMock | ||
); | ||
|
||
$this->assertEquals( | ||
$trickRepositoryMock, | ||
Assert::readAttribute($viewTrickHandler, 'tricks') | ||
); | ||
|
||
$this->assertEquals( | ||
$storeMock, | ||
Assert::readAttribute($viewTrickHandler, 'session') | ||
); | ||
} | ||
|
||
public function testHandle() | ||
{ | ||
$trickMock = Mockery::mock('Tricks\Trick'); | ||
|
||
$trickRepositoryMock = Mockery::mock('Tricks\Repositories\TrickRepositoryInterface'); | ||
|
||
$trickRepositoryMock | ||
->shouldReceive('incrementViews') | ||
->atLeast()->once() | ||
->with($trickMock) | ||
->andReturn('mocked'); | ||
|
||
$storeMock = Mockery::mock('Illuminate\Session\Store'); | ||
|
||
$viewTrickHandlerMock = Mockery::mock('Tricks\Events\ViewTrickHandler[hasViewedTrick,storeViewedTrick]', [ | ||
$trickRepositoryMock, | ||
$storeMock | ||
])->shouldAllowMockingProtectedMethods(); | ||
|
||
$viewTrickHandlerMock | ||
->shouldReceive('hasViewedTrick') | ||
->atLeast()->once() | ||
->andReturn(false); | ||
|
||
$viewTrickHandlerMock | ||
->shouldReceive('storeViewedTrick') | ||
->atLeast()->once() | ||
->with('mocked'); | ||
|
||
$viewTrickHandlerMock->handle($trickMock); | ||
} | ||
|
||
public function testHasViewedTrick() | ||
{ | ||
$viewTrickHandlerMock = Mockery::mock('Tricks\Events\ViewTrickHandler[getViewedTricks]', [ | ||
Mockery::mock('Tricks\Repositories\TrickRepositoryInterface'), | ||
Mockery::mock('Illuminate\Session\Store') | ||
]) | ||
->makePartial() | ||
->shouldAllowMockingProtectedMethods(); | ||
|
||
$time = time(); | ||
|
||
$tricks = [ | ||
"1" => $time - 50, | ||
"2" => $time - 150, | ||
"3" => $time | ||
]; | ||
|
||
$viewTrickHandlerMock | ||
->shouldReceive('getViewedTricks') | ||
->atLeast()->once() | ||
->andReturn($tricks); | ||
|
||
$trickMock = Mockery::mock('Tricks\Trick')->makePartial(); | ||
|
||
$trickMock->id = 2; | ||
|
||
$this->assertTrue($viewTrickHandlerMock->hasViewedTrick($trickMock)); | ||
} | ||
|
||
public function testGetViewedTricks() | ||
{ | ||
$trickRepositoryMock = Mockery::mock('Tricks\Repositories\TrickRepositoryInterface'); | ||
|
||
$storeMock = Mockery::mock('Illuminate\Session\Store'); | ||
|
||
$storeMock | ||
->shouldReceive('get') | ||
->atLeast()->once() | ||
->with('viewed_tricks', []) | ||
->andReturn('mocked'); | ||
|
||
$viewTrickHandlerMock = Mockery::mock('Tricks\Events\ViewTrickHandler[getViewedTricks]', [ | ||
$trickRepositoryMock, | ||
$storeMock | ||
])->shouldAllowMockingProtectedMethods(); | ||
|
||
$viewTrickHandlerMock | ||
->shouldReceive('getViewedTricks') | ||
->atLeast()->once() | ||
->passthru(); | ||
|
||
$this->assertEquals('mocked', $viewTrickHandlerMock->getViewedTricks()); | ||
} | ||
|
||
public function testStoreViewedTrick() | ||
{ | ||
$id = 2; | ||
|
||
$trickMock = Mockery::mock('Tricks\Trick')->makePartial(); | ||
|
||
$trickMock->id = $id; | ||
|
||
$trickRepositoryMock = Mockery::mock('Tricks\Repositories\TrickRepositoryInterface'); | ||
|
||
$storeMock = Mockery::mock('Illuminate\Session\Store'); | ||
|
||
$storeMock | ||
->shouldReceive('put') | ||
->atLeast()->once() | ||
->with('viewed_tricks.' . $id, time()) | ||
->andReturn('mocked'); | ||
|
||
$viewTrickHandlerMock = Mockery::mock('Tricks\Events\ViewTrickHandler[storeViewedTrick]', [ | ||
$trickRepositoryMock, | ||
$storeMock | ||
])->shouldAllowMockingProtectedMethods(); | ||
|
||
$viewTrickHandlerMock | ||
->shouldReceive('storeViewedTrick') | ||
->atLeast()->once() | ||
->with($trickMock) | ||
->passthru(); | ||
|
||
$viewTrickHandlerMock->storeViewedTrick($trickMock); | ||
} | ||
} |
Oops, something went wrong.