From cd5cefe084655ae6bc53bcdf7ea8187e86d7e95c Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Fri, 19 Mar 2021 18:05:43 -0400 Subject: [PATCH 1/8] [minor] use SHELL_VERBOSITY to hide logs during tests --- phpunit-dama-doctrine.xml.dist | 1 + phpunit.xml.dist | 1 + tests/Fixtures/Kernel.php | 3 --- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/phpunit-dama-doctrine.xml.dist b/phpunit-dama-doctrine.xml.dist index eec06eff3..73923e9cc 100644 --- a/phpunit-dama-doctrine.xml.dist +++ b/phpunit-dama-doctrine.xml.dist @@ -13,6 +13,7 @@ + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1ede534e4..29d74e997 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,6 +12,7 @@ + diff --git a/tests/Fixtures/Kernel.php b/tests/Fixtures/Kernel.php index 95a3f2820..80cde8418 100644 --- a/tests/Fixtures/Kernel.php +++ b/tests/Fixtures/Kernel.php @@ -4,7 +4,6 @@ use DAMA\DoctrineTestBundle\DAMADoctrineTestBundle; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; -use Psr\Log\NullLogger; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Bundle\MakerBundle\MakerBundle; @@ -41,8 +40,6 @@ public function registerBundles(): iterable protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void { - $c->register('logger', NullLogger::class); - $c->register(Service::class); $c->register(ServiceStory::class) ->setAutoconfigured(true) From 4dc13e646327a340443912f7cfc9d3818997aa7b Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Fri, 19 Mar 2021 18:17:41 -0400 Subject: [PATCH 2/8] [minor] adjust codecov threshold --- .codecov.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index f3cc1cce6..925641684 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,8 +1,12 @@ coverage: status: project: - default: - target: auto - threshold: 1% + default: + target: auto + threshold: 1% + patch: + default: + target: auto + threshold: 50% comment: false From aa6b32a266fcb432a29d70841d2a183bcc5c21f2 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 30 Mar 2021 11:43:30 -0400 Subject: [PATCH 3/8] [minor] lock php-cs-fixer version in ci (bug in latest release) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 184131fa2..4c8651af8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -266,7 +266,7 @@ jobs: with: php-version: 7.4 coverage: none - tools: php-cs-fixer + tools: php-cs-fixer:2.18.3 - name: Check CS run: php-cs-fixer fix --dry-run --diff --diff-format=udiff From 463d32a44b6b057f624d83b53b90692990dd3f17 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 30 Mar 2021 11:48:04 -0400 Subject: [PATCH 4/8] [minor] fix faker deprecations --- README.md | 14 +++++++------- tests/Fixtures/Factories/CategoryFactory.php | 2 +- tests/Fixtures/Factories/CommentFactory.php | 4 ++-- tests/Fixtures/Factories/PostFactory.php | 6 +++--- tests/Fixtures/Factories/TagFactory.php | 2 +- tests/Fixtures/Factories/UserFactory.php | 2 +- tests/Unit/FunctionsTest.php | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 57b4d29c5..13743a0cf 100644 --- a/README.md +++ b/README.md @@ -252,8 +252,8 @@ protected function getDefaults(): array return [ // Symfony's property-access component is used to populate the properties // this means that setTitle() will be called or you can have a $title constructor argument - 'title' => self::faker()->unique()->sentence, - 'body' => self::faker()->sentence, + 'title' => self::faker()->unique()->sentence(), + 'body' => self::faker()->sentence(), ]; } ``` @@ -339,7 +339,7 @@ final class PostFactory extends ModelFactory public function published(): self { // call setPublishedAt() and pass a random DateTime - return $this->addState(['published_at' => self::faker()->dateTime]); + return $this->addState(['published_at' => self::faker()->dateTime()]); } public function unpublished(): self @@ -402,7 +402,7 @@ $posts = PostFactory::new(['title' => 'Post A']) // Proxies are automatically converted to their wrapped object 'category' => CategoryFactory::createOne(), ]) - ->withAttributes(function() { return ['createdAt' => faker()->dateTime]; }) // see faker section below + ->withAttributes(function() { return ['createdAt' => faker()->dateTime()]; }) // see faker section below // create "2" Post's ->many(2)->create(['title' => 'Different Title']) @@ -430,10 +430,10 @@ random data for your factories: use Zenstruck\Foundry\Factory; use function Zenstruck\Foundry\faker; -Factory::faker()->name; // random name +Factory::faker()->name(); // random name // alternatively, use the helper function -faker()->email; // random email +faker()->email(); // random email ``` **NOTE**: You can register your own `Faker\Generator`: @@ -753,7 +753,7 @@ final class UserFactory extends ModelFactory protected function getDefaults(): array { return [ - 'email' => self::faker()->unique()->safeEmail, + 'email' => self::faker()->unique()->safeEmail(), 'password' => '1234', ]; } diff --git a/tests/Fixtures/Factories/CategoryFactory.php b/tests/Fixtures/Factories/CategoryFactory.php index 976252bc6..63ecbbba9 100644 --- a/tests/Fixtures/Factories/CategoryFactory.php +++ b/tests/Fixtures/Factories/CategoryFactory.php @@ -17,6 +17,6 @@ protected static function getClass(): string protected function getDefaults(): array { - return ['name' => self::faker()->sentence]; + return ['name' => self::faker()->sentence()]; } } diff --git a/tests/Fixtures/Factories/CommentFactory.php b/tests/Fixtures/Factories/CommentFactory.php index fe327e822..46378070c 100644 --- a/tests/Fixtures/Factories/CommentFactory.php +++ b/tests/Fixtures/Factories/CommentFactory.php @@ -11,8 +11,8 @@ protected function getDefaults(): array { return [ 'user' => UserFactory::new(), - 'body' => self::faker()->sentence, - 'created_at' => self::faker()->dateTime, + 'body' => self::faker()->sentence(), + 'created_at' => self::faker()->dateTime(), 'post' => PostFactory::new(), ]; } diff --git a/tests/Fixtures/Factories/PostFactory.php b/tests/Fixtures/Factories/PostFactory.php index 7bae34d40..df5579fe3 100644 --- a/tests/Fixtures/Factories/PostFactory.php +++ b/tests/Fixtures/Factories/PostFactory.php @@ -13,7 +13,7 @@ class PostFactory extends ModelFactory public function published(): self { return $this->addState(function() { - return ['published_at' => self::faker()->dateTime]; + return ['published_at' => self::faker()->dateTime()]; }); } @@ -25,8 +25,8 @@ protected static function getClass(): string protected function getDefaults(): array { return [ - 'title' => self::faker()->sentence, - 'body' => self::faker()->sentence, + 'title' => self::faker()->sentence(), + 'body' => self::faker()->sentence(), ]; } } diff --git a/tests/Fixtures/Factories/TagFactory.php b/tests/Fixtures/Factories/TagFactory.php index 49faa5bb1..38e138218 100644 --- a/tests/Fixtures/Factories/TagFactory.php +++ b/tests/Fixtures/Factories/TagFactory.php @@ -17,6 +17,6 @@ protected static function getClass(): string protected function getDefaults(): array { - return ['name' => self::faker()->sentence]; + return ['name' => self::faker()->sentence()]; } } diff --git a/tests/Fixtures/Factories/UserFactory.php b/tests/Fixtures/Factories/UserFactory.php index 3a50f5f31..2bf8881c1 100644 --- a/tests/Fixtures/Factories/UserFactory.php +++ b/tests/Fixtures/Factories/UserFactory.php @@ -10,7 +10,7 @@ final class UserFactory extends ModelFactory protected function getDefaults(): array { return [ - 'name' => self::faker()->name, + 'name' => self::faker()->name(), ]; } diff --git a/tests/Unit/FunctionsTest.php b/tests/Unit/FunctionsTest.php index fef5083c9..f2a31d338 100644 --- a/tests/Unit/FunctionsTest.php +++ b/tests/Unit/FunctionsTest.php @@ -31,7 +31,7 @@ final class FunctionsTest extends TestCase */ public function faker(): void { - $this->assertIsString(faker()->name); + $this->assertIsString(faker()->name()); } /** From 69fe2a6be349d4c645f2ed595bc7125731f4e581 Mon Sep 17 00:00:00 2001 From: AntoineRoue <64271860+AntoineRoue@users.noreply.github.com> Date: Tue, 30 Mar 2021 21:37:58 +0200 Subject: [PATCH 5/8] [doc] fix typo (#146) The method beforePersist from Factory class does not exist --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 13743a0cf..ea043ca91 100644 --- a/README.md +++ b/README.md @@ -494,7 +494,7 @@ You can also add hooks directly in your model factory class: protected function initialize(): self { return $this - ->beforePersist(function() {}) + ->afterPersist(function() {}) ; } ``` From 8466067d5fa13f56177ee0994ffa6245af1fcead Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Sun, 11 Apr 2021 20:05:34 +0200 Subject: [PATCH 6/8] [doc] fix small typo in docs (#147) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ea043ca91..895174c8f 100644 --- a/README.md +++ b/README.md @@ -733,7 +733,7 @@ common use-case: encoding a password with the `UserPasswordEncoderInterface` ser ```php // src/Factory/UserFactory.php -namespace App\Story; +namespace App\Factory; use App\Entity\User; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; From e800c835b4a4faa4c57cc19c01b2e728e5ab4a30 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Mon, 19 Apr 2021 16:26:40 -0400 Subject: [PATCH 7/8] [feature] add option to use doctrine migrations to reset database (#145) --- .github/workflows/ci.yml | 30 +++++++++-- README.md | 40 +++++++++----- composer.json | 3 +- run-tests | 10 ++++ src/Test/DatabaseResetter.php | 53 +++++++++++++------ tests/Fixtures/Kernel.php | 13 +++++ .../Migrations/Version20210218175742.php | 31 +++++++++++ .../Migrations/Version20210318175742.php | 29 ++++++++++ 8 files changed, 174 insertions(+), 35 deletions(-) create mode 100644 tests/Fixtures/Migrations/Version20210218175742.php create mode 100644 tests/Fixtures/Migrations/Version20210318175742.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c8651af8..07aeeecf1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,9 +35,9 @@ jobs: - php: 7.2 stability: '@stable' versions: lowest - - php: 8.0 - stability: '@dev' - versions: highest +# - php: 8.0 +# stability: '@dev' +# versions: highest steps: - name: Checkout code uses: actions/checkout@v2.3.3 @@ -84,6 +84,18 @@ jobs: USE_FOUNDRY_BUNDLE: 1 DATABASE_URL: mysql://root:1234@127.0.0.1:3306/zenstruck_foundry?serverVersion=5.7 + - name: 'Test: MySQL, DoctrineMigrationsBundle' + run: vendor/bin/simple-phpunit -v + env: + FOUNDRY_RESET_MODE: migrate + DATABASE_URL: mysql://root:1234@127.0.0.1:3306/zenstruck_foundry?serverVersion=5.7 + + - name: 'Test: MySQL, DoctrineMigrationsBundle, DAMABundle' + run: vendor/bin/simple-phpunit -v --configuration phpunit-dama-doctrine.xml.dist + env: + FOUNDRY_RESET_MODE: migrate + DATABASE_URL: mysql://root:1234@127.0.0.1:3306/zenstruck_foundry?serverVersion=5.7 + - name: 'Test: PostgreSQL' run: vendor/bin/simple-phpunit -v env: @@ -189,6 +201,18 @@ jobs: USE_FOUNDRY_BUNDLE: 1 DATABASE_URL: mysql://root:1234@127.0.0.1:3306/zenstruck_foundry?serverVersion=5.7 + - name: 'Test: MySQL, DoctrineMigrationsBundle' + run: vendor/bin/simple-phpunit -v --coverage-text --coverage-clover=mysql-migrations.clover + env: + FOUNDRY_RESET_MODE: migrate + DATABASE_URL: mysql://root:1234@127.0.0.1:3306/zenstruck_foundry?serverVersion=5.7 + + - name: 'Test: MySQL, DoctrineMigrationsBundle, DAMABundle' + run: vendor/bin/simple-phpunit -v --coverage-text --coverage-clover=mysql-migrations-dama.clover --configuration phpunit-dama-doctrine.xml.dist + env: + FOUNDRY_RESET_MODE: migrate + DATABASE_URL: mysql://root:1234@127.0.0.1:3306/zenstruck_foundry?serverVersion=5.7 + - name: 'Coverage: PostgreSQL' run: vendor/bin/simple-phpunit -v --coverage-text --coverage-clover=postgres.clover env: diff --git a/README.md b/README.md index 895174c8f..b0455d568 100644 --- a/README.md +++ b/README.md @@ -43,24 +43,25 @@ Want to watch a screencast 🎥 about it? Check out https://symfonycasts.com/fou 4. [Using with DoctrineFixturesBundle](#using-with-doctrinefixturesbundle) 5. [Using in your Tests](#using-in-your-tests) 1. [Enable Foundry in your TestCase](#enable-foundry-in-your-testcase) - 2. [Object Proxy](#object-proxy) + 2. [Database Reset](#database-reset) + 3. [Object Proxy](#object-proxy) 1. [Force Setting](#force-setting) 2. [Auto-Refresh](#auto-refresh) - 3. [Repository Proxy](#repository-proxy) - 4. [Assertions](#assertions) - 5. [Global State](#global-state) - 6. [PHPUnit Data Providers](#phpunit-data-providers) - 7. [Performance](#performance) + 4. [Repository Proxy](#repository-proxy) + 5. [Assertions](#assertions) + 6. [Global State](#global-state) + 7. [PHPUnit Data Providers](#phpunit-data-providers) + 8. [Performance](#performance) 1. [DAMADoctrineTestBundle](#damadoctrinetestbundle) 2. [Miscellaneous](#miscellaneous) - 8. [Non-Kernel Test](#non-kernel-tests) - 9. [Test-Only Configuration](#test-only-configuration) - 10. [Using without the Bundle](#using-without-the-bundle) -7. [Stories](#stories) + 9. [Non-Kernel Test](#non-kernel-tests) + 10. [Test-Only Configuration](#test-only-configuration) + 11. [Using without the Bundle](#using-without-the-bundle) +6. [Stories](#stories) 1. [Stories as Services](#stories-as-services) 2. [Story State](#story-state) -8. [Bundle Configuration](#bundle-configuration) -9. [Credit](#credit) +7. [Bundle Configuration](#bundle-configuration) +8. [Credit](#credit) ## Installation @@ -1024,8 +1025,10 @@ class MyTest extends WebTestCase } ``` -This library requires that your database be reset before each test. The packaged `ResetDatabase` trait handles this for -you. Before the first test, it drops (if exists) and creates the test database. Before each test, it resets the schema. +### Database Reset + +This library requires that your database be reset before each test. The packaged `ResetDatabase` trait handles +this for you. ```php use Zenstruck\Foundry\Test\Factories; @@ -1040,6 +1043,15 @@ class MyTest extends WebTestCase } ``` +Before the first test using the `ResetDatabase` trait, it drops (if exists) and creates the test database. +Then, by default, before each test, it resets the schema using `doctrine:schema:drop`/`doctrine:schema:create`. + +Alternatively, you can have it run your migrations instead by setting the env variable `FOUNDRY_RESET_MODE=migrate` +(in your `.env.test`). When using this *mode*, before each test, the database is dropped/created and your migrations +run (via `doctrine:migrations:migrate`). This mode can really make your test suite slow (especially if you have a lot +of migrations). It is highly recommended to use [DamaDoctrineTestBundle](#damadoctrinetestbundle) to improve the +speed. When this bundle is enabled, the database is dropped/created and migrated only once for the suite. + **TIP**: Create a base TestCase for tests using factories to avoid adding the traits to every TestCase. **NOTE**: If your tests [are not persisting](#without-persisting) the objects they create, these test traits are not diff --git a/composer.json b/composer.json index a695f044f..bbf44c141 100644 --- a/composer.json +++ b/composer.json @@ -22,11 +22,12 @@ "require-dev": { "dama/doctrine-test-bundle": "^6.0", "doctrine/doctrine-bundle": "^2.0", + "doctrine/doctrine-migrations-bundle": "^2.2|^3.0", "doctrine/orm": "^2.7", "matthiasnoback/symfony-dependency-injection-test": "^4.1", "psalm/plugin-symfony": "^1.5|^2.0", "symfony/framework-bundle": "^4.4|^5.0", - "symfony/maker-bundle": "^1.13", + "symfony/maker-bundle": "^1.30", "symfony/phpunit-bridge": "^5.2", "vimeo/psalm": "^3.18|^4.0" }, diff --git a/run-tests b/run-tests index ecc8bcfad..cf8e21d75 100755 --- a/run-tests +++ b/run-tests @@ -21,3 +21,13 @@ echo "Running with FoundryBundle and with DamaDoctrineTestBundle" echo "==========================================================" echo "" USE_FOUNDRY_BUNDLE=1 vendor/bin/simple-phpunit -c phpunit-dama-doctrine.xml + +echo "Running with DoctineMigrationsBundle and without DamaDoctrineTestBundle" +echo "=======================================================================" +echo "" +USE_FOUNDRY_BUNDLE=0 FOUNDRY_RESET_MODE=migrate vendor/bin/simple-phpunit + +echo "Running with DoctineMigrationsBundle and with DamaDoctrineTestBundle" +echo "====================================================================" +echo "" +USE_FOUNDRY_BUNDLE=0 FOUNDRY_RESET_MODE=migrate vendor/bin/simple-phpunit -c phpunit-dama-doctrine.xml diff --git a/src/Test/DatabaseResetter.php b/src/Test/DatabaseResetter.php index 8f32ad514..18fefcded 100644 --- a/src/Test/DatabaseResetter.php +++ b/src/Test/DatabaseResetter.php @@ -39,6 +39,28 @@ public static function resetDatabase(KernelInterface $kernel): void $application = self::createApplication($kernel); $registry = $kernel->getContainer()->get('doctrine'); + self::dropAndCreateDatabase($application, $registry); + self::createSchema($application, $registry); + + self::$hasBeenReset = true; + } + + public static function resetSchema(KernelInterface $kernel): void + { + $application = self::createApplication($kernel); + $registry = $kernel->getContainer()->get('doctrine'); + + self::dropSchema($application, $registry); + self::createSchema($application, $registry); + } + + private static function isResetUsingMigrations(): bool + { + return 'migrate' === ($_SERVER['FOUNDRY_RESET_MODE'] ?? 'schema'); + } + + private static function dropAndCreateDatabase(Application $application, ManagerRegistry $registry): void + { foreach (self::connectionsToReset($registry) as $connection) { $dropParams = ['--connection' => $connection, '--force' => true]; @@ -53,27 +75,18 @@ public static function resetDatabase(KernelInterface $kernel): void '--connection' => $connection, ]); } - - self::createSchema($application, $registry); - - self::$hasBeenReset = true; - } - - public static function resetSchema(KernelInterface $kernel): void - { - $application = self::createApplication($kernel); - $registry = $kernel->getContainer()->get('doctrine'); - - self::dropSchema($application, $registry); - self::createSchema($application, $registry); } private static function createSchema(Application $application, ManagerRegistry $registry): void { - foreach (self::objectManagersToReset($registry) as $manager) { - self::runCommand($application, 'doctrine:schema:create', [ - '--em' => $manager, - ]); + if (self::isResetUsingMigrations()) { + self::runCommand($application, 'doctrine:migrations:migrate', ['-n' => true]); + } else { + foreach (self::objectManagersToReset($registry) as $manager) { + self::runCommand($application, 'doctrine:schema:create', [ + '--em' => $manager, + ]); + } } if (!Factory::isBooted()) { @@ -85,6 +98,12 @@ private static function createSchema(Application $application, ManagerRegistry $ private static function dropSchema(Application $application, ManagerRegistry $registry): void { + if (self::isResetUsingMigrations()) { + self::dropAndCreateDatabase($application, $registry); + + return; + } + foreach (self::objectManagersToReset($registry) as $manager) { self::runCommand($application, 'doctrine:schema:drop', [ '--em' => $manager, diff --git a/tests/Fixtures/Kernel.php b/tests/Fixtures/Kernel.php index 80cde8418..c271a092e 100644 --- a/tests/Fixtures/Kernel.php +++ b/tests/Fixtures/Kernel.php @@ -4,6 +4,7 @@ use DAMA\DoctrineTestBundle\DAMADoctrineTestBundle; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; +use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Bundle\MakerBundle\MakerBundle; @@ -36,6 +37,10 @@ public function registerBundles(): iterable if (\getenv('USE_DAMA_DOCTRINE_TEST_BUNDLE')) { yield new DAMADoctrineTestBundle(); } + + if ('migrate' === \getenv('FOUNDRY_RESET_MODE')) { + yield new DoctrineMigrationsBundle(); + } } protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void @@ -81,6 +86,14 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'auto_refresh_proxies' => false, ]); } + + if ('migrate' === \getenv('FOUNDRY_RESET_MODE')) { + $c->loadFromExtension('doctrine_migrations', [ + 'migrations_paths' => [ + 'Zenstruck\Foundry\Tests\Fixtures\Migrations' => '%kernel.project_dir%/tests/Fixtures/Migrations', + ], + ]); + } } protected function configureRoutes(RouteCollectionBuilder $routes): void diff --git a/tests/Fixtures/Migrations/Version20210218175742.php b/tests/Fixtures/Migrations/Version20210218175742.php new file mode 100644 index 000000000..ca40bfe25 --- /dev/null +++ b/tests/Fixtures/Migrations/Version20210218175742.php @@ -0,0 +1,31 @@ +addSql('CREATE TABLE categories (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE comments (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, post_id INT NOT NULL, body LONGTEXT NOT NULL, createdAt DATETIME NOT NULL, approved TINYINT(1) NOT NULL, INDEX IDX_5F9E962AA76ED395 (user_id), INDEX IDX_5F9E962A4B89032C (post_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE contacts (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, address_value VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE posts (id INT AUTO_INCREMENT NOT NULL, category_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, body LONGTEXT NOT NULL, shortDescription VARCHAR(255) DEFAULT NULL, viewCount INT NOT NULL, createdAt DATETIME NOT NULL, publishedAt DATETIME DEFAULT NULL, INDEX IDX_885DBAFA12469DE2 (category_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE post_tag (post_id INT NOT NULL, tag_id INT NOT NULL, INDEX IDX_5ACE3AF04B89032C (post_id), INDEX IDX_5ACE3AF0BAD26311 (tag_id), PRIMARY KEY(post_id, tag_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE tags (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + } + + public function down(Schema $schema): void + { + } +} diff --git a/tests/Fixtures/Migrations/Version20210318175742.php b/tests/Fixtures/Migrations/Version20210318175742.php new file mode 100644 index 000000000..7e1e42967 --- /dev/null +++ b/tests/Fixtures/Migrations/Version20210318175742.php @@ -0,0 +1,29 @@ +addSql('ALTER TABLE comments ADD CONSTRAINT FK_5F9E962AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE comments ADD CONSTRAINT FK_5F9E962A4B89032C FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE posts ADD CONSTRAINT FK_885DBAFA12469DE2 FOREIGN KEY (category_id) REFERENCES categories (id)'); + $this->addSql('ALTER TABLE post_tag ADD CONSTRAINT FK_5ACE3AF04B89032C FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE post_tag ADD CONSTRAINT FK_5ACE3AF0BAD26311 FOREIGN KEY (tag_id) REFERENCES tags (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + } +} From 7dc49f0e6247db66b7d8215d04b5d3b9e4455734 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Mon, 19 Apr 2021 16:28:09 -0400 Subject: [PATCH 8/8] [minor] unlock php-cs-fixer in gh action --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07aeeecf1..509fef767 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -290,7 +290,7 @@ jobs: with: php-version: 7.4 coverage: none - tools: php-cs-fixer:2.18.3 + tools: php-cs-fixer - name: Check CS run: php-cs-fixer fix --dry-run --diff --diff-format=udiff