Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated assertion usage #54

Conversation

codisart
Copy link
Contributor

Q A
Documentation no
Bugfix no
BC Break no
New Feature no
RFC no
QA yes

Description

Remove some deprecated phpunit assertions that test non public attribute

@codisart codisart force-pushed the refactor-remove-deprecated-phpunit-assertions branch from 0c47f26 to c3d4646 Compare February 10, 2020 17:49
@codisart codisart force-pushed the refactor-remove-deprecated-phpunit-assertions branch from c3d4646 to 1407dd2 Compare February 19, 2020 12:12
$messageTemplates = [
'notBetween' => "The input is not between '%min%' and '%max%', inclusively",
'notBetweenStrict' => "The input is not strictly between '%min%' and '%max%'",
'valueNotNumeric' => "The min ('%min%') and max ('%max%') values are numeric, but the input is not",
Copy link
Member

Choose a reason for hiding this comment

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

I think with this type of test only duplicates are created.
For instance: the message text of Between::VALUE_NOT_NUMERIC is already tested in
BetweenTest ::testStringValidatedAgainstNumericMinAndMaxIsInvalidAndReturnsAFailureMessage.

public function testStringValidatedAgainstNumericMinAndMaxIsInvalidAndReturnsAFailureMessage()
{
$validator = new Between(['min' => 1, 'max' => 10]);
$this->assertFalse($validator->isValid('a'));
$messages = $validator->getMessages();
$this->assertContains(
'The min (\'1\') and max (\'10\') values are numeric, but the input is not',
$messages
);
}

If the messages are to be compared then maybe test only for the keys by using the class constants.

Copy link
Contributor Author

@codisart codisart Feb 25, 2020

Choose a reason for hiding this comment

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

Hello @froschdesign

The tests that I have replaced focused only on the error messages configuration. To be able to remove the most of the usage of assertAttributeEquals, I tought it best to keep for now the same intention of these olds tests. The only change that I have made is to use the real strings instead of the keys in order to not couple the tests with the classes that they test.

To be honest, I don't see a lot of value with these tests. I would prefer to create the case where these message are used. I propose to amend my PR to remove the test methods for the test classes where all the messages are already tested. What do you think ?

Copy link
Member

Choose a reason for hiding this comment

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

@codisart
The content of the messages should not be tested in all testEqualsMessageTemplates tests. But there is another option if you do not want to throw out the tests:

public function testEqualsMessageTemplates()
{
    $validator = new Between(['min' => 1, 'max' => 10]);
    $this->assertSame(
        [
            Between::NOT_BETWEEN,
            Between::NOT_BETWEEN_STRICT,
            Between::VALUE_NOT_NUMERIC,
            Between::VALUE_NOT_STRING,
        ],
        array_keys($validator->getMessageTemplates())
    );
}

Please feel free add your own proposal to find the best solution.

(Other improvements of the tests should be done in a separate pull requests because we should stay on the topic "Prepare update to phpunit 9".)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@froschdesign
Don't you think that to use directly the class constants add coupling between the test and the tested class ?

I am more and more inclined to just throw these tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the class constants for the tests as you suggested.

@codisart codisart force-pushed the refactor-remove-deprecated-phpunit-assertions branch 3 times, most recently from af0b04d to 655503b Compare April 4, 2020 21:40
@codisart
Copy link
Contributor Author

codisart commented Apr 11, 2020

Hello @froschdesign, are my last changes ok with your recommendations ?

);
}

public function testConstructorWithFormatParameter()
Copy link
Member

Choose a reason for hiding this comment

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

any reason why this test has been removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is an error. I will put it back.

@codisart codisart force-pushed the refactor-remove-deprecated-phpunit-assertions branch from 655503b to debf38c Compare May 9, 2020 22:05
@geerteltink geerteltink changed the base branch from master to 2.14.x September 12, 2020 07:48
@codisart
Copy link
Contributor Author

codisart commented Oct 1, 2020

Hello @michalbundyra,

Do I need to change things for this PR ?

@boesing
Copy link
Member

boesing commented Nov 18, 2020

Oh snap... I wasn't aware of this PR.
By adding support for PHP 8.0 in #75, PHPUnit 9.X was also necessary there.
Sadly, the author of that PR did not see this PR as he could used it as a starting point.

@codisart Could you compare your changes with those from #75? If you have additional changes for better support of phpunit 9, I'd suggest to rebase against that branch as it will likely be merged in favor of your PR due to the adoption of PHP 8.0.

@codisart
Copy link
Contributor Author

Hello @boesing

There is a lot of differences between my fixes of the removal of "assertAttributeEquals" with #75.
I will rebase and put in draft.

@codisart codisart marked this pull request as draft January 2, 2021 00:49
@codisart
Copy link
Contributor Author

codisart commented Jan 2, 2021

Hello @boesing should I rebase using #79 also ?

@boesing
Copy link
Member

boesing commented Jan 3, 2021

@codisart one step after another. PRs should only rebase against their targets.
Lets wait until we get #79 and/or #75 merged.

@codisart codisart force-pushed the refactor-remove-deprecated-phpunit-assertions branch 2 times, most recently from 7993e1d to 8b7995a Compare January 7, 2021 23:22
@codisart codisart changed the base branch from 2.14.x to 2.15.x January 7, 2021 23:23
@codisart codisart force-pushed the refactor-remove-deprecated-phpunit-assertions branch from 8b7995a to dfb2843 Compare January 7, 2021 23:26
@codisart
Copy link
Contributor Author

codisart commented Jan 7, 2021

@boesing Everything is up to date !

@weierophinney
Copy link
Member

weierophinney commented Jan 13, 2021

@codisart #75 adds PHP 8 support... and, to do so, bumps PHPUnit to 9.3. From what I can see, we're seill using some deprecated assertions currently (though they are not raising notices, from what I can see). As such:

  • Please change the title of the PR to "remove deprecated assertion usage"
  • Please use $this-> instead of self:: in the patch, for internal consistency; we can revisit $this vs self:: later, and, if we decide on the latter, convert everything at once, instead of piecemeal.

Once those changes are in place, please don't forget to to hit the "Ready for review" button so we can review and merge!

Thanks!

@codisart
Copy link
Contributor Author

ok let's go !

@codisart codisart changed the title Prepare update to phpunit 9 Remove deprecated assertion usage Jan 13, 2021
@codisart codisart force-pushed the refactor-remove-deprecated-phpunit-assertions branch from dfb2843 to 0ddcdf4 Compare January 13, 2021 21:35
@codisart codisart marked this pull request as ready for review January 13, 2021 21:36
Signed-off-by: codisart <louis.celier@gmail.com>
@weierophinney weierophinney changed the base branch from 2.15.x to 2.14.x July 14, 2021 13:55
@weierophinney weierophinney force-pushed the refactor-remove-deprecated-phpunit-assertions branch from 0ddcdf4 to 10df593 Compare July 14, 2021 13:55
@weierophinney weierophinney added this to the 2.14.5 milestone Jul 14, 2021
@weierophinney weierophinney merged commit d588301 into laminas:2.14.x Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants