Skip to content

Commit aded39c

Browse files
committed
Refactoring unit testing
1 parent 4fff9e1 commit aded39c

38 files changed

+396
-543
lines changed

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<testsuites>
55
<testsuite name="alltest">
6-
<file>tests/AllTests.php</file>
6+
<directory suffix="Test.php">tests/Sniffs</directory>
77
</testsuite>
88
</testsuites>
99
</phpunit>

tests/AllTests.php

-28
This file was deleted.

tests/CSAbstractSniffUnitTest.php

-125
This file was deleted.

tests/CSTestEntity.php

-46
This file was deleted.
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
$myArray ['key'] = $value;
34
$myArray[ 'key'] = $value;
45
$myArray['key' ] = $value;

tests/Inc/Arrays/ArrayDeclaration.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
$array = array ();
44

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
$var = 'Hello'. ' World';
4-
5-
// No Error
6-
$var = 'Hello'
7-
. ' World';

tests/Inc/Strings/DoubleQuoteUsage.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
$var = "Hello world!";
44
$var = "Hello $there";

tests/Inc/Strings/EchoedStrings.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
echo('hello');

tests/Inc/WhiteSpace/CastSpacing.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

3-
$var = ( int ) "1";
3+
$var = ( int ) '1';

tests/Inc/WhiteSpace/FunctionOpeningBraceSpace.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
function MyFunction1()
44
{

tests/Inc/WhiteSpace/FunctionSpacing.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
class Test
44
{
@@ -22,4 +22,4 @@ function testA()
2222
function testB()
2323
{}
2424

25-
echo 'test';
25+
$a = new stdClass();

tests/Inc/WhiteSpace/LanguageConstructSpacing.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
require$blah;
44
require $blah;

tests/Inc/WhiteSpace/LogicalOperatorSpacing.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
if ($foo|| $bar) {}
44
if ($foo ||$bar) {}

tests/Inc/WhiteSpace/MemberVarSpacing.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
class Testing
44
{

tests/Inc/WhiteSpace/ObjectOperatorSpacing.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
$this ->testThis();
44
$this-> testThis();

tests/Inc/WhiteSpace/OperatorSpacing.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
$varA= 1 + 2;
44
$varA =1 + 2;

tests/Inc/WhiteSpace/ScopeIndent.inc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
/**
34
* Block comment
45
*/

tests/Sniffs/AbstractTestCase.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PhpCodeConv\Tests\Sniffs;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
abstract class AbstractTestCase extends TestCase
8+
{
9+
10+
/** @var Validator */
11+
private static $validator;
12+
13+
abstract protected function getFilename() : string;
14+
15+
/** @phpstan-ignore-next-line */
16+
final public function __construct($name = null, array $data = [], $dataName = '')
17+
{
18+
parent::__construct($name, $data, $dataName);
19+
}
20+
21+
/** @return string[] */
22+
protected function getExcludeSniff() : array
23+
{
24+
return [];
25+
}
26+
27+
/** @return void */
28+
final public static function setUpBeforeClass()
29+
{
30+
self::$validator = new Validator();
31+
32+
$filepath = dirname(__DIR__) . '/Inc/' . (new static)->getFilename();
33+
34+
self::$validator->setFile($filepath, (new static)->getExcludeSniff());
35+
}
36+
37+
/** @return void */
38+
final public static function tearDownAfterClass()
39+
{
40+
if (self::$validator->errorCount() > 0) {
41+
printf("\n\n");
42+
self::$validator->printError();
43+
}
44+
45+
self::assertEquals(0, self::$validator->errorCount());
46+
}
47+
48+
/** @return void */
49+
final protected function checkSniff(int $line, int $column, string $sniff, string $message)
50+
{
51+
$key = SniffEntity::createKey($line, $column, $sniff);
52+
53+
$this->assertTrue(self::$validator->hasKey($key));
54+
$this->assertSame($message, self::$validator->getMessage($key));
55+
56+
self::$validator->removeItem($key);
57+
}
58+
}

0 commit comments

Comments
 (0)