Use proper check in acceptForeignKey()#3994
Conversation
This comment has been minimized.
This comment has been minimized.
754e607 to
e615ecf
Compare
| } | ||
|
|
||
| /** | ||
| * @doesNotPerformAssertions |
There was a problem hiding this comment.
Just a note: @doesNotPerformAssertions also disregards coverage (conscious decision on PHPUnit's side). The recommended way to test that an exception hasn't been thrown is calling $this->addToAssertionCount(1) after the method that throws exceptions.
There was a problem hiding this comment.
@greg0ire sebastianbergmann/phpunit#3348 (and I didn't send the PR to fix the docs since I got no confirmation 😆)
There was a problem hiding this comment.
I'm really confused about having @doesNotPerformAssertions here. Is the only outcome of actions in the test scenario is not having an exception thrown? I would understand such expectations in a validation scenario (no exception means “valid”) but not here.
There was a problem hiding this comment.
@morozov my goal here was to have a failing test for an existing bug, I'm not really trying to assert anything, I want to fix a crash, and make sure it does not come back. Tell me if this file is not the right place for that (since it is in Functional, it might not be, but I'm not sure where I should put this). For PHPUnit I would put that kind of test here: For PHPUnit I would put it here: https://github.com/sebastianbergmann/phpunit/tree/master/tests/end-to-end/regression/GitHub
For DBAL… I have no clue. Please help.
There was a problem hiding this comment.
I want to fix a crash, and make sure it does not come back.
IMO, the purpose of a test is to ensure that the code works, not that it doesn't crash. I.e. should be worded in terms of assertions against produced results.
How do you know that just the absence of failure is enough in the reported case?
There was a problem hiding this comment.
Because this is what is complained about… they are not complaining that the fk does not get created properly for instance.
Anyway, I started by asserting that the generated SQL contains something about foreign key, but then I thought that even that might not work so I executed the SQL and asserted that there is a foreign key defined on it, tell me if I went overboard.
There was a problem hiding this comment.
Because this is what is complained about… they are not complaining that the fk does not get created properly for instance.
I don't think this is the right mindset. But I believe we're on the same page now.
[…] tell me if I went overboard
The approach looks fine. The only question is, is this case is platform-specific or we can move it into a platform-independent suite and get covered on all platforms. The fact that people tend to write platform-specific tests because they experience issues using a given platform is the primary reason why we have inconsistency in platform support.
e615ecf to
747101a
Compare
80708dd to
a97799f
Compare
| } | ||
|
|
||
| public function testCreatingATableWithAForeignKey() : void | ||
| { |
There was a problem hiding this comment.
Few tests here have a guard clause about sqlite3, should I add one?
There was a problem hiding this comment.
Is there anything specific to SQLite in this scenario? If yes, then I think the setup of the functional platform-specific test should require the corresponding platform to be active.
Otherwise, the test should be part of a platform-independent suite.
There was a problem hiding this comment.
I think this is platform independent, and I'm not sure what a platform-independent suite is. I moved it to a file that inherits from DbalFunctionTestCase, let's see how this pans out. My only doubt is about the foreign key name, I have no idea what computes it and if it will be the same for every platform.
86eea63 to
fe17629
Compare
|
Just pushed a version with a way, way less specific assertion. |
|
@morozov any idea why it fails for IBM DB2 and only for that RDBMS? |
I cannot check it right now. It's fine to mark it incomplete for DB2 and fix later but I think you'll need the @beberlei’s approval to get it merged. |
|
Well, actually, the problem seems to be in the case-sensitivity of DB2 when using quoted names. This is what the SQL creating the tables looks like (note that one name is quoted and the other isn't): CREATE TABLE referenced (id INTEGER NOT NULL, PRIMARY KEY(id))
CREATE TABLE "referencing" (referenced_id INTEGER NOT NULL)
-- ...
ALTER TABLE "referencing" ADD CONSTRAINT FK_E844F4C85A38C91 FOREIGN KEY (referenced_id) REFERENCES referenced (id)And then how the FK is selected: I don't think that quoting object names by default on DB2 or Oracle is the right thing to do, so it's definitely a bug in DBAL. And this is why it's quoted: |
|
Ok, I'll just pick another name for this PR I guess! Thanks a lot for the investigation. |
Checking that the platform supports foreign key is not the right case here, because we should check if we can create them by themselves, after the table is created. It is not the case for Sqlite. Closes doctrine#3990
fe17629 to
f0c1af4
Compare
|
The tests that fails is unrelated (and seems time based) |
This reverts commit d1953d6. doctrine/dbal has been fixed, see doctrine/dbal#3994
…ire) This PR was squashed before being merged into the 3.4 branch. Discussion ---------- Remove patches for Doctrine bugs and deprecations | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a | License | MIT | Doc PR | n/a This PR removes patches put in place because of a bug fixed in doctrine/dbal#3994, and because of deprecations addressed in doctrine/orm#7953 Commits ------- 2f305cd Remove patches for Doctrine bugs and deprecations
Summary
Checking that the platform supports foreign key is not the right case
here, because we should check if we can create them by themselves, after
the table is created. It is not the case for Sqlite.
Closes #3990
How can I test this?
composer config repositories.greg0ire vcs https://github.com/greg0ire/doctrine-dbal composer require doctrine/dbal "dev-check-for-alter-support as 2.10.2"