-
Notifications
You must be signed in to change notification settings - Fork 78
Additional blank lines make generated class not PSR2 compliant #135
Comments
@JuJuDropThor can you maybe write a test that verifies PSR-2 compliance of generated code? |
I'm not sure I understand what you asked. You want to know how I checked if the generated code was PSR-2 compliant ? I just ran phpcs with --standard=PSR2 argument. |
@JuJuDropThor yes, what we'd need is a test that automates such a check |
Sure. See the code below :
|
Hello guys Any news ? Tell me if you need more code. |
@JuJuDropThor what would be needed is to turn this into a proper test case. |
Something like this class works for testing various generated code: use PHPUnit\Framework\TestCase;
use Zend\Code\Generator\ClassGenerator;
use Zend\Code\Generator\FileGenerator;
class Psr2ComplianceTest extends TestCase
{
public function testEmptyClassCompliance()
{
$classGenerator = new ClassGenerator('Bar', 'Foo');
$fileGenerator = new FileGenerator();
$fileGenerator->setClass($classGenerator);
$generatedCode = $fileGenerator->generate();
$codeSniffer = new \PHP_CodeSniffer();
$codeSniffer->initStandard('PSR2');
$report = $codeSniffer->processFile('', $generatedCode);
$this->assertEquals(0, $report->getErrorCount());
$this->assertEquals(0, $report->getWarningCount());
}
} I'll write some tests for various generated code later. |
Hello I added your unit test and ran it with phpunit ./test/Psr2ComplianceTest. See bellow what I got
$report->getErrorCount() return 1. But it's strange because $report->getErrors() return an empty array |
That one is obvious, you have 2 blank lines but it expects 0 blank lines, that is ok.
This also seems obvious, how many blank lines did you actually have? |
This repository has been closed and moved to laminas/laminas-code; a new issue has been opened at laminas/laminas-code#10. |
Hi guys
I saw PSR2 issues when generating classes.
See errors below
I post you an exemple which generate these errors
The text was updated successfully, but these errors were encountered: