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

Implement specialized alternatives to assertInternalType() and assertNotInternalType() #3368

Closed
sebastianbergmann opened this issue Oct 24, 2018 · 10 comments
Assignees
Milestone

Comments

@sebastianbergmann
Copy link
Owner

@sebastianbergmann sebastianbergmann commented Oct 24, 2018

Implement

  • assertIsArray()
  • assertIsBool()
  • assertIsFloat()
  • assertIsInt()
  • assertIsNumeric()
  • assertIsObject()
  • assertIsResource()
  • assertIsString()
  • assertIsScalar()
  • assertIsCallable()
  • assertIsIterable()
  • assertIsNotArray()
  • assertIsNotBool()
  • assertIsNotFloat()
  • assertIsNotInt()
  • assertIsNotNumeric()
  • assertIsNotObject()
  • assertIsNotResource()
  • assertIsNotString()
  • assertIsNotScalar()
  • assertIsNotCallable()
  • assertIsNotIterable()
@keradus
Copy link
Contributor

@keradus keradus commented Oct 25, 2018

can you elaborate on that one, @sebastianbergmann ?
looks like lot of new assertions

I agree that with assertInternalType it's easy to make a typo with provided type, like bol instead of bool, yet even if one would do the typo, then when he run tests assertion will fail anyway

@TomasVotruba
Copy link
Contributor

@TomasVotruba TomasVotruba commented Dec 31, 2018

What will happen to same checks just for arrays?

$this->assertContainsOnly('string', $types);
nelson6e65 added a commit to nelson6e65/php_nml that referenced this issue Jan 16, 2019
@glensc
Copy link

@glensc glensc commented Feb 9, 2019

what phpunit min version has the new assertions?

@sebastianbergmann
Copy link
Owner Author

@sebastianbergmann sebastianbergmann commented Feb 9, 2019

These assertions were implemented for PHPUnit 7.5.

@glensc
Copy link

@glensc glensc commented Feb 9, 2019

what's the replacement for such code:

        $this->assertInternalType(gettype($algo), $res['algo']);
@nelson6e65
Copy link

@nelson6e65 nelson6e65 commented Feb 9, 2019

what's the replacement for such code:

        $this->assertInternalType(gettype($algo), $res['algo']);

@glensc Maybe...

$assertIsType = 'assertIs'.gettype($algo);

$this->$assertIsType($res['algo']);

But... if you need this dynamic, you may need a redesign of the test. 😅

@JeroenDeDauw
Copy link
Contributor

@JeroenDeDauw JeroenDeDauw commented Feb 24, 2020

Is there a way to make these available in PHPUnit 6?

I'd be tempted to reply to my own question with "just use a modern version of PHPUnit", so here some background of why this change sucks for me. I maintain a number of MediaWiki extensions. The development version of MediaWiki uses PHPUnit 8, so no problems there. However the latest LTS uses PHPUnit 6. Which means I cannot use the new assertion methods introduced in PHPUnit 7.5. So I'm forced to either write instant legacy assertions and live with a pile of warnings, or to drop testing against a very relevant version of MediaWiki from the CI.

@nelson6e65
Copy link

@nelson6e65 nelson6e65 commented Mar 1, 2020

Is there a way to make these available in PHPUnit 6?

I'd be tempted to reply to my own question with "just use a modern version of PHPUnit", so here some background of why this change sucks for me. I maintain a number of MediaWiki extensions. The development version of MediaWiki uses PHPUnit 8, so no problems there. However the latest LTS uses PHPUnit 6. Which means I cannot use the new assertion methods introduced in PHPUnit 7.5. So I'm forced to either write instant legacy assertions and live with a pile of warnings, or to drop testing against a very relevant version of MediaWiki from the CI.

Well... there are the changes in a406c85#diff-9ae7a972d07df5f73629d5d315bf405a

Yo can create a trait with that methods and try to use it in your tests classes.

@JeroenDeDauw
Copy link
Contributor

@JeroenDeDauw JeroenDeDauw commented Mar 1, 2020

Thanks for the link. I asked here in the hope there already is a package that provides a copy.

@joelmellon
Copy link

@joelmellon joelmellon commented Mar 26, 2020

what's the replacement for such code:

        $this->assertInternalType(gettype($algo), $res['algo']);
$this->assertEquals(gettype($algo), gettype($res['algo']));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.