Skip to content

Instantly share code, notes, and snippets.

@harmenjanssen
Created March 27, 2018 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harmenjanssen/d114ca40571e20069821817ef5f45663 to your computer and use it in GitHub Desktop.
Save harmenjanssen/d114ca40571e20069821817ef5f45663 to your computer and use it in GitHub Desktop.
Use `@dataProvider` to quickly pass a bunch of invalid input through your function to make sure it fails correctly.
<?php
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase {
/**
* @dataProvider invalidArgumentProvider
* @expectedException InvalidArgumentException
*/
public function test_should_throw_on_invalid_arguments($arg) {
my_func($arg);
}
public function invalidArgumentProvider() {
return [
[new stdClass],
[true],
[999]
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment