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
Labels
type/enhancement A new idea that should be implemented
Milestone

Comments

@sebastianbergmann
Copy link
Owner

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 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

What will happen to same checks just for arrays?

$this->assertContainsOnly('string', $types);

@glensc
Copy link

glensc commented Feb 9, 2019

what phpunit min version has the new assertions?

@sebastianbergmann
Copy link
Owner Author

These assertions were implemented for PHPUnit 7.5.

@glensc
Copy link

glensc commented Feb 9, 2019

what's the replacement for such code:

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

@nelson6e65
Copy link

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

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 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 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 commented Mar 26, 2020

what's the replacement for such code:

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

jrfnl added a commit to jrfnl/wordpress-develop that referenced this issue Aug 16, 2020
…tIs[Not]Array()`

The `assertInternalType()` and `assertNotInternalType()` methods were soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

The more specific `assertIsArray()`, `assertIsNotArray()`, `assertIsBool()`, `assertIsNotBool()`, `assertIsFloat()`, `assertIsNotFloat()`, `assertIsInt()`, `assertIsNotInt()`, `assertIsNumeric()`, `assertIsNotNumeric()`, `assertIsObject()`, `assertIsNotObject()`, `assertIsResource()`, `assertIsNotResource()`, `assertIsString()`,
`assertIsNotString()`, `assertIsScalar()`, `assertIsNotScalar()`, `assertIsCallable()`, `assertIsNotCallable()`, `assertIsIterable()`, `assertIsNotIterable()` methods were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3368
jrfnl added a commit to jrfnl/wordpress-develop that referenced this issue Aug 16, 2020
…Is[Not]Bool()`

The `assertInternalType()` and `assertNotInternalType()` methods were soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

The more specific `assertIsArray()`, `assertIsNotArray()`, `assertIsBool()`, `assertIsNotBool()`, `assertIsFloat()`, `assertIsNotFloat()`, `assertIsInt()`, `assertIsNotInt()`, `assertIsNumeric()`, `assertIsNotNumeric()`, `assertIsObject()`, `assertIsNotObject()`, `assertIsResource()`, `assertIsNotResource()`, `assertIsString()`,
`assertIsNotString()`, `assertIsScalar()`, `assertIsNotScalar()`, `assertIsCallable()`, `assertIsNotCallable()`, `assertIsIterable()`, `assertIsNotIterable()` methods were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3368
jrfnl added a commit to jrfnl/wordpress-develop that referenced this issue Aug 16, 2020
…tIs[Not]Float()`

The `assertInternalType()` and `assertNotInternalType()` methods were soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

The more specific `assertIsArray()`, `assertIsNotArray()`, `assertIsBool()`, `assertIsNotBool()`, `assertIsFloat()`, `assertIsNotFloat()`, `assertIsInt()`, `assertIsNotInt()`, `assertIsNumeric()`, `assertIsNotNumeric()`, `assertIsObject()`, `assertIsNotObject()`, `assertIsResource()`, `assertIsNotResource()`, `assertIsString()`,
`assertIsNotString()`, `assertIsScalar()`, `assertIsNotScalar()`, `assertIsCallable()`, `assertIsNotCallable()`, `assertIsIterable()`, `assertIsNotIterable()` methods were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3368
jrfnl added a commit to jrfnl/wordpress-develop that referenced this issue Aug 16, 2020
…s[Not]Int()`

The `assertInternalType()` and `assertNotInternalType()` methods were soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

