My aim in making Testify was to make my life easier and that, in the strict environment of “writing PHPUnit tests for PHP classes”, meant automating the most boring task that could be automated in the fun (I mean it) process of testing code: writing tests.
At least their bones.
At first Testify did not speak my language
Some time ago (3 days in this moment) I knew nearly nothing about Python and Sublime Text plugins but did know I wanted to select multiple lines of natural language and see them transformed into test code.
My first implementation of Testify
did that but using the ugly #
symbol to work.
That was not my language.
should throw exception for #bad arguments
Now it speaks my language
I’m surely too proud of Testify
latest incarnation but I do like that the sentence above
should throw exception for bad arguments
will translate, without using any hashtag, into
public function badArgumentsProvider()
{
return array(
// $badArguments
);
}
/**
* @dataProvider badArgumentsProvider
*/
public function testShouldThrowExceptionForBadArguments($badArguments)
{
$this->markTestIncomplete('This test has not been implemented yet.');
}
Specifically the plugin will pick up for
and with
as the introduction to a string of variables supplied by some kind of data provider and will generate an adequate data provider method. And will accept multiple variables too
method will return string for string, int and array
translates into
public function stringIntArrayProvider()
{
return array(
// $string, $int, $array
);
}
/**
* @dataProvider stringIntArrayProvider
*/
public function testMethodWillReturnStringForStringIntAndArray($string, $int, $array)
{
$this->markTestIncomplete('This test has not been implemented yet.');
}
It’s also very smart
The plugin will also avoid creating duplicate data provider methods if the same data provider method is requested by more than one test method
method one will throw for string key and int value
method two will throw for string key and int value
will translate
public function stringKeyIntValueProvider()
{
return array(
// $stringKey, $intValue
);
}
/**
* @dataProvider stringKeyIntValueProvider
*/
public function testMethodOneWillThrowForStringKeyAndIntValue($stringKey, $intValue)
{
$this->markTestIncomplete('This test has not been implemented yet.');
}
/**
* @dataProvider stringKeyIntValueProvider
*/
public function testMethodTwoWillThrowForStringKeyAndIntValue($stringKey, $intValue)
{
$this->markTestIncomplete('This test has not been implemented yet.');
}
There is some refactoring to do and, ironically, some testing but so far so good.