Files
archived-mongodb-maker-bundle/tests/Maker/MakeDocumentTest.php
Jérôme Tamarelle e59afbe9e5 PHPORM-439 Initialize the make:document command (#3)
* Setup test

* Draft implementation of make:document command

* doctrine/mongodb-odm-bundle has now an official recipe

* Add tests to MongoDBHelper

* Update attribute namespace for ODM v2.16

* Fix tests

* Require version 1.x from symfony/maker-bundle, as it exist in my fork and in the symfony repo

* Add symfony/phpunit-bridge because it's symlinked in test environment

'https://github.com/symfony/maker-bundle/pull/480#pullrequestreview-304282682'

* Add mongodb-atlas-local container to tests

* Add PHP 8.5 polyfill
2026-01-30 12:01:03 +01:00

82 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MongoDBMakerBundle\Tests\Maker;
use Doctrine\Bundle\MongoDBMakerBundle\Maker\MakeDocument;
use Generator;
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
use Symfony\Bundle\MakerBundle\Test\MakerTestDetails;
use Symfony\Bundle\MakerBundle\Test\MakerTestRunner;
use Symfony\Component\HttpKernel\KernelInterface;
use function getenv;
class MakeDocumentTest extends MakerTestCase
{
protected function getMakerClass(): string
{
return MakeDocument::class;
}
private static function createMakeDocumentTest(bool $withDatabase = true): MakerTestDetails
{
return self::buildMakerTest()
->preRun(static function (MakerTestRunner $runner) use ($withDatabase): void {
if (! $withDatabase) {
return;
}
$runner->replaceInFile(
'.env',
'mongodb://localhost:27017',
(string) getenv('MONGODB_URI'),
);
});
}
protected function createKernel(): KernelInterface
{
return new MakerTestKernel('dev', true);
}
public static function getTestDetails(): Generator
{
yield 'it_creates_a_new_class_basic' => [
self::createMakeDocumentTest()
->run(static function (MakerTestRunner $runner): void {
$runner->runMaker([
// document class name
'User',
// no additional fields
'',
]);
self::runDocumentTest($runner);
}),
];
}
/** @param array<string, mixed> $data */
private static function runDocumentTest(MakerTestRunner $runner, array $data = []): void
{
$runner->renderTemplateFile(
'make-document/GeneratedDocumentTest.php.twig',
'tests/GeneratedDocumentTest.php',
['data' => $data],
);
$runner->runTests();
}
}