mirror of
https://github.com/flarum/framework.git
synced 2025-02-17 02:02:47 +08:00
Integration tests for DiscussionRepository
Also add some TestDummy factories (needs more work)
This commit is contained in:
parent
6751cb2bea
commit
0ad1b9784f
10
framework/core/tests/_support/IntegrationHelper.php
Normal file
10
framework/core/tests/_support/IntegrationHelper.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
namespace Codeception\Module;
|
||||
|
||||
// here you can define custom actions
|
||||
// all public methods declared in helper class will be available in $I
|
||||
|
||||
class IntegrationHelper extends \Codeception\Module
|
||||
{
|
||||
|
||||
}
|
9
framework/core/tests/factories/factories.php
Normal file
9
framework/core/tests/factories/factories.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
$factory('Flarum\Core\Discussions\Discussion', [
|
||||
'title' => $faker->sentence
|
||||
]);
|
||||
|
||||
$factory('Flarum\Core\Users\User', [
|
||||
'username' => $faker->sentence
|
||||
]);
|
3
framework/core/tests/integration.suite.yml
Normal file
3
framework/core/tests/integration.suite.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
class_name: IntegrationTester
|
||||
modules:
|
||||
enabled: [IntegrationHelper, Laravel4, Mockery]
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
use Laracasts\TestDummy\Factory;
|
||||
use \Mockery as m;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Core\Discussions\Discussion;
|
||||
use Flarum\Core\Discussions\DiscussionRepository;
|
||||
use Codeception\Util\Stub;
|
||||
|
||||
class DiscussionRepositoryTest extends \Codeception\TestCase\Test
|
||||
{
|
||||
/**
|
||||
* @var \IntegrationTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
$this->repo = new DiscussionRepository;
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_discussion_by_id()
|
||||
{
|
||||
// Given I have a discussion
|
||||
$discussion = Factory::create('Flarum\Core\Discussions\Discussion');
|
||||
|
||||
// When I fetch the discussion by its ID
|
||||
$result = $this->repo->find($discussion->id);
|
||||
|
||||
// Then I should receive it
|
||||
$this->assertEquals($discussion->id, $result->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*/
|
||||
public function it_throws_an_exception_when_a_discussion_cannot_be_viewed()
|
||||
{
|
||||
// Given I have a discussion
|
||||
$discussion = Factory::create('Flarum\Core\Discussions\Discussion');
|
||||
|
||||
// And forum permissions do not allow guests to view the forum
|
||||
$manager = m::mock('Flarum\Core\Permissions\Manager');
|
||||
$manager->shouldReceive('granted')->andReturn(false);
|
||||
app()->instance('flarum.permissions', $manager);
|
||||
|
||||
// When I fetch the discussion by its ID, I expect an exception to be thrown
|
||||
$this->repo->findOrFail($discussion->id, new Flarum\Core\Users\Guest);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_saves_a_discussion()
|
||||
{
|
||||
// Given I have a new discussion
|
||||
$user = Factory::create('Flarum\Core\Users\User');
|
||||
$discussion = Discussion::start('foo', $user);
|
||||
|
||||
// When I save it
|
||||
$discussion = $this->repo->save($discussion);
|
||||
|
||||
// Then it should be in the database
|
||||
$this->tester->seeRecord('discussions', ['title' => 'foo']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @expectedException Flarum\Core\Support\Exceptions\ValidationFailureException
|
||||
*/
|
||||
public function it_will_not_save_an_invalid_discussion()
|
||||
{
|
||||
// Given I have a new discussion containing no information
|
||||
$discussion = new Discussion;
|
||||
|
||||
// When I save it, I expect an exception to be thrown
|
||||
$this->repo->save($discussion);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_deletes_a_discussion()
|
||||
{
|
||||
// Given I have a discussion
|
||||
$discussion = Factory::create('Flarum\Core\Discussions\Discussion');
|
||||
|
||||
// When I delete it
|
||||
$this->repo->delete($discussion);
|
||||
|
||||
// Then it should no longer be in the database
|
||||
$this->tester->dontSeeRecord('discussions', ['id' => $discussion->id]);
|
||||
}
|
||||
|
||||
}
|
1988
framework/core/tests/integration/IntegrationTester.php
Normal file
1988
framework/core/tests/integration/IntegrationTester.php
Normal file
File diff suppressed because it is too large
Load Diff
2
framework/core/tests/integration/_bootstrap.php
Normal file
2
framework/core/tests/integration/_bootstrap.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Here you can initialize variables that will be available to your tests
|
Loading…
Reference in New Issue
Block a user