Skip to content

Commit

Permalink
Merge pull request #56 from stlgaits/main
Browse files Browse the repository at this point in the history
retrofit
  • Loading branch information
stlgaits authored Nov 20, 2022
2 parents bb52b66 + 7c085ee commit dd71fe1
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results

Large diffs are not rendered by default.

328 changes: 163 additions & 165 deletions clover.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
[![docsify](https://img.shields.io/badge/documented%20with-docsify-cc00ff.svg)](https://docsify.js.org/)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/def1dc4a68e847998365282ad9e8b3ee)](https://www.codacy.com/gh/EstelleMyddleware/todo/dashboard?utm_source=github.com&utm_medium=referral&utm_content=EstelleMyddleware/todo&utm_campaign=Badge_Coverage)

:mega::mega::mega: **You can view the detailed documentation & UML diagrams of this project [here](https://stlgaits.github.io/todo/)** :mega::mega::mega:

!> This project is part of the Openclassrooms PHP / Symfony Apps Developer training course. It consists in auditing,
unit-testing, profiling & making improvements to an existing to-do list app built in Symfony 3.1
(available [here](https://github.com/saro0h/projet8-TodoList)).

[![Estelle's GitHub stats](https://github-readme-stats.vercel.app/api?username=stlgaits&show_icons=true&theme=tokyonight)](https://github.com/stlgaits/github-readme-stats)

You can view the detailed documentation of this project [here](https://stlgaits.github.io/todo/)

## Installation

### Downloading the project
Expand Down
4 changes: 4 additions & 0 deletions src/Test/CustomTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
use Hautelook\AliceBundle\PhpUnit\RefreshDatabaseTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;


/**
* @codeCoverageIgnore
*/
class CustomTestCase extends WebTestCase
{
use RefreshDatabaseTrait;
Expand Down
11 changes: 10 additions & 1 deletion tests/Controller/DefaultControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
use App\Test\CustomTestCase;

/**
* @covers \App\Entity\DefaultController
* @covers \App\Controller\DefaultController
* @uses \App\Security\Voter\TaskVoter
* @uses \App\Entity\User
*/
final class DefaultControllerTest extends CustomTestCase
{

/**
* @covers \App\Controller\DefaultController::index
*/
public function testIndex(): void
{
self::ensureKernelShutdown();
Expand All @@ -23,6 +29,9 @@ public function testIndex(): void
$this->assertSelectorTextContains('h1', "Bienvenue sur Todo List, l'application vous permettant de gérer l'ensemble de vos tâches sans effort !");
}

/**
* @covers \App\Controller\DefaultController::index
*/
public function testVisitingWhileLoggedIn(): void
{
$client = self::createClient();
Expand Down
17 changes: 17 additions & 0 deletions tests/Controller/SecurityControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@
/**
* @group security
* @covers \App\Controller\SecurityController
* @covers \App\Security\Voter\TaskVoter
* @uses \App\Entity\User
*/
final class SecurityControllerTest extends CustomTestCase
{
/**
* @covers \App\Controller\SecurityController::login
*/
public function testAnyoneCanAccessLoginForm(): void
{
$client = $this->createClient();
$client->request('GET', '/login');
$this->assertResponseIsSuccessful();
}

/**
* @covers \App\Controller\SecurityController::login
*/
public function testLogin(): void
{
$client = $this->createClient();
Expand All @@ -28,6 +36,9 @@ public function testLogin(): void
$this->assertResponseIsSuccessful();
}

/**
* @covers \App\Controller\SecurityController::login
*/
public function testUserCanLoginViaForm(): void
{
$client = $this->createClient();
Expand All @@ -43,6 +54,9 @@ public function testUserCanLoginViaForm(): void
}


/**
* @covers \App\Controller\SecurityController::login
*/
public function testCannotLoginWithInvalidCredentials(): void
{
$client = static::createClient();
Expand All @@ -60,6 +74,9 @@ public function testCannotLoginWithInvalidCredentials(): void
}


/**
* @covers \App\Controller\SecurityController::logout
*/
public function testLogout(): void
{
$this->markTestSkipped();
Expand Down
52 changes: 51 additions & 1 deletion tests/Controller/TaskControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@
use App\Test\CustomTestCase;

/**
* @covers \App\Entity\TaskController
* @covers \App\Controller\TaskController
* @uses \App\Security\Voter\TaskVoter
* @uses \App\Entity\Task
* @uses \App\Repository\TaskRepository
* @uses \App\Entity\User
*/
final class TaskControllerTest extends CustomTestCase
{
/**
* @covers \App\Controller\TaskController::list
*/
public function testUserCanReadTasksList(): void
{
$client = $this->createClient();
Expand All @@ -22,6 +29,10 @@ public function testUserCanReadTasksList(): void
$this->assertResponseIsSuccessful();
}

/**
* @covers \App\Controller\TaskController::list
* @uses \App\Controller\DefaultController::index
*/
public function testUserCanAccessTaskListViaALink(): void
{
$client = $this->createClient();
Expand All @@ -35,6 +46,9 @@ public function testUserCanAccessTaskListViaALink(): void
$this->assertSelectorTextContains("button", "Marquer comme faite");
}

/**
* @covers \App\Controller\TaskController::list
*/
public function testCannotAccessTasksListAnonymously(): void
{
$client = $this->createClient();
Expand All @@ -44,6 +58,10 @@ public function testCannotAccessTasksListAnonymously(): void
}


/**
* @covers \App\Controller\TaskController::create
* @uses \App\Controller\SecurityController::login
*/
public function testCannotCreateTaskAnonymously(): void
{
$client = $this->createClient();
Expand All @@ -57,6 +75,10 @@ public function testCannotCreateTaskAnonymously(): void
);
}

/**
* @covers \App\Controller\TaskController::create
* @uses \App\Form\TaskType
*/
public function testLoggedInUsersCanAccessTaskCreationPage(): void
{
$client = $this->createClient();
Expand All @@ -70,6 +92,10 @@ public function testLoggedInUsersCanAccessTaskCreationPage(): void
$this->assertSelectorExists('button[type="submit"]');
}

/**
* @covers \App\Controller\TaskController::create
* @uses \App\Form\TaskType
*/
public function testUserCanCreateNewTask(): void
{
$client = $this->createClient();
Expand All @@ -91,6 +117,10 @@ public function testUserCanCreateNewTask(): void
}


/**
* @covers \App\Controller\TaskController::edit
* @uses \App\Form\TaskType
*/
public function testCannotEditTaskAuthor(): void
{
$client = $this->createClient();
Expand All @@ -117,6 +147,9 @@ public function testCannotEditTaskAuthor(): void
$this->assertResponseRedirects('/tasks', 303);
}

/**
* @covers \App\Controller\TaskController::deleteTask
*/
public function testAdminUserCanDeleteDefaultTasks(): void
{
$client = $this->createClient();
Expand All @@ -131,6 +164,10 @@ public function testAdminUserCanDeleteDefaultTasks(): void
$this->assertResponseRedirects('/tasks', 303);
}

/**
* @covers \App\Controller\TaskController::edit
* @uses \App\Form\TaskType
*/
public function testAuthorCanAccessTaskEditForm(): void
{
$client = $this->createClient();
Expand All @@ -147,6 +184,10 @@ public function testAuthorCanAccessTaskEditForm(): void
$this->assertSelectorExists('button[type="submit"]');
}

/**
* @covers \App\Controller\TaskController::edit
* @uses \App\Form\TaskType
*/
public function testTaskCanBeEdited(): void
{
$client = $this->createClient();
Expand All @@ -169,6 +210,9 @@ public function testTaskCanBeEdited(): void
}


/**
* @covers \App\Controller\TaskController::toggleTask
*/
public function testUserCanToggleATask(): void
{
$client = $this->createClient();
Expand All @@ -186,6 +230,9 @@ public function testUserCanToggleATask(): void
$this->assertResponseRedirects("/tasks", 303);
}

/**
* @covers \App\Controller\TaskController::deleteTask
*/
public function testAuthorCanDeleteTheirOwnTask(): void
{
$client = $this->createClient();
Expand All @@ -199,6 +246,9 @@ public function testAuthorCanDeleteTheirOwnTask(): void
$this->assertNull($taskRepository->find(2));
}

/**
* @covers \App\Controller\TaskController::deleteTask
*/
public function testCannotDeleteTaskOfWhichUserIsNotTheAuthor(): void
{
$client = $this->createClient();
Expand Down
34 changes: 33 additions & 1 deletion tests/Controller/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
namespace App\Tests\Controller;

use App\Test\CustomTestCase;
use http\Client\Curl\User;

/**
* @group security
* @covers App\Controller\UserController
* @uses \App\Entity\User
* @uses \App\Security\Voter\TaskVoter
*/
final class UserControllerTest extends CustomTestCase
{
/**
* @covers \App\Controller\UserController::list
*/
public function testOnlyAdminUsersCanAccessUsersListPage(): void
{
$client = $this->createClient();
Expand All @@ -20,6 +27,9 @@ public function testOnlyAdminUsersCanAccessUsersListPage(): void
$this->assertResponseIsSuccessful();
}

/**
* @covers \App\Controller\UserController::list
*/
public function testAnonymousUserCannotAccessUsersListPage(): void
{
$client = $this->createClient();
Expand All @@ -28,6 +38,9 @@ public function testAnonymousUserCannotAccessUsersListPage(): void
$this->assertResponseStatusCodeSame(302);
}

/**
* @covers \App\Controller\UserController::list
*/
public function testNonAdminUserCannotAccessUsersListPage(): void
{
$client = $this->createClient();
Expand All @@ -37,10 +50,14 @@ public function testNonAdminUserCannotAccessUsersListPage(): void
$this->assertResponseStatusCodeSame(403);
}

/**
* @covers \App\Controller\UserController::create
*/
public function testAdminUserCanCreateNewUser(): void
{
$client = $this->createClient();
$user = $this->createAdminUser("IamAdmin", "mysupersecureadminpwd", "[email protected]");
$userRepository = $this->getEntityManager()->getRepository(User::class);
$user = $userRepository->findOneBy(['username' => 'admin']);
$client->loginUser($user);
$client->request('GET', '/users/create');
$this->markTestIncomplete();
Expand All @@ -51,26 +68,41 @@ public function testAdminUserCanCreateNewUser(): void
$this->assertResponseIsSuccessful();
}

/**
* @covers \App\Controller\UserController::create
*/
public function testNonAdminUserCannotCreateNewUser(): void
{
$this->markTestIncomplete();
}

/**
* @covers \App\Controller\UserController::edit
*/
public function testAdminUserCanEditAnotherUser(): void
{
$this->markTestIncomplete();
}

/**
* @covers \App\Controller\UserController::edit
*/
public function testAdminUserCanPromoteAnotherUser(): void
{
$this->markTestIncomplete();
}

/**
* @covers \App\Controller\UserController::edit
*/
public function testAdminUserCanDemoteAnotherUser(): void
{
$this->markTestIncomplete();
}

/**
* @covers \App\Controller\UserController::edit
*/
public function testNonAdminUserCannotEditAnotherUser(): void
{
$this->markTestIncomplete();
Expand Down
Loading

0 comments on commit dd71fe1

Please sign in to comment.