$ php -v):PHP 7.2.11-2+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Oct 15 2018 11:40:35) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.11-2+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
$ php-cs-fixer -V):PHP CS Fixer 2.13.0 Yogi's BBQ by Fabien Potencier and Dariusz Ruminski (7136aa4)
php-cs-fixer fix
<?php
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'php_unit_no_expectation_annotation' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
)
;
<?php
declare(strict_types=1);
namespace MyApp\Tests;
use PHPUnit\Framework\TestCase;
use MyApp\MyException;
final class MyTest extends TestCase
{
/**
* @expectedException \MyApp\MyException
* @expectedExceptionMessage Test message.
*/
public function testThrowsException(): void
{
throw new MyException;
}
}
<?php
declare(strict_types=1);
namespace MyApp\Tests;
use PHPUnit\Framework\TestCase;
use MyApp\MyException;
final class MyTest extends TestCase
{
/**
*/
public function testThrowsException(): void
{
$this->setExpectedException(\MyApp\MyException::class, 'Test message.');
throw new MyException;
}
}
<?php
declare(strict_types=1);
namespace MyApp\Tests;
use PHPUnit\Framework\TestCase;
use MyApp\MyException;
final class MyTest extends TestCase
{
public function testThrowsException(): void
{
$this->setExpectedException(MyException::class, 'Test message.');
throw new MyException;
}
}
Hi @emodric ,
Thanks for the report! Your request seems like a good improvement to the project so i like to keep it open :)
We're kind of busy with PR's and issues at the moment so it might take some time before someone picks this up, do you plan to give it a shot with a PR to bring this improvement in?
Hi @SpacePossum
I can try to pick it up if I will have some free time, sure! :+1:
IMO, this could be a new fixer, as the behaviour is useful outside of the php_unit_no_expectation_annotation fixer. Your thoughts?
It would be incredibly helpful to have a general fixer to automatically import namespaces. I stupidly thought GlobalNamespaceImportFixer was supposed to do that before I realized my obvious mistake, but it seems like much of the work is already done there, it just needs to be extended to all namespaces. This would also duplicate the FullyQualifiedStrictTypesFixer. I created a simple testcase based on the GlobalNamespaceImportFixerTest:
return [
'with same namespace' => [
<<<'EXPECTED'
<?php
namespace Test;
use foo;
new Foo();
Bar::baz();
/** @return Baz<string, foo> */
function x() {}
EXPECTED
,
<<<'INPUT'
<?php
namespace Test;
new \Foo();
\Test\Bar::baz();
/** @return \Test\Baz<string, \foo> */
function x() {}
INPUT
],
'with child namespace' => [
<<<'EXPECTED'
<?php
namespace Test;
use Test\Child\Bar;
use Test\Child\Baz;
use foo;
new Foo();
Bar::baz();
/** @return Baz<string, foo> */
function x() {}
EXPECTED
,
<<<'INPUT'
<?php
namespace Test;
new \Foo();
\Test\Child\Bar::baz();
/** @return \Test\Child\Baz<string, \foo> */
function x() {}
INPUT
],
];
Most helpful comment
IMO, this could be a new fixer, as the behaviour is useful outside of the php_unit_no_expectation_annotation fixer. Your thoughts?