From dc683362d76d0721b476848e9310d05d21cc9aae Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sat, 1 Apr 2023 21:23:30 +0300 Subject: [PATCH] Ported DataFixtures. composer require doctrine-fixtures-bundle. --- composer.json | 1 + composer.lock | 167 +++++++++++++++++- config/bundles.php | 1 + .../DataFixtures}/LoadCommentsData.php | 24 +-- .../ORM => src/DataFixtures}/LoadPostData.php | 19 +- .../DataFixtures}/LoadSubscribersData.php | 15 +- .../ORM => src/DataFixtures}/LoadUserData.php | 13 +- symfony.lock | 12 ++ 8 files changed, 216 insertions(+), 36 deletions(-) rename {old/src/PointToolsBundle/DataFixtures/ORM => src/DataFixtures}/LoadCommentsData.php (68%) rename {old/src/PointToolsBundle/DataFixtures/ORM => src/DataFixtures}/LoadPostData.php (84%) rename {old/src/PointToolsBundle/DataFixtures/ORM => src/DataFixtures}/LoadSubscribersData.php (79%) rename {old/src/PointToolsBundle/DataFixtures/ORM => src/DataFixtures}/LoadUserData.php (86%) diff --git a/composer.json b/composer.json index 8a1cca6..9272275 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "ext-iconv": "*", "doctrine/annotations": "^2.0", "doctrine/doctrine-bundle": "^2.8", + "doctrine/doctrine-fixtures-bundle": "^3.4", "doctrine/doctrine-migrations-bundle": "^3.2", "doctrine/orm": "^2.14", "jms/serializer-bundle": "^5.2", diff --git a/composer.lock b/composer.lock index 07b2cf1..fe4d814 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "adf20c9a601a7f685ece9da4a4ac9e47", + "content-hash": "93a3119667f6f43c8cf9d580299de8c8", "packages": [ { "name": "doctrine/annotations", @@ -352,6 +352,88 @@ ], "time": "2022-10-09T11:47:59+00:00" }, + { + "name": "doctrine/data-fixtures", + "version": "1.6.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/data-fixtures.git", + "reference": "c27821d038e64f1bfc852a94064d65d2a75ad01f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/c27821d038e64f1bfc852a94064d65d2a75ad01f", + "reference": "c27821d038e64f1bfc852a94064d65d2a75ad01f", + "shasum": "" + }, + "require": { + "doctrine/persistence": "^1.3.3|^2.0|^3.0", + "php": "^7.2 || ^8.0" + }, + "conflict": { + "doctrine/dbal": "<2.13", + "doctrine/orm": "<2.12", + "doctrine/phpcr-odm": "<1.3.0" + }, + "require-dev": { + "doctrine/coding-standard": "^10.0", + "doctrine/dbal": "^2.13 || ^3.0", + "doctrine/deprecations": "^1.0", + "doctrine/mongodb-odm": "^1.3.0 || ^2.0.0", + "doctrine/orm": "^2.12", + "ext-sqlite3": "*", + "phpstan/phpstan": "^1.5", + "phpunit/phpunit": "^8.5 || ^9.5", + "symfony/cache": "^5.0 || ^6.0", + "vimeo/psalm": "^4.10" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "For using MongoDB ODM 1.3 with PHP 7 (deprecated)", + "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", + "doctrine/orm": "For loading ORM fixtures", + "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Common\\DataFixtures\\": "lib/Doctrine/Common/DataFixtures" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Data Fixtures for all Doctrine Object Managers", + "homepage": "https://www.doctrine-project.org", + "keywords": [ + "database" + ], + "support": { + "issues": "https://github.com/doctrine/data-fixtures/issues", + "source": "https://github.com/doctrine/data-fixtures/tree/1.6.3" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdata-fixtures", + "type": "tidelift" + } + ], + "time": "2023-01-07T15:10:22+00:00" + }, { "name": "doctrine/dbal", "version": "3.6.1", @@ -622,6 +704,89 @@ ], "time": "2023-02-03T09:32:42+00:00" }, + { + "name": "doctrine/doctrine-fixtures-bundle", + "version": "3.4.2", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineFixturesBundle.git", + "reference": "601988c5b46dbd20a0f886f967210aba378a6fd5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/601988c5b46dbd20a0f886f967210aba378a6fd5", + "reference": "601988c5b46dbd20a0f886f967210aba378a6fd5", + "shasum": "" + }, + "require": { + "doctrine/data-fixtures": "^1.3", + "doctrine/doctrine-bundle": "^1.11|^2.0", + "doctrine/orm": "^2.6.0", + "doctrine/persistence": "^1.3.7|^2.0|^3.0", + "php": "^7.1 || ^8.0", + "symfony/config": "^3.4|^4.3|^5.0|^6.0", + "symfony/console": "^3.4|^4.3|^5.0|^6.0", + "symfony/dependency-injection": "^3.4.47|^4.3|^5.0|^6.0", + "symfony/doctrine-bridge": "^3.4|^4.1|^5.0|^6.0", + "symfony/http-kernel": "^3.4|^4.3|^5.0|^6.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9", + "phpstan/phpstan": "^1.4.10", + "phpunit/phpunit": "^7.5.20 || ^8.5.26 || ^9.5.20", + "symfony/phpunit-bridge": "^6.0.8", + "vimeo/psalm": "^4.22" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "Doctrine\\Bundle\\FixturesBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Doctrine Project", + "homepage": "https://www.doctrine-project.org" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DoctrineFixturesBundle", + "homepage": "https://www.doctrine-project.org", + "keywords": [ + "Fixture", + "persistence" + ], + "support": { + "issues": "https://github.com/doctrine/DoctrineFixturesBundle/issues", + "source": "https://github.com/doctrine/DoctrineFixturesBundle/tree/3.4.2" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdoctrine-fixtures-bundle", + "type": "tidelift" + } + ], + "time": "2022-04-28T17:58:29+00:00" + }, { "name": "doctrine/doctrine-migrations-bundle", "version": "3.2.2", diff --git a/config/bundles.php b/config/bundles.php index 7f4b24c..6bc19b2 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -15,4 +15,5 @@ return [ Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => ['all' => true], + Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], ]; diff --git a/old/src/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php b/src/DataFixtures/LoadCommentsData.php similarity index 68% rename from old/src/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php rename to src/DataFixtures/LoadCommentsData.php index 521a76a..c3a1650 100644 --- a/old/src/PointToolsBundle/DataFixtures/ORM/LoadCommentsData.php +++ b/src/DataFixtures/LoadCommentsData.php @@ -1,17 +1,17 @@ getReference('test_post_longpost'); @@ -30,7 +30,7 @@ class LoadCommentsData extends AbstractFixture implements OrderedFixtureInterfac foreach (range(1, 10000) as $num) { $comment = (new Comment()) ->setNumber($num) - ->setDeleted(mt_rand(0, 15) ? false : true) + ->setDeleted(\random_int(0, 15) ? false : true) ->setCreatedAt(new \DateTime()) ->setAuthor($users[array_rand($users)]) ->setRec(false) @@ -42,8 +42,8 @@ class LoadCommentsData extends AbstractFixture implements OrderedFixtureInterfac ) ; - if (count($comments) > 0 && mt_rand(0, 1)) { - $comment->setParent($comments[mt_rand(0, count($comments) - 1)]); + if (count($comments) > 0 && \random_int(0, 1)) { + $comment->setParent($comments[\random_int(0, count($comments) - 1)]); } $post->addComment($comment); @@ -59,4 +59,4 @@ class LoadCommentsData extends AbstractFixture implements OrderedFixtureInterfac { return 3; } -} \ No newline at end of file +} diff --git a/old/src/PointToolsBundle/DataFixtures/ORM/LoadPostData.php b/src/DataFixtures/LoadPostData.php similarity index 84% rename from old/src/PointToolsBundle/DataFixtures/ORM/LoadPostData.php rename to src/DataFixtures/LoadPostData.php index 87ed72c..3e81241 100644 --- a/old/src/PointToolsBundle/DataFixtures/ORM/LoadPostData.php +++ b/src/DataFixtures/LoadPostData.php @@ -1,16 +1,17 @@