The more specific `assertIsArray()`, `assertIsNotArray()`, `assertIsBool()`, `assertIsNotBool()`, `assertIsFloat()`, `assertIsNotFloat()`, `assertIsInt()`, `assertIsNotInt()`, `assertIsNumeric()`, `assertIsNotNumeric()`, `assertIsObject()`, `assertIsNotObject()`, `assertIsResource()`, `assertIsNotResource()`, `assertIsString()`,
`assertIsNotString()`, `assertIsScalar()`, `assertIsNotScalar()`, `assertIsCallable()`, `assertIsNotCallable()`, `assertIsIterable()`, `assertIsNotIterable()` methods were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3368
jrfnl added a commit to jrfnl/wordpress-develop that referenced this issue Aug 21, 2020
…tIs[Not]Float()`

The `assertInternalType()` and `assertNotInternalType()` methods were soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

The more specific `assertIsArray()`, `assertIsNotArray()`, `assertIsBool()`, `assertIsNotBool()`, `assertIsFloat()`, `assertIsNotFloat()`, `assertIsInt()`, `assertIsNotInt()`, `assertIsNumeric()`, `assertIsNotNumeric()`, `assertIsObject()`, `assertIsNotObject()`, `assertIsResource()`, `assertIsNotResource()`, `assertIsString()`,
`assertIsNotString()`, `assertIsScalar()`, `assertIsNotScalar()`, `assertIsCallable()`, `assertIsNotCallable()`, `assertIsIterable()`, `assertIsNotIterable()` methods were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3368
jrfnl added a commit to jrfnl/wordpress-develop that referenced this issue Aug 21, 2020
…s[Not]Int()`

The `assertInternalType()` and `assertNotInternalType()` methods were soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

The more specific `assertIsArray()`, `assertIsNotArray()`, `assertIsBool()`, `assertIsNotBool()`, `assertIsFloat()`, `assertIsNotFloat()`, `assertIsInt()`, `assertIsNotInt()`, `assertIsNumeric()`, `assertIsNotNumeric()`, `assertIsObject()`, `assertIsNotObject()`, `assertIsResource()`, `assertIsNotResource()`, `assertIsString()`,
`assertIsNotString()`, `assertIsScalar()`, `assertIsNotScalar()`, `assertIsCallable()`, `assertIsNotCallable()`, `assertIsIterable()`, `assertIsNotIterable()` methods were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3368

Includes removing a few assignments made within function calls.
jrfnl added a commit to jrfnl/wordpress-develop that referenced this issue Aug 21, 2020
…rtIs[Not]Object()`

The `assertInternalType()` and `assertNotInternalType()` methods were soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

The more specific `assertIsArray()`, `assertIsNotArray()`, `assertIsBool()`, `assertIsNotBool()`, `assertIsFloat()`, `assertIsNotFloat()`, `assertIsInt()`, `assertIsNotInt()`, `assertIsNumeric()`, `assertIsNotNumeric()`, `assertIsObject()`, `assertIsNotObject()`, `assertIsResource()`, `assertIsNotResource()`, `assertIsString()`,
`assertIsNotString()`, `assertIsScalar()`, `assertIsNotScalar()`, `assertIsCallable()`, `assertIsNotCallable()`, `assertIsIterable()`, `assertIsNotIterable()` methods were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3368
jrfnl added a commit to jrfnl/wordpress-develop that referenced this issue Aug 21, 2020
…sertIs[Not]Resource()`

The `assertInternalType()` and `assertNotInternalType()` methods were soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

