Skip to content

Commit

Permalink
Updated samuelgfeller/test-traits to v6 [SLE-192]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed Apr 12, 2024
1 parent e1bb6fc commit 648f267
Show file tree
Hide file tree
Showing 39 changed files with 132 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
run: composer update --no-ansi --no-interaction --no-progress

- name: Execute database migrations
run: composer migrate-prod
run: composer migrate:prod

- name: Show test db tables
run: mysql -uroot -proot -D ${{ matrix.test-database }} -e "SHOW TABLES;"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
script: |
cd ${{ secrets.DEMO_PROJECT_ROOT }}
chmod +x vendor/bin/phinx
composer migrate-prod
composer migrate:prod
- name: ♥️ Sync files with care-point
uses: SamKirkland/[email protected]
Expand All @@ -90,4 +90,4 @@ jobs:
script: |
cd ${{ secrets.CARE_POINT_PROJECT_ROOT }}
chmod +x vendor/bin/phinx
composer migrate-prod
composer migrate:prod
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ It showcases the implementation of a simple yet robust
with a variety of backend and
frontend features built using the Slim 4 micro-framework.
The base for this project was the official
[Slim-Skeleton](https://github.com/slimphp/Slim-Skeleton).
[Slim-Skeleton](https://github.com/slimphp/Slim-Skeleton) and the [slim4-skeleton](https://github.com/odan/slim4-skeleton).

This repository can serve as a learning example or be adapted for developing new
applications.
applications.

External library dependencies are [kept to a minimum](https://github.com/samuelgfeller/slim-example-project/wiki/Libraries-and-Framework)
to facilitate maintenance and ensure long-term viability.
Expand All @@ -32,17 +32,18 @@ A detailed [**documentation**](https://github.com/samuelgfeller/slim-example-pro
Please read the [**installation guide**](https://github.com/samuelgfeller/slim-example-project/wiki/Installation-Guide)
to get started.

Stripped down versions of this repository are available as skeleton templates:
[**slim-api-starter**](https://github.com/samuelgfeller/slim-api-starter) (only API) and
[**slim-starter**](https://github.com/samuelgfeller/slim-starter) (with frontend and API endpoint).
Stripped down versions of this repository are available as skeleton
templates.
With frontend [`slim-starter`](https://github.com/samuelgfeller/slim-starter) or just for an API:
[`slim-api-starter`](https://github.com/samuelgfeller/slim-api-starter).

## Features
All the features were developed with an effort to ensure maximum user-friendliness.
The frontend should be intuitive, aesthetically pleasing, minimalistic, and functional.
The backend should be efficient and secure.
The frontend, intuitive, aesthetically pleasing, minimalistic, and functional.
The backend, efficient and secure.

This project is currently designed for non-profit organizations or foundations that require a platform
to manage and maintain a record of communication through notes of people they assist.
to manage and maintain a record of communication through notes of people they help.

**Project components:**

Expand All @@ -56,8 +57,7 @@ to manage and maintain a record of communication through notes of people they as
protection against rapid fire and distributed brute force attacks (time throttling and captcha)
* [Localization](https://github.com/samuelgfeller/slim-example-project/wiki/Translations) - English, German and French
* [Validation](https://github.com/samuelgfeller/slim-example-project/wiki/Validation)
* [Template rendering](https://github.com/samuelgfeller/slim-example-project/wiki/Template-rendering) with native PHP syntax
* [Editing values using `contenteditable`](https://github.com/samuelgfeller/slim-example-project/wiki/JavaScript-Frontend#contenteditable-fields)
* [Template rendering](https://github.com/samuelgfeller/slim-example-project/wiki/Template-rendering) with native PHP syntax (easily interchangeable with twig)
* [Dark theme](https://github.com/samuelgfeller/slim-example-project/wiki/Dark-Theme)
* [Advanced error handling](https://github.com/samuelgfeller/slim-example-project/wiki/Error-Handling)
* [Integration & unit testing](https://github.com/samuelgfeller/slim-example-project/wiki/Writing-Tests)
Expand All @@ -66,7 +66,8 @@ to manage and maintain a record of communication through notes of people they as
* [Query Builder](https://github.com/samuelgfeller/slim-example-project/wiki/Repository-and-Query-Builder)
* [Logging](https://github.com/samuelgfeller/slim-example-project/wiki/Logging)
* [Mailing](https://github.com/samuelgfeller/slim-example-project/wiki/Mailing)
* Simple [console commands](https://github.com/samuelgfeller/slim-example-project/wiki/Console-Commands)
* [Simple console commands](https://github.com/samuelgfeller/slim-example-project/wiki/Console-Commands)
* [Scrutinizer](https://github.com/samuelgfeller/slim-example-project/wiki/How-to-set-up-Scrutinizer)
* [GitHub Actions](https://github.com/samuelgfeller/slim-example-project/wiki/GitHub-Actions)

**Functionalities demonstrating real-world features:**
Expand All @@ -86,9 +87,9 @@ to manage and maintain a record of communication through notes of people they as
<summary><b>Click to see demo</b></summary>

Link: [Login](https://demo.slim-example-project.samuel-gfeller.ch)
Usernames: `admin@user.com` | `[email protected]` | `[email protected]` | `newcomer@user.com`
Username: `[email protected]`
Password: `12345678`
The database is reset every hour.
The database is reset regularly.

</details>

Expand Down Expand Up @@ -121,7 +122,7 @@ Of course, there are big frameworks that have their own well-established set of
implementations of features.

However, I find them often
too complex, where the code makes too much "behind the scenes" and lots of dependencies,
too complex, where the code makes too much "behind the scenes" and with lots of dependencies,
which can lead to time-consuming refactoring on version changes.
I also dislike having to follow the propitiatory rules of a framework and
much prefer the freedom of a micro-framework and carefully
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"selective/basepath": "^2.0",
"symfony/mailer": "^7",
"odan/session": "^6",
"nyholm/psr7": "^1.5",
"nyholm/psr7-server": "^1.1",
"fig/http-message-util": "^1.1",
"nyholm/psr7": "^1",
"nyholm/psr7-server": "^1",
"fig/http-message-util": "^1",
"php": "^8.2",
"ext-pdo": "*",
"ext-json": "*",
Expand All @@ -29,7 +29,7 @@
"jetbrains/phpstorm-attributes": "^1.0",
"friendsofphp/php-cs-fixer": "^3",
"odan/phinx-migrations-generator": "^6",
"samuelgfeller/test-traits": "^5"
"samuelgfeller/test-traits": "^6"
},
"autoload": {
"psr-4": {
Expand All @@ -54,9 +54,9 @@
"phinx-migrations generate --overwrite -c config/env/env.phinx.php --ansi",
"@schema:generate"
],
"migrate-prod": "vendor/bin/phinx migrate -c config/env/env.phinx.php --ansi -vvv",
"migrate:prod": "vendor/bin/phinx migrate -c config/env/env.phinx.php --ansi -vvv",
"migrate": [
"@migrate-prod",
"@migrate:prod",
"@schema:generate"
],
"schema:generate": [
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Responder/RedirectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function redirectToUrl(
* @param ResponseInterface $response The response
* @param string $routeName The redirect route name
* @param array $data Named argument replacement data
* @param array<string, int|string> $queryParams Optional query string parameters
* @param array<string, string> $queryParams Optional query string parameters
*
* @return ResponseInterface The response
*/
Expand Down
4 changes: 1 addition & 3 deletions tests/Fixture/ClientFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace App\Test\Fixture;

use TestTraits\Interface\FixtureInterface;

/**
* Client values that can be inserted into the database.
*/
class ClientFixture implements FixtureInterface
class ClientFixture
{
// Table name
public string $table = 'client';
Expand Down
6 changes: 2 additions & 4 deletions tests/Fixture/ClientStatusFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

namespace App\Test\Fixture;

use TestTraits\Interface\FixtureInterface;

/**
* Client status values that can be inserted into the database
* No fixture has to be inserted first.
*/
class ClientStatusFixture implements FixtureInterface
class ClientStatusFixture
{
// Table name
public string $table = 'client_status';

// Database records in 2d array
public array $records = [
// First record must have deleted_at => null
[
'id' => 1,
'name' => 'Action pending',
// The first record must have deleted_at => null
'deleted_at' => null,
],
[
Expand Down
6 changes: 2 additions & 4 deletions tests/Fixture/NoteFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

namespace App\Test\Fixture;

use TestTraits\Interface\FixtureInterface;

/**
* Note values that can be inserted into the database.
*/
class NoteFixture implements FixtureInterface
class NoteFixture
{
// Table name
public string $table = 'note';

// Database records in 2d array
public array $records = [
// First record must have deleted_at => null
[
'id' => 1,
'user_id' => 10,
Expand All @@ -24,6 +21,7 @@ class NoteFixture implements FixtureInterface
'hidden' => null,
'updated_at' => '2024-01-01 00:00:01',
'created_at' => '2024-01-01 00:00:01',
// The first record must have deleted_at => null
'deleted_at' => null,
],
// Note id 2: is not main note and linked to user 10 and client 1
Expand Down
4 changes: 1 addition & 3 deletions tests/Fixture/UserActivityFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace App\Test\Fixture;

use TestTraits\Interface\FixtureInterface;

class UserActivityFixture implements FixtureInterface
class UserActivityFixture
{
// Table name
public string $table = 'user_activity';
Expand Down
4 changes: 1 addition & 3 deletions tests/Fixture/UserFilterSettingFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace App\Test\Fixture;

use TestTraits\Interface\FixtureInterface;

class UserFilterSettingFixture implements FixtureInterface
class UserFilterSettingFixture
{
// Table name
public string $table = 'user_filter_setting';
Expand Down
4 changes: 1 addition & 3 deletions tests/Fixture/UserFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace App\Test\Fixture;

use TestTraits\Interface\FixtureInterface;

/**
* User values that can be inserted into the database.
* ! All user roles are inserted automatically for each test (in AppTestTrait).
*/
class UserFixture implements FixtureInterface
class UserFixture
{
// Table name
public string $table = 'user';
Expand Down
4 changes: 1 addition & 3 deletions tests/Fixture/UserRoleFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace App\Test\Fixture;

use TestTraits\Interface\FixtureInterface;

class UserRoleFixture implements FixtureInterface
class UserRoleFixture
{
// Table name
public string $table = 'user_role';
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/Authentication/AccountUnlockActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testAccountUnlockAction(UserVerificationData $verification, stri
{
// Insert locked user
$userRow = $this->insertFixture(
new UserFixture(),
UserFixture::class,
['status' => UserStatus::Locked->value, 'id' => $verification->userId],
);

Expand Down Expand Up @@ -87,7 +87,7 @@ public function testAccountUnlockActionInvalidExpiredToken(
): void {
// Insert locked user
$userRow = $this->insertFixture(
new UserFixture(),
UserFixture::class,
['status' => UserStatus::Locked->value, 'id' => $verification->userId],
);

Expand Down Expand Up @@ -133,7 +133,7 @@ public function testAccountUnlockActionAlreadyUnlocked(
): void {
// Insert locked user
$userRow = $this->insertFixture(
new UserFixture(),
UserFixture::class,
['status' => UserStatus::Active->value, 'id' => $verification->userId],
);

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Authentication/LoginPageActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testLoginPageAction(): void
public function testLoginPageActionAlreadyLoggedIn(): void
{
// Insert authenticated user
$userId = $this->insertFixture(new UserFixture())['id'];
$userId = $this->insertFixture(UserFixture::class)['id'];
// Simulate logged-in user by setting the user_id session variable
$this->container->get(SessionInterface::class)->set('user_id', $userId);
// Prepare route to test the case when the user clicks on a login link with a redirect route
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Authentication/LoginSecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testLoginThrottlingWrongCredentials(): void
$correctLoginRequestBody = ['email' => $email, 'password' => $password];

// Insert user fixture
$user = $this->insertFixture(new UserFixture(), [
$user = $this->insertFixture(UserFixture::class, [
'email' => $email,
'password_hash' => password_hash($password, PASSWORD_DEFAULT),
], );
Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/Authentication/LoginSubmitActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testLoginSubmitAction(): void
{
$loginValues = ['password' => '12345678', 'email' => '[email protected]'];
$userRow = $this->insertFixture(
new UserFixture(),
UserFixture::class,
[
'password_hash' => password_hash($loginValues['password'], PASSWORD_DEFAULT),
'email' => $loginValues['email'],
Expand Down Expand Up @@ -79,7 +79,7 @@ public function testLoginSubmitAction(): void
*/
public function testLoginSubmitActionWrongPassword(): void
{
$this->insertFixture(new UserFixture());
$this->insertFixture(UserFixture::class);

$invalidCredentials = [
'email' => '[email protected]',
Expand Down Expand Up @@ -114,7 +114,7 @@ public function testLoginSubmitActionWrongPassword(): void
#[DataProviderExternal(\App\Test\Provider\Authentication\AuthenticationProvider::class, 'invalidLoginCredentialsProvider')]
public function testLoginSubmitActionInvalidValues(array $invalidLoginValues, string $errorMessage): void
{
$this->insertFixture(new UserFixture());
$this->insertFixture(UserFixture::class);

// Create request
$request = $this->createFormRequest('POST', $this->urlFor('login-submit'), $invalidLoginValues);
Expand Down Expand Up @@ -148,7 +148,7 @@ public function testLoginSubmitActionNotActiveAccount(UserStatus $status, string
{
$loginValues = ['password' => '12345678', 'email' => '[email protected]'];
$userRow = $this->insertFixture(
new UserFixture(),
UserFixture::class,
[
'password_hash' => password_hash($loginValues['password'], PASSWORD_DEFAULT),
'email' => $loginValues['email'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PasswordForgottenEmailSubmitActionTest extends TestCase
public function testPasswordForgottenEmailSubmit(): void
{
// Insert user
$userRow = $this->insertFixture(new UserFixture());
$userRow = $this->insertFixture(UserFixture::class);
$userId = $userRow['id'];
$email = $userRow['email'];

Expand Down Expand Up @@ -134,7 +134,7 @@ public function testPasswordForgottenEmailSubmitUserNotExisting(): void
public function testPasswordForgottenEmailSubmitInvalidData(): void
{
// Insert user
$userRow = $this->insertFixture(new UserFixture());
$userRow = $this->insertFixture(UserFixture::class);

// Simulate logged-in user with id 2
$this->container->get(SessionInterface::class)->set('user_id', $userRow['id']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testResetPasswordSubmit(UserVerificationData $verification, stri
{
$newPassword = 'new password';
// Insert user
$userRow = $this->insertFixture(new UserFixture(), ['id' => $verification->userId]);
$userRow = $this->insertFixture(UserFixture::class, ['id' => $verification->userId]);

$this->insertFixtureRow('user_verification', $verification->toArrayForDatabase());

Expand Down Expand Up @@ -85,7 +85,7 @@ public function testResetPasswordSubmitInvalidToken(
): void {
// User needed to insert verification
$userRow = $this->insertFixture(
new UserFixture(),
UserFixture::class,
['id' => $verification->userId, 'status' => UserStatus::Unverified->value],
);

Expand Down Expand Up @@ -140,7 +140,7 @@ public function testResetPasswordSubmitInvalidData(
// Invalid new password
$newPassword = '1';
// Insert user id 2 role: user
$userRow = $this->insertFixture(new UserFixture(), ['id' => $verification->userId]);
$userRow = $this->insertFixture(UserFixture::class, ['id' => $verification->userId]);

$this->insertFixtureRow('user_verification', $verification->toArrayForDatabase());

Expand Down
Loading

0 comments on commit 648f267

Please sign in to comment.