diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 3969cfc34a2..149048876cb 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -31,9 +31,9 @@ jobs: - name: Global require pdg run: | cd $(composer -n config --global home) - echo "{\"repositories\":[{\"type\":\"vcs\",\"url\":\"https://github.com/JacquesDurand/php-documentation-generator\"}]}" > composer.json + echo "{\"repositories\":[{\"type\":\"vcs\",\"url\":\"https://github.com/php-documentation-generator/php-documentation-generator\"}]}" > composer.json composer global config --no-plugins allow-plugins.symfony/runtime true - composer global require api-platform/pdg:dev-main + composer global require php-documentation-generator/php-documentation-generator:dev-main - name: Cache dependencies uses: actions/cache@v3 with: diff --git a/docs/guide/creating-a-custom-doctrine-filter.php b/docs/guide/creating-a-custom-doctrine-filter.php index 1ad45b9010a..892c3569c25 100644 --- a/docs/guide/creating-a-custom-doctrine-filter.php +++ b/docs/guide/creating-a-custom-doctrine-filter.php @@ -143,17 +143,15 @@ public function down(Schema $schema): void namespace App\Tests { use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use App\Entity\Book; + use PhpDocumentGenerator\Playground\TestGuideTrait; final class BookTest extends ApiTestCase { - protected function setUp(): void - { - static::createKernel()->executeMigrations(); - } + use TestGuideTrait; public function testAsAnonymousICanAccessTheDocumentation(): void { - $resp = static::createClient()->request('GET', '/books.jsonld?regexp_title=^[Found]'); + static::createClient()->request('GET', '/books.jsonld?regexp_title=^[Found]'); $this->assertResponseIsSuccessful(); $this->assertMatchesResourceCollectionJsonSchema(Book::class, '_api_/books{._format}_get_collection'); diff --git a/docs/guide/doctrine-orm-and-mongodb-odm-attribute-filters.php b/docs/guide/doctrine-orm-and-mongodb-odm-attribute-filters.php index 52b4f48ba33..c84f18530dc 100644 --- a/docs/guide/doctrine-orm-and-mongodb-odm-attribute-filters.php +++ b/docs/guide/doctrine-orm-and-mongodb-odm-attribute-filters.php @@ -52,18 +52,39 @@ function request(): Request } } +namespace DoctrineMigrations { + use Doctrine\DBAL\Schema\Schema; + use Doctrine\Migrations\AbstractMigration; + + final class Migration extends AbstractMigration + { + public function up(Schema $schema): void + { + $this->addSql('CREATE TABLE book (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title VARCHAR(255) NOT NULL, author VARCHAR(255) NOT NULL)'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP TABLE book'); + } + } +} + namespace App\Tests { use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use App\Entity\Book; + use PhpDocumentGenerator\Playground\TestGuideTrait; final class BookTest extends ApiTestCase { + use TestGuideTrait; + public function testAsAnonymousICanAccessTheDocumentation(): void { static::createClient()->request('GET', '/books.jsonld'); $this->assertResponseIsSuccessful(); - $this->assertMatchesResourceCollectionJsonSchema(Book::class, '_api_/books.{_format}_get_collection', 'jsonld'); + $this->assertMatchesResourceCollectionJsonSchema(Book::class, '_api_/books{._format}_get_collection', 'jsonld'); $this->assertJsonContains([ 'hydra:search' => [ '@type' => 'hydra:IriTemplate', diff --git a/docs/guide/doctrine-orm-and-mongodb-odm-service-filters.php b/docs/guide/doctrine-orm-and-mongodb-odm-service-filters.php index 6ceed4459da..25e1047c62c 100644 --- a/docs/guide/doctrine-orm-and-mongodb-odm-service-filters.php +++ b/docs/guide/doctrine-orm-and-mongodb-odm-service-filters.php @@ -30,15 +30,19 @@ class Book } } -namespace App\Configurator { +namespace App\DependencyInjection { use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; function configure(ContainerConfigurator $configurator) { $configurator->services() ->set('book.search_filter') ->parent('api_platform.doctrine.orm.search_filter') - ->args(['title' => null]) - ->tag('api_platform.filter'); + ->args([['title' => null]]) + ->tag('api_platform.filter') + ->autowire(false) + ->autoconfigure(false) + ->public(false) + ; } } @@ -51,18 +55,39 @@ function request(): Request } } +namespace DoctrineMigrations { + use Doctrine\DBAL\Schema\Schema; + use Doctrine\Migrations\AbstractMigration; + + final class Migration extends AbstractMigration + { + public function up(Schema $schema): void + { + $this->addSql('CREATE TABLE book (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title VARCHAR(255) NOT NULL)'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP TABLE book'); + } + } +} + namespace App\Tests { use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use App\Entity\Book; + use PhpDocumentGenerator\Playground\TestGuideTrait; final class BookTest extends ApiTestCase { + use TestGuideTrait; + public function testAsAnonymousICanAccessTheDocumentation(): void { static::createClient()->request('GET', '/books.jsonld'); $this->assertResponseIsSuccessful(); - $this->assertMatchesResourceCollectionJsonSchema(Book::class, '_api_/books.{_format}_get_collection', 'jsonld'); + $this->assertMatchesResourceCollectionJsonSchema(Book::class, '_api_/books{._format}_get_collection', 'jsonld'); $this->assertJsonContains([ 'hydra:search' => [ '@type' => 'hydra:IriTemplate', diff --git a/docs/guide/handle-a-pagination-on-a-custom-collection.php b/docs/guide/handle-a-pagination-on-a-custom-collection.php index 50ccd084ee7..ee017437f66 100644 --- a/docs/guide/handle-a-pagination-on-a-custom-collection.php +++ b/docs/guide/handle-a-pagination-on-a-custom-collection.php @@ -148,14 +148,11 @@ public function load(ObjectManager $manager): void namespace App\Tests { use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use App\Entity\Book; + use PhpDocumentGenerator\Playground\TestGuideTrait; final class BookTest extends ApiTestCase { - protected function setUp(): void - { - static::createKernel()->executeMigrations(); - static::createKernel()->loadFixtures(); - } + use TestGuideTrait; public function testTheCustomCollectionIsPaginated(): void { diff --git a/docs/guide/using-doctrine-orm-filters.php b/docs/guide/using-doctrine-orm-filters.php index c11438deba2..e427a45bb83 100644 --- a/docs/guide/using-doctrine-orm-filters.php +++ b/docs/guide/using-doctrine-orm-filters.php @@ -43,7 +43,6 @@ public function getId(): ?int * Each Book is related to a User, supposedly allowed to authenticate. */ #[ApiResource] - #[ApiFilter(UserFilter::class)] #[ORM\Entity] /* * This entity is restricted by current user: only current user books will be shown (cf. UserFilter). @@ -171,6 +170,7 @@ function configure(ContainerConfigurator $configurator) { $services = $configurator->services(); $services->set(UserAwareEventSubscriber::class) ->args([service('doctrine.orm.default_entity_manager')]) + ->tag('kernel.event_subscriber') ; $configurator->extension('doctrine', [ 'orm' => [ @@ -186,24 +186,6 @@ function configure(ContainerConfigurator $configurator) { } } -namespace App\Configurator { - use App\Filter\UserFilter; - use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - - function configure(ContainerConfigurator $configurator) { - $configurator->extension('doctrine', [ - 'orm' => [ - 'filters' => [ - 'user_filter' => [ - 'class' => UserFilter::class, - 'enabled' => true, - ], - ], - ], - ]); - } -} - namespace App\Playground { use Symfony\Component\HttpFoundation\Request; @@ -223,7 +205,7 @@ final class Migration extends AbstractMigration public function up(Schema $schema): void { $this->addSql('CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username VARCHAR(255) NOT NULL)'); - $this->addSql('CREATE TABLE book (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title VARCHAR(255) NOT NULL, user_id INTEGER NOT NULL)'); + $this->addSql('CREATE TABLE book (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title VARCHAR(255) NOT NULL, user_id INTEGER NOT NULL, FOREIGN KEY (user_id) REFERENCES user (id))'); } } } @@ -239,10 +221,19 @@ final class BookFixtures extends Fixture { public function load(ObjectManager $manager): void { - $johnDoe = AnonymousFactory::new(User::class)::createOne(['username' => 'john.doe']); - $janeDoe = AnonymousFactory::new(User::class)::createOne(['username' => 'jane.doe']); - AnonymousFactory::new(Book::class)::createMany(10, ['user' => $johnDoe]); - AnonymousFactory::new(Book::class)::createMany(10, ['user' => $janeDoe]); + $userFactory = AnonymousFactory::new(User::class); + $johnDoe = $userFactory->create(['username' => 'john.doe']); + $janeDoe = $userFactory->create(['username' => 'jane.doe']); + + $bookFactory = AnonymousFactory::new(Book::class); + $bookFactory->many(10)->create([ + 'title' => 'title', + 'user' => $johnDoe + ]); + $bookFactory->many(10)->create([ + 'title' => 'title', + 'user' => $janeDoe + ]); } } } @@ -250,20 +241,18 @@ public function load(ObjectManager $manager): void namespace App\Tests { use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use App\Entity\Book; + use PhpDocumentGenerator\Playground\TestGuideTrait; final class BookTest extends ApiTestCase { - protected function setUp(): void - { - static::createKernel()->executeMigrations(); - } + use TestGuideTrait; public function testAsAnonymousICanAccessTheDocumentation(): void { $response = static::createClient()->request('GET', '/books.jsonld'); $this->assertResponseIsSuccessful(); - $this->assertMatchesResourceCollectionJsonSchema(Book::class, '_api_/books.{_format}_get_collection', 'jsonld'); + $this->assertMatchesResourceCollectionJsonSchema(Book::class, '_api_/books{._format}_get_collection', 'jsonld'); $this->assertNotSame(0, $response->toArray(false)['hydra:totalItems'], 'The collection is empty.'); $this->assertJsonContains([ 'hydra:totalItems' => 10, diff --git a/docs/guide/using-messenger-with-an-input-object.php b/docs/guide/using-messenger-with-an-input-object.php index 02f0da03695..9be62713514 100644 --- a/docs/guide/using-messenger-with-an-input-object.php +++ b/docs/guide/using-messenger-with-an-input-object.php @@ -150,13 +150,11 @@ function request(): Request use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use App\Entity\Book; use Symfony\Component\HttpFoundation\Response; + use PhpDocumentGenerator\Playground\TestGuideTrait; final class BookTest extends ApiTestCase { - protected function setUp(): void - { - static::createKernel()->executeMigrations(); - } + use TestGuideTrait; public function testAsAnonymousICanAccessTheDocumentation(): void {