The more specific `assertIsArray()`, `assertIsNotArray()`, `assertIsBool()`, `assertIsNotBool()`, `assertIsFloat()`, `assertIsNotFloat()`, `assertIsInt()`, `assertIsNotInt()`, `assertIsNumeric()`, `assertIsNotNumeric()`, `assertIsObject()`, `assertIsNotObject()`, `assertIsResource()`, `assertIsNotResource()`, `assertIsString()`,
`assertIsNotString()`, `assertIsScalar()`, `assertIsNotScalar()`, `assertIsCallable()`, `assertIsNotCallable()`, `assertIsIterable()`, `assertIsNotIterable()` methods were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3368
jrfnl added a commit to jrfnl/wordpress-develop that referenced this issue Aug 21, 2020
…rtIs[Not]String()`

The `assertInternalType()` and `assertNotInternalType()` methods were soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

The more specific `assertIsArray()`, `assertIsNotArray()`, `assertIsBool()`, `assertIsNotBool()`, `assertIsFloat()`, `assertIsNotFloat()`, `assertIsInt()`, `assertIsNotInt()`, `assertIsNumeric()`, `assertIsNotNumeric()`, `assertIsObject()`, `assertIsNotObject()`, `assertIsResource()`, `assertIsNotResource()`, `assertIsString()`,
`assertIsNotString()`, `assertIsScalar()`, `assertIsNotScalar()`, `assertIsCallable()`, `assertIsNotCallable()`, `assertIsIterable()`, `assertIsNotIterable()` methods were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3368
colinmollenhour pushed a commit to colinmollenhour/credis that referenced this issue Oct 12, 2020
* Update Dockerfile

- Removed PHP 5.5 & Added PHP 7.4
- PHP Redis Extension 4.3.0 is the latest version to support PHP 5
- Update Redis to 6.0.8 and enable TLS support for PHP 7

* Update .travis.yml

- Update php-redis to 5.3.0
- Update redis-server to 6.0.8

* Fixes test failures

- Use [assertIsArray](sebastianbergmann/phpunit#3368) method since PHPUnit v7.5
- Fixes AUTH error message changed since Redis v6
- `getMock()` is deprecated since PHPUnit v5.4

* Update Client.php

- PHP Redis extension support TLS since [5.3.0](https://pecl.php.net/package/redis/5.3.0)
- Fixes AUTH may not cleanup last error
Mopolo added a commit to Mopolo/laminas-soap that referenced this issue Jan 11, 2021
Mopolo added a commit to Mopolo/laminas-soap that referenced this issue Jan 11, 2021
As documented here: sebastianbergmann/phpunit#3368

Signed-off-by: Nathan Boiron <[email protected]>
NicTorgersen added a commit to pindena/omnipay-tests that referenced this issue May 31, 2021
dawitengageiq pushed a commit to dawitengageiq/NLR that referenced this issue Sep 29, 2023
debaste pushed a commit to debaste/yii that referenced this issue Nov 25, 2023
psrpinto added a commit to psrpinto/GlotPress that referenced this issue Jan 10, 2024
psrpinto added a commit to psrpinto/GlotPress that referenced this issue Jan 10, 2024
psrpinto added a commit to psrpinto/GlotPress that referenced this issue Jan 10, 2024
psrpinto added a commit to psrpinto/GlotPress that referenced this issue Jan 10, 2024
psrpinto added a commit to psrpinto/GlotPress that referenced this issue Jan 10, 2024
amieiro added a commit to GlotPress/GlotPress that referenced this issue Jan 11, 2024
* Add npm command to run tests in wp-env

* Add a base env:tests-cmd script

* Run composer install before running tests

* Upgrade phpunit to 8.5 (latest 8.* minor release)

* Void return type must now be specified in certain test methods

See 'Return Type of Template Methods' at https://phpunit.de/announcements/phpunit-8.html

* Remove calls to deprecated assertInternalType()

See sebastianbergmann/phpunit#3368

* Don't generate test cache file

* Don't use depreacated canonicalize parameter of assertEquals()

* Using assertContains() with string haystacks is deprecated

* Upgrade phpunit to 9.6 (latest 9.* minor release)

* assertObjectHasAttribute() is deprecated in favour of assertObjectHasProperty()

* assertRegExp() is deprecated in favour of assertMatchesRegularExpression()

* Remove commented out code

* Only run tests against nightly once

* In GitHub actions, test under PHP 8.3 instead of 7.4

* Document jobs

* In GitHub actions, also test under PHP 7.4

* Add some PHPUnit workflows with PHP 7.4

* Expand GitHub workflows matrix, instead of specifying each job

---------

Co-authored-by: Jesús Amieiro Becerra <[email protected]>
adamfranco added a commit to middlebury/coursecatalog that referenced this issue Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

7 participants