From 167059027e5a066d618599c90164ef1b5a509148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Tue, 1 Jan 2019 21:02:18 +0100 Subject: [PATCH] Increasing test coverage (#1711) * added a few more tests, renamed singular to plural to match controller * increase error reporting * removed debugging and wait for tests --- .travis.yml | 3 ++ ....php => ListDiscussionsControllerTest.php} | 2 +- .../Controller/ListGroupsControllerTest.php | 33 +++++++++++++++ .../ListNotificationsControllerTest.php | 40 +++++++++++++++++++ .../Controller/ListUsersControllerTest.php | 40 +++++++++++++++++++ 5 files changed, 117 insertions(+), 1 deletion(-) rename tests/Api/Controller/{ListDiscussionControllerTest.php => ListDiscussionsControllerTest.php} (94%) create mode 100644 tests/Api/Controller/ListGroupsControllerTest.php create mode 100644 tests/Api/Controller/ListNotificationsControllerTest.php create mode 100644 tests/Api/Controller/ListUsersControllerTest.php diff --git a/.travis.yml b/.travis.yml index c62d1e8d6e..d4a4effca1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/tests/Api/Controller/ListDiscussionControllerTest.php b/tests/Api/Controller/ListDiscussionsControllerTest.php similarity index 94% rename from tests/Api/Controller/ListDiscussionControllerTest.php rename to tests/Api/Controller/ListDiscussionsControllerTest.php index 276d0273a0..c7d2abe932 100644 --- a/tests/Api/Controller/ListDiscussionControllerTest.php +++ b/tests/Api/Controller/ListDiscussionsControllerTest.php @@ -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; diff --git a/tests/Api/Controller/ListGroupsControllerTest.php b/tests/Api/Controller/ListGroupsControllerTest.php new file mode 100644 index 0000000000..34d945a904 --- /dev/null +++ b/tests/Api/Controller/ListGroupsControllerTest.php @@ -0,0 +1,33 @@ + + * + * 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'])); + } +} diff --git a/tests/Api/Controller/ListNotificationsControllerTest.php b/tests/Api/Controller/ListNotificationsControllerTest.php new file mode 100644 index 0000000000..f269b8da8b --- /dev/null +++ b/tests/Api/Controller/ListNotificationsControllerTest.php @@ -0,0 +1,40 @@ + + * + * 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()); + } +} diff --git a/tests/Api/Controller/ListUsersControllerTest.php b/tests/Api/Controller/ListUsersControllerTest.php new file mode 100644 index 0000000000..34350db875 --- /dev/null +++ b/tests/Api/Controller/ListUsersControllerTest.php @@ -0,0 +1,40 @@ + + * + * 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()); + } +}