Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Fixed tests for quoteValue() methods in all Platform classes #7251

Merged
merged 1 commit into from
Mar 18, 2015
Merged

Fixed tests for quoteValue() methods in all Platform classes #7251

merged 1 commit into from
Mar 18, 2015

Conversation

hschletz
Copy link
Contributor

The tests for quoteValue() are incomplete. When quoteValue() raises an E_USER_NOTICE, PHPUnit converts it to an exception which is tested. The tests try to check the return value, but neither the return value generating code nor the assertion are executed. The tests pass, but only the error message is effectively tested.

I split the tests: One test checks the exception as usual, but the return value is discarded (It would be NULL anyway within a PHPUnit environment - in other context a value would be returned, but that is difficult to test). I also tightened the exception type check from PHPUnit_Framework_Error to PHPUnit_Framework_Error_Notice.

The other test executes quoteValue() with error suppression so that the return value can be checked. Since quoteValue() and quoteTrustedValue() are implemented separately, I added the full set of test values to the test.

$this->assertEquals("E'value'", @$this->platform->quoteValue('value'));
$this->assertEquals("E'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar"));
$this->assertEquals('E\'\\\'; DELETE FROM some_table; -- \'', @$this->platform->quoteValue('\'; DELETE FROM some_table; -- '));
$this->assertEquals("E'\\\\\\'; DELETE FROM some_table; -- '", @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- '));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please check this against the changes introduced to fix ZF2015-02? I'm pretty sure we changed escaping to better match the recommendations made by PostgreSQL.

@hschletz
Copy link
Contributor Author

Yes, the PR is based on yesterday's snapshot of the develop branch, which contains the fix in afe4172. The improvement to quoteValue() and quoteTrustedValue() is the 'E' prefix. This had been added to testQuoteTrustedValue(), but forgotten in testQuoteValue(), where it made no difference for the reason mentioned in the initial post.

This PR contains the updated assertions copied to testQuoteValue(), in addition to the structural changes to the test.

@weierophinney
Copy link
Member

@hschletz Can you please rebase against develop, so I can merge? I need that done by tomorrow, 19 March 2015; otherwise, we'll have to review after the 2.4 release.

@hschletz
Copy link
Contributor Author

Rebased against latest HEAD, merged into single commit.

@weierophinney weierophinney merged commit 6d22441 into zendframework:develop Mar 18, 2015
weierophinney added a commit that referenced this pull request Mar 18, 2015
Fixed tests for quoteValue() methods in all Platform classes
weierophinney added a commit that referenced this pull request Mar 18, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants