Sortie du snippet Doctrine "Récupérer la liste des champs et des associations d'une entité Doctrine "

Environement :

  • Strangebuzz Snippet VM : 2.2.1

Sortie du code exécuté :

array(17) {
  [0]=>
  string(2) "id"
  [1]=>
  string(6) "active"
  [2]=>
  string(4) "name"
  [3]=>
  string(4) "slug"
  [4]=>
  string(16) "mainEntityOfPage"
  [5]=>
  string(13) "datePublished"
  [6]=>
  string(12) "dateModified"
  [7]=>
  string(10) "inLanguage"
  [8]=>
  string(7) "keyword"
  [9]=>
  string(8) "headline"
  [10]=>
  string(11) "description"
  [11]=>
  string(6) "author"
  [12]=>
  string(5) "about"
  [13]=>
  string(5) "image"
  [14]=>
  string(12) "timeRequired"
  [15]=>
  string(9) "createdAt"
  [16]=>
  string(9) "updatedAt"
}
array(5) {
  [0]=>
  string(4) "type"
  [1]=>
  string(15) "previousArticle"
  [2]=>
  string(11) "nextArticle"
  [3]=>
  string(9) "publisher"
  [4]=>
  string(4) "tags"
}

 Retour au code  ≪ this.showUnitTest ? this.trans.hide_unit_test : this.trans.show_unit_test ≫  Plus sur Stackoverflow   Lire la doc  Snippet aléatoire

<?php declare(strict_types=1);

namespace App\Tests\Controller\Snippets;

use App\Entity\Article;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
 * @covers Snippet107Trait
 */
final class Snippet107Test extends KernelTestCase
{
    private EntityManagerInterface $em;

    protected function setUp(): void
    {
        self::bootKernel();
        $this->em = self::$container->get(EntityManagerInterface::class);
    }

    /**
     * @covers Snippet107Trait::snippet107
     */
    public function testSnippet107(): void
    {
        $articleMetaData = $this->em->getClassMetadata(Article::class);
        $properties = $articleMetaData->getFieldNames();
        $associations = $articleMetaData->getAssociationNames();
        self::assertIsArray($properties);
        self::assertIsArray($associations);
        self::assertCount(17, $properties);
        self::assertCount(5, $associations);
    }
}