TASK: Improve tests
* Allow phpcbf / diff to be optional, as not all tests are fixable. * Provide more information in case of error. * Provide phpunit dist to run phpunit without anything special. Relates: #46
This commit is contained in:
parent
7c35998c62
commit
b23ee6ef8b
5 changed files with 192 additions and 17 deletions
23
phpunit.xml.dist
Normal file
23
phpunit.xml.dist
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Project Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
26
tests/FileNotFoundException.php
Normal file
26
tests/FileNotFoundException.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Typo3Update\Tests;
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
class FileNotFoundException extends \Exception
|
||||
{
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
"files": {
|
||||
"InputFileForIssues.php": {
|
||||
"errors": 6,
|
||||
"messages": [
|
||||
{
|
||||
"column": 34,
|
||||
"fixable": true,
|
||||
"line": 22,
|
||||
"message": "Legacy classes are not allowed; found \"Tx_Extbase_Configuration_Configurationmanager\", use \"TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager\" instead",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname",
|
||||
"type": "ERROR"
|
||||
},
|
||||
{
|
||||
"column": 91,
|
||||
"fixable": true,
|
||||
"line": 22,
|
||||
"message": "Legacy classes are not allowed; found \"t3lib_Singleton\", use \"TYPO3\\CMS\\Core\\SingletonInterface\" instead",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname",
|
||||
"type": "ERROR"
|
||||
},
|
||||
{
|
||||
"column": 108,
|
||||
"fixable": true,
|
||||
"line": 22,
|
||||
"message": "Legacy classes are not allowed; found \"Tx_Extbase_Core_BootstrapInterface\", use \"TYPO3\\CMS\\Extbase\\Core\\BootstrapInterface\" instead",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname",
|
||||
"type": "ERROR"
|
||||
},
|
||||
{
|
||||
"column": 34,
|
||||
"fixable": true,
|
||||
"line": 27,
|
||||
"message": "Legacy classes are not allowed; found \"Tx_Extbase_Configuration_Configurationmanager\", use \"TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager\" instead",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname",
|
||||
"type": "ERROR"
|
||||
},
|
||||
{
|
||||
"column": 5,
|
||||
"fixable": true,
|
||||
"line": 28,
|
||||
"message": "Legacy classes are not allowed; found \"t3lib_Singleton\", use \"TYPO3\\CMS\\Core\\SingletonInterface\" instead",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname",
|
||||
"type": "ERROR"
|
||||
},
|
||||
{
|
||||
"column": 5,
|
||||
"fixable": true,
|
||||
"line": 29,
|
||||
"message": "Legacy classes are not allowed; found \"Tx_Extbase_Core_BootstrapInterface\", use \"TYPO3\\CMS\\Extbase\\Core\\BootstrapInterface\" instead",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname",
|
||||
"type": "ERROR"
|
||||
}
|
||||
],
|
||||
"warnings": 0
|
||||
}
|
||||
},
|
||||
"totals": {
|
||||
"errors": 6,
|
||||
"fixable": 6,
|
||||
"warnings": 0
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
class InputFileForIssues extends Tx_Extbase_Configuration_Configurationmanager implements t3lib_Singleton, Tx_Extbase_Core_BootstrapInterface
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class InputFileForIssues extends Tx_Extbase_Configuration_Configurationmanager implements
|
||||
t3lib_Singleton,
|
||||
Tx_Extbase_Core_BootstrapInterface
|
||||
{
|
||||
|
||||
}
|
|
@ -66,18 +66,24 @@ class SniffsTest extends TestCase
|
|||
$this->assertEquals(
|
||||
$this->getExpectedJsonOutput($folder),
|
||||
$this->getOutput($folder, 'json')['output'],
|
||||
'Sniff ' . $this->getSniffByFolder($folder)
|
||||
'Checking Sniff "' . $this->getSniffByFolder($folder) . '"'
|
||||
. ' did not produce expected output for input file '
|
||||
. $this->getInputFile($folder)
|
||||
. ' called: ' . $this->getPhpcsCall($folder, 'json')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->getExpectedDiffOutput($folder),
|
||||
$this->getOutput($folder, 'diff')['output'],
|
||||
'Sniff ' . $this->getSniffByFolder($folder)
|
||||
. ' did not produce expected diff for input file '
|
||||
. $this->getInputFile($folder)
|
||||
);
|
||||
try {
|
||||
$this->assertEquals(
|
||||
$this->getExpectedDiffOutput($folder),
|
||||
$this->getOutput($folder, 'diff')['output'],
|
||||
'Fixing Sniff "' . $this->getSniffByFolder($folder) . '"'
|
||||
. ' did not produce expected diff for input file '
|
||||
. $this->getInputFile($folder)
|
||||
. ' called: ' . $this->getPhpcsCall($folder, 'diff')
|
||||
);
|
||||
} catch (FileNotFoundException $e) {
|
||||
// Ok, ignore, we don't have an diff.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,10 +105,17 @@ class SniffsTest extends TestCase
|
|||
*
|
||||
* @param SplFileInfo $folder
|
||||
* @return string
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
protected function getExpectedDiffOutput(SplFileInfo $folder)
|
||||
{
|
||||
return file_get_contents($folder->getRealPath() . DIRECTORY_SEPARATOR . 'Expected.diff');
|
||||
$file = $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Expected.diff';
|
||||
if (!is_file($file)) {
|
||||
throw new FileNotFoundException('File does not exist.', 1491469621);
|
||||
}
|
||||
|
||||
return file_get_contents($file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,6 +144,25 @@ class SniffsTest extends TestCase
|
|||
return $folder->getRealPath() . DIRECTORY_SEPARATOR . 'InputFileForIssues.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build cli call for phpcs.
|
||||
*
|
||||
* @param SplFileInfo $folder
|
||||
* @param string $report Defined the report format to use for output.
|
||||
* @return string
|
||||
*/
|
||||
protected function getPhpcsCall(SplFileInfo $folder, $report)
|
||||
{
|
||||
$bin = './vendor/bin/phpcs';
|
||||
$arguments = '--sniffs=' . $this->getSniffByFolder($folder)
|
||||
. ' --report=' . $report
|
||||
. ' '
|
||||
. $this->getInputFile($folder)
|
||||
;
|
||||
|
||||
return $bin . ' ' . $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes phpcs for sniff based on $folder and returns the generated output.
|
||||
*
|
||||
|
@ -140,16 +172,9 @@ class SniffsTest extends TestCase
|
|||
*/
|
||||
protected function getOutput(SplFileInfo $folder, $report)
|
||||
{
|
||||
$bin = './vendor/bin/phpcs';
|
||||
$arguments = '--sniffs=' . $this->getSniffByFolder($folder)
|
||||
. ' --report=' . $report
|
||||
. ' '
|
||||
. $this->getInputFile($folder)
|
||||
;
|
||||
$output = '';
|
||||
$returnValue;
|
||||
|
||||
exec($bin . ' ' . $arguments, $output, $returnValue);
|
||||
exec($this->getPhpcsCall($folder, $report), $output, $returnValue);
|
||||
|
||||
if ($report === 'json') {
|
||||
$output = $this->prepareJsonOutput($output);
|
||||
|
|
Loading…
Reference in a new issue