feat: Ajoute l'attribut Mainframe et ses tests

This commit is contained in:
Serreau Jovann
2025-07-16 12:04:44 +02:00
parent 874d56ef11
commit e90cf52aac
6 changed files with 103 additions and 2 deletions

1
.gitignore vendored
View File

@@ -30,4 +30,5 @@ phpstan.neon
/public/media/cache/
###< liip/imagine-bundle ###
.coverage
coverage/
.phpunit.cache

View File

@@ -20,6 +20,7 @@ services:
# Monte le socket Docker pour permettre l'exécution de commandes docker depuis le conteneur
- /var/run/docker.sock:/var/run/docker.sock
- ./coverage:/opt/phpstorm-coverage
- ./.coverage:/opt/phpstorm-coverage
depends_on:
# S'assure que la base de données et Redis sont démarrés avant PHP
- db

View File

@@ -77,6 +77,7 @@ RUN mkdir -p /opt/phpstorm-coverage && \
# Installer Composer globalement
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN mkdir -p /opt/phpstorm-coverage/ && chmod -R 777 /opt/phpstorm-coverage/
# Créer un utilisateur et un groupe non-root pour l'application
# Utilisation de useradd/groupadd pour les systèmes basés sur Debian/Ubuntu
@@ -85,6 +86,5 @@ RUN groupadd -g $GID appuser && \
# Changer pour l'utilisateur non-root
USER appuser
# Définir le répertoire de travail
WORKDIR /srv/app

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Attribute;
use Attribute;
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::TARGET_PROPERTY)]
class Mainframe
{
/**
* @param bool $index Indique si le contenu est indexable.
* @param bool $sitemap Indique si le contenu doit être inclus dans le sitemap.
* @param string|null $sitemapPage Le nom de la page du sitemap si applicable.
*/
public function __construct(
public bool $index = false,
public bool $sitemap = false,
public ?string $sitemapPage = null
) {
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Controller;
use App\Attribute\Mainframe;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
@@ -10,9 +11,9 @@ class HomeController extends AbstractController
{
#[Route(path: '/',name: 'toot',methods: 'GET')]
#[Mainframe(index: false,sitemap: false,sitemapPage: null)]
public function index(): JsonResponse
{
return$this->json([]);
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace App\Tests\Attribute;
use App\Attribute\Mainframe;
use PHPUnit\Framework\TestCase;
class MainframeTest extends TestCase
{
/**
* Tests the default values of the Mainframe attribute.
*/
public function testDefaultValues(): void
{
$attribute = new Mainframe();
// Assert that default values are as expected
$this->assertFalse($attribute->index);
$this->assertFalse($attribute->sitemap);
$this->assertNull($attribute->sitemapPage);
}
/**
* Tests the Mainframe attribute with custom values.
*/
public function testCustomValues(): void
{
$attribute = new Mainframe(
index: true,
sitemap: true,
sitemapPage: 'about-us'
);
// Assert that custom values are correctly set
$this->assertTrue($attribute->index);
$this->assertTrue($attribute->sitemap);
$this->assertEquals('about-us', $attribute->sitemapPage);
}
/**
* Tests the Mainframe attribute with only 'index' set to true.
*/
public function testIndexOnly(): void
{
$attribute = new Mainframe(index: true);
// Assert 'index' is true, others are default
$this->assertTrue($attribute->index);
$this->assertFalse($attribute->sitemap);
$this->assertNull($attribute->sitemapPage);
}
/**
* Tests the Mainframe attribute with only 'sitemap' set to true.
*/
public function testSitemapOnly(): void
{
$attribute = new Mainframe(sitemap: true);
// Assert 'sitemap' is true, others are default
$this->assertFalse($attribute->index);
$this->assertTrue($attribute->sitemap);
$this->assertNull($attribute->sitemapPage);
}
/**
* Tests the Mainframe attribute with 'sitemapPage' set.
*/
public function testSitemapPageOnly(): void
{
$attribute = new Mainframe(sitemapPage: 'contact');
// Assert 'sitemapPage' is set, others are default
$this->assertFalse($attribute->index);
$this->assertFalse($attribute->sitemap);
$this->assertEquals('contact', $attribute->sitemapPage);
}
}