Skip to content

Commit

Permalink
Increasing test coverage (#1711)
Browse files Browse the repository at this point in the history
* added a few more tests, renamed singular to plural to match controller

* increase error reporting

* removed debugging and wait for tests
  • Loading branch information
luceos authored and franzliedke committed Jan 1, 2019
1 parent 208bad3 commit 1670590
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ install:
- composer install
- mysql -e 'CREATE DATABASE flarum;'

before_script:
- echo 'error_reporting = E_ALL' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

script:
- vendor/bin/phpunit --coverage-clover=coverage.xml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Flarum\Api\Controller\ListDiscussionsController;
use Flarum\Discussion\Discussion;

class ListDiscussionControllerTest extends ApiControllerTestCase
class ListDiscussionsControllerTest extends ApiControllerTestCase
{
protected $controller = ListDiscussionsController::class;

Expand Down
33 changes: 33 additions & 0 deletions tests/Api/Controller/ListGroupsControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Flarum\Tests\Api\Controller;

use Flarum\Api\Controller\ListGroupsController;
use Flarum\Group\Group;

class ListGroupsControllerTest extends ApiControllerTestCase
{
protected $controller = ListGroupsController::class;

/**
* @test
*/
public function shows_index_for_guest()
{
$response = $this->callWith();

$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody()->getContents(), true);

$this->assertEquals(Group::count(), count($data['data']));
}
}
40 changes: 40 additions & 0 deletions tests/Api/Controller/ListNotificationsControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Flarum\Tests\Api\Controller;

use Flarum\Api\Controller\ListNotificationsController;

class ListNotificationsControllerTest extends ApiControllerTestCase
{
protected $controller = ListNotificationsController::class;

/**
* @test
* @expectedException \Flarum\User\Exception\PermissionDeniedException
*/
public function disallows_index_for_guest()
{
$this->callWith();
}

/**
* @test
*/
public function show_index_for_user()
{
$this->actor = $this->getNormalUser();

$response = $this->callWith();

$this->assertEquals(200, $response->getStatusCode());
}
}
40 changes: 40 additions & 0 deletions tests/Api/Controller/ListUsersControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Flarum\Tests\Api\Controller;

use Flarum\Api\Controller\ListUsersController;

class ListUsersControllerTest extends ApiControllerTestCase
{
protected $controller = ListUsersController::class;

/**
* @test
* @expectedException \Flarum\User\Exception\PermissionDeniedException
*/
public function disallows_index_for_guest()
{
$this->callWith();
}

/**
* @test
*/
public function shows_index_for_admin()
{
$this->actor = $this->getAdminUser();

$response = $this->callWith();

$this->assertEquals(200, $response->getStatusCode());
}
}

0 comments on commit 1670590

Please sign in to comment.