Commit 625bb977 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

add tests for groups database repository

parent 70f9d79e
......@@ -5,7 +5,6 @@ namespace Source\Gateways\Groups;
use Source\Entities\Group;
// TODO: Write tests for this
class DatabaseGroupsRepository implements GroupsRepository
{
/**
......@@ -22,7 +21,11 @@ class DatabaseGroupsRepository implements GroupsRepository
return self::makeGroupFromDbGroup($group);
}
public static function makeGroupFromDbGroup(\App\Group $group): Group
/**
* @param \App\Group $group
* @return \Source\Entities\Group
*/
protected static function makeGroupFromDbGroup(\App\Group $group): Group
{
return new Group(
$group->id,
......@@ -58,7 +61,7 @@ class DatabaseGroupsRepository implements GroupsRepository
return self::makeGroupFromDbGroup($newGroup);
}
public static function fillBasicAttrs(Group $group, \App\Group $dbGroup): \App\Group
protected static function fillBasicAttrs(Group $group, \App\Group $dbGroup): \App\Group
{
$dbGroup->title = $group->getTitle();
$dbGroup->description = $group->getDescription();
......@@ -89,7 +92,7 @@ class DatabaseGroupsRepository implements GroupsRepository
*/
public function delete(string $groupId): bool
{
\App\Group::destroy($groupId);
return \App\Group::destroy($groupId);
}
/**
......
<?php
namespace Tests\Database;
use Source\Entities\Group;
use Tests\DatabaseTestCase;
use Source\Gateways\Groups\DatabaseGroupsRepository;
class GroupDatabaseTest extends DatabaseTestCase
{
/**
* @var \Source\Gateways\Groups\DatabaseGroupsRepository
*/
protected DatabaseGroupsRepository $groups;
public function setUp(): void
{
parent::setUp();
$this->groups = new DatabaseGroupsRepository();
}
/**
* @test
*/
public function it_gets_all_groups(): void
{
$all = $this->groups->all();
$this->assertEquals([], $all);
$this->groups->create(new Group(0, '', ''));
$this->groups->create(new Group(0, '', ''));
$all = $this->groups->all();
$this->assertCount(2, $all);
}
/**
* @test
*/
public function it_gets_a_group(): void
{
$group = $this->groups->get(10);
$this->assertNull($group);
$group = $this->groups->create(new Group(0, '',''));
$this->assertEquals($group, $this->groups->get(1));
}
/**
* @test
*/
public function it_creates_a_group(): void
{
$group = $this->groups->create(new Group(0, '', ''));
$this->assertEquals($group, $this->groups->get(1));
}
/**
* @test
*/
public function it_deletes_a_group(): void
{
$this->groups->create(new Group(0, '', ''));
$this->assertTrue($this->groups->delete(1));
$this->assertFalse($this->groups->exists(1));
$this->assertFalse($this->groups->delete(2));
}
/**
* @test
*/
public function it_checks_existence_of_groups(): void
{
$this->groups->create(new Group(0, '', ''));
$this->assertTrue($this->groups->exists(1));
$this->assertFalse($this->groups->exists(2));
}
/**
* @test
*/
public function it_updates_a_group(): void
{
$this->groups->create(new Group(0, 'title', 'description'));
$this->groups->update(1, new Group(0, 'new title', 'new desc'));
$group = $this->groups->get(1);
$this->assertEquals('new title', $group->getTitle());
$this->assertEquals('new desc', $group->getDescription());
}
}
......@@ -25,18 +25,12 @@ class UserDatabaseTest extends DatabaseTestCase
/**
* @test
*/
public function it_gets_all_users_with_none(): void
public function it_gets_all_users(): void
{
$all = $this->users->all();
$this->assertEquals([], $all);
}
/**
* @test
*/
public function it_gets_all_users(): void
{
$this->users->create(new User(0, '', '', '', null, 'email@email.com', null, null));
$this->users->create(new User(0, '', '', '', null, 'email2@email.com', null, null));
......@@ -57,7 +51,7 @@ class UserDatabaseTest extends DatabaseTestCase
$user = $this->users->get(1);
$this->assertEquals(
'cc356dd9dac1c54e8ad414ea2df7de0da19261724ccca9f449c3e33e1e5d996824241948a7e4bc466447aa9c3efccbfe8a32ced03fea8b5cd8c564f741382ee4',
DatabaseUsersRepository::secureDoorcode('doorcode'),
$user->getDoorcode()
);
......@@ -125,6 +119,8 @@ class UserDatabaseTest extends DatabaseTestCase
$this->assertTrue($this->users->delete(1));
$this->assertFalse($this->users->exists(1));
$this->assertFalse($this->users->delete(2));
}
......
Supports Markdown
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