Implement
assertIsArray()assertIsBool()assertIsFloat()assertIsInt()assertIsNumeric()assertIsObject()assertIsResource()assertIsString()assertIsScalar()assertIsCallable()assertIsIterable()assertIsNotArray()assertIsNotBool()assertIsNotFloat()assertIsNotInt()assertIsNotNumeric()assertIsNotObject()assertIsNotResource()assertIsNotString()assertIsNotScalar()assertIsNotCallable()assertIsNotIterable()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
What will happen to same checks just for arrays?
$this->assertContainsOnly('string', $types);
what phpunit min version has the new assertions?
These assertions were implemented for PHPUnit 7.5.
what's the replacement for such code:
$this->assertInternalType(gettype($algo), $res['algo']);
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. :sweat_smile:
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.
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 https://github.com/sebastianbergmann/phpunit/commit/a406c85c51edd76ace29119179d8c21f590c939e#diff-9ae7a972d07df5f73629d5d315bf405a
Yo can create a trait with that methods and try to use it in your tests classes.
Thanks for the link. I asked here in the hope there already is a package that provides a copy.
what's the replacement for such code:
$this->assertInternalType(gettype($algo), $res['algo']);
$this->assertEquals(gettype($algo), gettype($res['algo']));
Most helpful comment
@glensc Maybe...
But... if you need this dynamic, you may need a redesign of the test. :sweat_smile: