cebe / yii2-openapi

REST API application generator for Yii2, openapi 3.0 YAML -> Yii2
MIT License
129 stars 23 forks source link

A test passes locally fails in Github action CI or vice versa #137

Closed SOHELAHMED7 closed 1 year ago

SOHELAHMED7 commented 1 year ago

Test: tests\unit\MultiDbSecondaryMigrationTest::testMysql

Github action fail: https://github.com/SOHELAHMED7/yii2-openapi/actions/runs/4253815431/jobs/7399197040

Locally

There was 1 failure:

1) tests\unit\MultiDbSecondaryMigrationTest::testMysql
Failed asserting that file contents of
/app/tests/tmp/docker_app/migrations_mysql_db/m200000_000005_change_table_v2_comments.php
are equal to file contents of
/app/tests/specs/blog_v2/migrations_mysql_db/m200000_000005_change_table_v2_comments.php
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
+        $this->dropForeignKey('fk_v2_comments_post_id_v2_posts_uid', '{{%v2_comments}}');\n
         $this->dropForeignKey('fk_v2_comments_author_id_v2_users_id', '{{%v2_comments}}');\n
-        $this->dropForeignKey('fk_v2_comments_post_id_v2_posts_uid', '{{%v2_comments}}');\n
@@ @@
+        $this->addForeignKey('fk_v2_comments_author_id_v2_users_id', '{{%v2_comments}}', 'id', 'v2_users', 'author_id');\n
         $this->addForeignKey('fk_v2_comments_post_id_v2_posts_uid', '{{%v2_comments}}', 'uid', 'v2_posts', 'post_id');\n
-        $this->addForeignKey('fk_v2_comments_author_id_v2_users_id', '{{%v2_comments}}', 'id', 'v2_users', 'author_id');\n

/app/tests/unit/MultiDbSecondaryMigrationTest.php:109
/app/tests/unit/MultiDbSecondaryMigrationTest.php:67
phpvfscomposer:///app/vendor/phpunit/phpunit/phpunit:52

FAILURES!
Tests: 1, Assertions: 33, Failures: 1.

If I fix locally by copying content of /app/tests/tmp/docker_app/migrations_mysql_db/m200000_000005_change_table_v2_comments.php to /app/tests/specs/blog_v2/migrations_mysql_db/m200000_000005_change_table_v2_comments.php then this test fails on Github actions.

If I fix this test as per Github action, then Github CI passes but this tests fails locally.

cebe commented 1 year ago

how is the order in the migration determined?

might need to add an explicit ordering by sorting the array by something useful.

SOHELAHMED7 commented 1 year ago

I attempted to reproduce this issue by running this tests outside the container with the help of $ docker-compose run --rm php sh -c 'vendor/bin/phpunit'

I saw 3 failing tests. One of them signalled me to run make clean_all and make up && make migrate

This fixed this issue.

The problem was stale migration was not removed from db.migration table.