Fix a condition that would not allow diffing of foreign keys for Sqlite#4012
Fix a condition that would not allow diffing of foreign keys for Sqlite#4012camilleterol wants to merge 6 commits intodoctrine:2.12.xfrom
Conversation
|
For safe-keeping, here is the previous PR that was not referencing the correct branch. |
FYI you could have just clicked the |
|
Copying my comment here: This looks a lot like #3994 … maybe there are more occurrences of supportsForeignKeyConstraints that should be re-evaluated? In any case, please add a test. |
|
Sorry about that. I forked the whole thing instead of creating a branch for the PR because I'm lazy. |
|
It's not SVN anymore, creating branches is cheap, try it next time ;) |
|
For sure! I haven't used SVN since 2008 so creating a branch is what I usually do. But I was confused by GitHub's UI. |
Today being a bank holiday, I'll try and add the test case that we mentioned above for SQLite. Approaching the repository, though, I'm wondering if it could be of use to add a CONTRIBUTE guide and a section on how to run the tests in the README to lower the barrier of entry. |
I have had the same thought in the back of my mind, I know @morozov asks for a lot of functional tests, but when I contributed as a dev rather than as a maintainer in #3994, I had a hard time figuring out where this should go and how things are organized. @morozov , your input on this would be priceless. |
|
I wrote a failing test, then made sure that my modification in commit dd6aaea would make the test pass. TDD 🎉 |
| $diff = $this->createSchemaDiff(); | ||
| $platform = $this->createPlatform(true); | ||
|
|
||
| $sql = $diff->toSql($platform); | ||
|
|
||
| $expected = ['create_table']; | ||
|
|
||
| self::assertEquals($expected, $sql); |
There was a problem hiding this comment.
| $diff = $this->createSchemaDiff(); | |
| $platform = $this->createPlatform(true); | |
| $sql = $diff->toSql($platform); | |
| $expected = ['create_table']; | |
| self::assertEquals($expected, $sql); | |
| self::assertEquals( | |
| ['create_table'], | |
| $this->createSchemaDiff()->toSql($this->createPlatform(true)) | |
| ); |
|
|
||
| $expected = ['create_table']; | ||
|
|
||
| self::assertEquals($expected, $sql); |
There was a problem hiding this comment.
This looks exactly as the test above. Instead of having the reader read both tests to notice that, please use one test with a data provider. The data provider should have keys describing what true and false mean.
| /** | ||
| * @return AbstractPlatform|MockObject | ||
| */ | ||
| private function createPlatform(bool $unsafe) |
There was a problem hiding this comment.
Can be merged with the aforementioned test I suppose
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class SqliteSchemaDiffTest extends TestCase |
There was a problem hiding this comment.
Are the tests specific to Sqlite or could they apply to other platforms?
There was a problem hiding this comment.
I'm not sure. They are testing a specific use case that I encountered with SQLite, it might apply to any platform where supportsForeignKeyConstraints() is true and supportsCreateDropForeignKeyConstraints() is false.
There was a problem hiding this comment.
Given the number of things mocked, I can barely understand what is being tested here. Would it make sense to have an integration test instead?
There was a problem hiding this comment.
I guess so. I just copied the code that was in the SchemaDiffTest. Maybe a more generic integration test could cover both cases.
| ->will($this->throwException( | ||
| new DBALException('Sqlite platform does not support alter foreign key, the table must be fully recreated using getAlterTableSQL.') | ||
| )); | ||
| } |
There was a problem hiding this comment.
That's a lot of mocking… why not use the real object? A cross-platform functional test should make all this a bit shorter.
There was a problem hiding this comment.
My thoughts exactly. All of your above remarks apply. I just copied the SchemaDiffTest and kept the same coding style.
|
I tweaked my test case a little. My time working on this for today is up. But any feedback is welcome :) I might be able to fork on this further if need be tomorrow or Sunday. |
|
I'll have some more time to work on this tomorrow, so what do you guys prefer? Should I strive for consistency and keep the test somewhat identical to the |
I don't think you should, or maybe be consistent with another, better test if you can find one.
Sounds good. You should be able to do so by using |
|
Thanks for your insight on the matter. I'll do just that. Unfortunately I have not gotten the time yet to work on this further. I will try and take a look at it in the next few days if time allows. |
Summary
After the changes introduced by #1204, the SchemaDiff would throw an error when trying to diff an Sqlite-backed schema with foreign keys modifications.