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

Rule php_unit_dedicate_assert should not use assertInternalType anymore. #6179

Closed
drupol opened this issue Dec 15, 2021 · 12 comments
Closed
Labels

Comments

@drupol
Copy link
Contributor

drupol commented Dec 15, 2021

Hi,

I just noticed that PHP CS Fixer replace this:

-        self::assertTrue(is_resource($file));
+        self::assertInternalType('resource', $file);

However, the method TestCase::assertInternalType does not exist anymore in PHPUnit, it has been deprecated.

On top of that, if just like me you're using the function is_resource to check if a resource is open or not, then replacing it with TestCase::assertInternalType is wrong because it doesn't check that specific thing. Why? Because TestCase::assertInternalType is based on getType() and does not check the status of the resource.

@keradus
Copy link
Member

keradus commented Dec 15, 2021

Thanks for the report!

Looks like we have a new feature of assertInternalType -> assertIsResource ;)

I believe it's a quirk that you checked the resources was open, to be honest. Looks like you check the side effect

@keradus
Copy link
Member

keradus commented Dec 15, 2021

actually we have that rule already: php_unit_dedicate_assert_internal_type.
how you decided to use php_unit_dedicate_assert only?

@drupol
Copy link
Contributor Author

drupol commented Dec 15, 2021

Hi Darius,

Actually I was testing if the resource was still open or not, this is why I why using:

self::assertTrue(is_resource($file));

For the rest of your questions, I'll get back to you as soon as possible.

@drupol
Copy link
Contributor Author

drupol commented Jan 24, 2022

@keradus both rules are existing, I can then use one or another, no ?

@SpacePossum
Copy link
Contributor

if you want this;

-        self::assertTrue(is_resource($file));
+        self::assertIsResource($file);

you'll need both php_unit_dedicate_assert and php_unit_dedicate_assert_internal_type

@drupol
Copy link
Contributor Author

drupol commented Jan 25, 2022

But that's the thing, this is definitely wrong because it has a different meaning.

When using the function is_resource to check if a resource is open or not, then replacing it with TestCase::assertInternalType is wrong because it doesn't check that specific thing.

TestCase::assertInternalType is based on getType() and does not check the status of the resource.

@SpacePossum
Copy link
Contributor

but replacing with assertIsResource is correct, or also not?

@drupol
Copy link
Contributor Author

drupol commented Jan 25, 2022

For me these two are completely different and should not be mixed.

@SpacePossum
Copy link
Contributor

SpacePossum commented Jan 25, 2022

ok, check, I see now 👍
for reference
from;
https://github.com/sebastianbergmann/phpunit/blob/9.5.13/src/Framework/Assert.php#L1519
to;
https://github.com/sebastianbergmann/phpunit/blob/9.5.13/src/Framework/Constraint/Type/IsType.php#L189

not sure how to proceed, no longer do the change, or do the change but update the docs about this, any preferences by anyone?

@drupol
Copy link
Contributor Author

drupol commented Jan 25, 2022

IMHO: I would just no longer do the change.

@SpacePossum
Copy link
Contributor

sounds good to me, can you prepare a PR for it maybe? let me know if not, no problem than I'll put it on my backlog

@drupol
Copy link
Contributor Author

drupol commented Jan 25, 2022

I will try... I don't promise you anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants