feat: Ajoute l'attribut Mainframe et ses tests
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -30,4 +30,5 @@ phpstan.neon
|
|||||||
/public/media/cache/
|
/public/media/cache/
|
||||||
###< liip/imagine-bundle ###
|
###< liip/imagine-bundle ###
|
||||||
.coverage
|
.coverage
|
||||||
|
coverage/
|
||||||
.phpunit.cache
|
.phpunit.cache
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ services:
|
|||||||
# Monte le socket Docker pour permettre l'exécution de commandes docker depuis le conteneur
|
# Monte le socket Docker pour permettre l'exécution de commandes docker depuis le conteneur
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
- ./coverage:/opt/phpstorm-coverage
|
- ./coverage:/opt/phpstorm-coverage
|
||||||
|
- ./.coverage:/opt/phpstorm-coverage
|
||||||
depends_on:
|
depends_on:
|
||||||
# S'assure que la base de données et Redis sont démarrés avant PHP
|
# S'assure que la base de données et Redis sont démarrés avant PHP
|
||||||
- db
|
- db
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ RUN mkdir -p /opt/phpstorm-coverage && \
|
|||||||
|
|
||||||
# Installer Composer globalement
|
# Installer Composer globalement
|
||||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
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
|
# 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
|
# 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
|
# Changer pour l'utilisateur non-root
|
||||||
USER appuser
|
USER appuser
|
||||||
|
|
||||||
# Définir le répertoire de travail
|
# Définir le répertoire de travail
|
||||||
WORKDIR /srv/app
|
WORKDIR /srv/app
|
||||||
|
|||||||
21
src/Attribute/Mainframe.php
Normal file
21
src/Attribute/Mainframe.php
Normal 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
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Attribute\Mainframe;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
@@ -10,9 +11,9 @@ class HomeController extends AbstractController
|
|||||||
{
|
{
|
||||||
|
|
||||||
#[Route(path: '/',name: 'toot',methods: 'GET')]
|
#[Route(path: '/',name: 'toot',methods: 'GET')]
|
||||||
|
#[Mainframe(index: false,sitemap: false,sitemapPage: null)]
|
||||||
public function index(): JsonResponse
|
public function index(): JsonResponse
|
||||||
{
|
{
|
||||||
return$this->json([]);
|
return$this->json([]);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
77
tests/Attribute/MainframeTest.php
Normal file
77
tests/Attribute/MainframeTest.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user