Commit c7e1d228 authored by Jacob Priddy's avatar Jacob Priddy 👌

Fix tests.

parent 2d88155c
Pipeline #11829 passed with stages
in 3 minutes and 2 seconds
......@@ -43,7 +43,6 @@ class AuthController extends ApiController
*/
public function welcome(): JsonResponse
{
dd(microtime(true) - LARAVEL_START);
return new JsonResponse(['welcome' => 'Welcome to the elock API.']);
}
......
<?php
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
......
......@@ -20,7 +20,8 @@ class CreateGroupApiTest extends AuthenticatesWithApplicationTestCase
{
parent::setUp();
$this->groups = $this->app->make(GroupsRepository::class);
$this->groups = new InMemoryGroupsRepository();
$this->instance(GroupsRepository::class, $this->groups);
}
/**
......@@ -89,6 +90,7 @@ class CreateGroupApiTest extends AuthenticatesWithApplicationTestCase
* @param array $message
* @dataProvider invalidGroupProvider
* @throws EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_tests_the_validation_rules(array $data, array $message): void
{
......@@ -100,6 +102,7 @@ class CreateGroupApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_creates_a_group(): void
{
......
......@@ -8,12 +8,13 @@ use Illuminate\Testing\TestResponse;
use Source\Gateways\Groups\GroupsRepository;
use Source\Exceptions\EntityNotFoundException;
use Tests\Doubles\InMemoryGroupsRepositoryStub;
use Source\Gateways\Groups\InMemoryGroupsRepository;
use Tests\Feature\AuthenticatesWithApplicationTestCase;
class DeleteGroupApiTest extends AuthenticatesWithApplicationTestCase
{
/**
* @var \Illuminate\Foundation\Testing\TestResponse
* @var \Illuminate\Testing\TestResponse
*/
protected TestResponse $response;
......@@ -26,7 +27,8 @@ class DeleteGroupApiTest extends AuthenticatesWithApplicationTestCase
{
parent::setUp();
$this->groups = $this->app->make(GroupsRepository::class);
$this->groups = new InMemoryGroupsRepository();
$this->instance(GroupsRepository::class, $this->groups);
}
protected function stubGroupsRepository(): void
......@@ -56,6 +58,7 @@ class DeleteGroupApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_protects_the_route(): void
{
......@@ -69,6 +72,7 @@ class DeleteGroupApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_deletes_a_non_existent_group(): void
{
......@@ -81,6 +85,7 @@ class DeleteGroupApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_deletes_a_group(): void
{
......@@ -105,6 +110,7 @@ class DeleteGroupApiTest extends AuthenticatesWithApplicationTestCase
* @test
* @throws EntityNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_handles_a_failed_delete(): void
{
......
......@@ -7,12 +7,13 @@ use Source\Entities\Group;
use Illuminate\Testing\TestResponse;
use Source\Gateways\Groups\GroupsRepository;
use Source\Exceptions\EntityNotFoundException;
use Source\Gateways\Groups\InMemoryGroupsRepository;
use Tests\Feature\AuthenticatesWithApplicationTestCase;
class GetAllGroupsApiTest extends AuthenticatesWithApplicationTestCase
{
/**
* @var \Illuminate\Foundation\Testing\TestResponse
* @var \Illuminate\Testing\TestResponse
*/
protected TestResponse $response;
......@@ -25,7 +26,8 @@ class GetAllGroupsApiTest extends AuthenticatesWithApplicationTestCase
{
parent::setUp();
$this->groups = $this->app->make(GroupsRepository::class);
$this->groups = new InMemoryGroupsRepository();
$this->instance(GroupsRepository::class, $this->groups);
}
protected function handleTest(): void
......@@ -46,6 +48,7 @@ class GetAllGroupsApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_protects_the_route(): void
{
......@@ -59,6 +62,7 @@ class GetAllGroupsApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_returns_empty_when_no_groups_are_added(): void
{
......@@ -75,6 +79,7 @@ class GetAllGroupsApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_returns_groups_in_the_repository(): void
{
......
......@@ -8,22 +8,35 @@ use Source\Entities\Group;
use Illuminate\Testing\TestResponse;
use Source\Gateways\Groups\GroupsRepository;
use Source\Gateways\GroupUser\GroupUserRepository;
use Source\Gateways\Groups\InMemoryGroupsRepository;
use Tests\Feature\AuthenticatesWithApplicationTestCase;
use Source\Gateways\GroupUser\InMemoryGroupUserRepository;
class GetUsersForGroupApiTest extends AuthenticatesWithApplicationTestCase
{
/**
* @var \Illuminate\Testing\TestResponse
*/
protected TestResponse $response;
protected GroupsRepository $groups;
/**
* @var \Source\Gateways\Groups\InMemoryGroupsRepository
*/
protected InMemoryGroupsRepository $groups;
protected GroupUserRepository $repository;
/**
* @var \Source\Gateways\GroupUser\InMemoryGroupUserRepository
*/
protected InMemoryGroupUserRepository $repository;
public function setUp(): void
{
parent::setUp();
$this->groups = $this->app->make(GroupsRepository::class);
$this->repository = $this->app->make(GroupUserRepository::class);
$this->groups = new InMemoryGroupsRepository();
$this->repository = new InMemoryGroupUserRepository($this->usersRepository, $this->groups);
$this->instance(GroupsRepository::class, $this->groups);
$this->instance(GroupUserRepository::class, $this->repository);
}
public function handleTest(string $groupId): void
......@@ -44,6 +57,7 @@ class GetUsersForGroupApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_protects_the_route(): void
{
......@@ -57,6 +71,7 @@ class GetUsersForGroupApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_gets_users_for_a_group(): void
{
......
......@@ -14,7 +14,7 @@ use Source\Gateways\GroupUser\InMemoryGroupUserRepository;
class GetCurrentUserGroupsApiTest extends AuthenticatesWithApplicationTestCase
{
/**
* @var \Illuminate\Foundation\Testing\TestResponse
* @var \Illuminate\Testing\TestResponse
*/
protected TestResponse $response;
......@@ -32,8 +32,10 @@ class GetCurrentUserGroupsApiTest extends AuthenticatesWithApplicationTestCase
{
parent::setUp();
$this->groups = $this->app->make(GroupsRepository::class);
$this->repository = $this->app->make(GroupUserRepository::class);
$this->groups = new InMemoryGroupsRepository();
$this->repository = new InMemoryGroupUserRepository($this->usersRepository, $this->groups);
$this->instance(GroupsRepository::class, $this->groups);
$this->instance(GroupUserRepository::class, $this->repository);
}
protected function handleTest(): void
......@@ -54,6 +56,7 @@ class GetCurrentUserGroupsApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_gets_the_logged_in_user_groups(): void
{
......
......@@ -8,7 +8,9 @@ use Source\Entities\Group;
use Illuminate\Testing\TestResponse;
use Source\Gateways\Groups\GroupsRepository;
use Source\Gateways\GroupUser\GroupUserRepository;
use Source\Gateways\Groups\InMemoryGroupsRepository;
use Tests\Feature\AuthenticatesWithApplicationTestCase;
use Source\Gateways\GroupUser\InMemoryGroupUserRepository;
class AddUserToGroupApiTest extends AuthenticatesWithApplicationTestCase
{
......@@ -22,8 +24,10 @@ class AddUserToGroupApiTest extends AuthenticatesWithApplicationTestCase
{
parent::setUp();
$this->groups = $this->app->make(GroupsRepository::class);
$this->repository = $this->app->make(GroupUserRepository::class);
$this->groups = new InMemoryGroupsRepository();
$this->repository = new InMemoryGroupUserRepository($this->usersRepository, $this->groups);
$this->instance(GroupsRepository::class, $this->groups);
$this->instance(GroupUserRepository::class, $this->repository);
}
public function handleTest(string $userId, string $groupId): void
......@@ -47,6 +51,7 @@ class AddUserToGroupApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_protects_the_route(): void
{
......@@ -60,6 +65,7 @@ class AddUserToGroupApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_adds_a_group_to_a_user(): void
{
......
......@@ -8,7 +8,9 @@ use Source\Entities\Group;
use Illuminate\Testing\TestResponse;
use Source\Gateways\Groups\GroupsRepository;
use Source\Gateways\GroupUser\GroupUserRepository;
use Source\Gateways\Groups\InMemoryGroupsRepository;
use Tests\Feature\AuthenticatesWithApplicationTestCase;
use Source\Gateways\GroupUser\InMemoryGroupUserRepository;
class GetGroupsForUserApiTest extends AuthenticatesWithApplicationTestCase
{
......@@ -22,8 +24,10 @@ class GetGroupsForUserApiTest extends AuthenticatesWithApplicationTestCase
{
parent::setUp();
$this->groups = $this->app->make(GroupsRepository::class);
$this->repository = $this->app->make(GroupUserRepository::class);
$this->groups = new InMemoryGroupsRepository();
$this->repository = new InMemoryGroupUserRepository($this->usersRepository, $this->groups);
$this->instance(GroupsRepository::class, $this->groups);
$this->instance(GroupUserRepository::class, $this->repository);
}
public function handleTest(string $userId): void
......@@ -44,6 +48,7 @@ class GetGroupsForUserApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_protects_the_route(): void
{
......
......@@ -8,7 +8,9 @@ use Source\Entities\Group;
use Illuminate\Testing\TestResponse;
use Source\Gateways\Groups\GroupsRepository;
use Source\Gateways\GroupUser\GroupUserRepository;
use Source\Gateways\Groups\InMemoryGroupsRepository;
use Tests\Feature\AuthenticatesWithApplicationTestCase;
use Source\Gateways\GroupUser\InMemoryGroupUserRepository;
class RemoveUserFromGroupApiTest extends AuthenticatesWithApplicationTestCase
{
......@@ -22,8 +24,10 @@ class RemoveUserFromGroupApiTest extends AuthenticatesWithApplicationTestCase
{
parent::setUp();
$this->groups = $this->app->make(GroupsRepository::class);
$this->repository = $this->app->make(GroupUserRepository::class);
$this->groups = new InMemoryGroupsRepository();
$this->repository = new InMemoryGroupUserRepository($this->usersRepository, $this->groups);
$this->instance(GroupsRepository::class, $this->groups);
$this->instance(GroupUserRepository::class, $this->repository);
}
public function handleTest(string $userId, string $groupId): void
......@@ -47,6 +51,7 @@ class RemoveUserFromGroupApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_protects_the_route(): void
{
......@@ -60,6 +65,7 @@ class RemoveUserFromGroupApiTest extends AuthenticatesWithApplicationTestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_removes_a_group_from_a_user(): void
{
......
......@@ -50,10 +50,13 @@ class AuthenticatesWithApplicationTestCase extends TestCase
return new AuthorizerStub();
});
$this->tokens = $this->app->make(TokensRepository::class);
$this->usersRepository = $this->app->make(UsersRepository::class);
$this->tokens = new InMemoryTokensRepository();
$this->usersRepository = new InMemoryUsersRepository();
$this->doorsRepository = new InMemoryDoorsRepository();
$this->instance(TokensRepository::class, $this->tokens);
$this->instance(UsersRepository::class, $this->usersRepository);
$this->instance(DoorsRepository::class, $this->doorsRepository);
$this->authorizer = $this->app->make(Authorizer::class);
$this->doorsRepository = $this->app->make(DoorsRepository::class);
}
/**
......
......@@ -9,3 +9,6 @@ composer install
# Apply any new migrations
php artisan migrate --force
# Regenerate cache
php artisan optimize
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment