Auto-complete in traits
Is it possible to make the IDE recognize that a trait will be used in a certain context? For example, I have a trait that adds more assertions for unit testing that looks like:
trait assertHeaders
{
protected function assertHeaderStatus($iStatusCode)
{
$this->assertEquals($iStatusCode, http_response_code());
}
protected function assertHeaderSet($strKey, $mValue)
{
$aHeaders = [];
foreach(xdebug_get_headers() as $strHeader)
{
$aHeader = explode(':',$strHeader);
$aHeaders[$aHeader[0]] = $aHeader[1];
}
$this->assertArrayHasKey($strKey, $aHeaders);
$this->assertContains($mValue, $aHeaders[$strKey]);
}
}
It will only ever be used in a unit testing context IE:class BaseControllerTest extends PHPUnit_Framework_TestCase
{
use assertHeaders;// Tests go here }
However, the assert calls within the trait are not recognized. I'm wondering if there's a way to make this possible? Some fancy docblock or setting I'm missing would be great. If not, the only way to make auto-complete work is to do say UnitTestAssertHeaders extends PHPUnit_Framework_TestCase, but this leads to not being able to easily use multiple custom assertions, since PHP does not allow multiple inheritance.
Please sign in to leave a comment.
Hi there,
https://youtrack.jetbrains.com/issue/WI-16368