Skip to content

Commit

Permalink
DisallowImplicitArrayCreationSniff: More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Oct 5, 2018
1 parent 9e97d4b commit 06d996b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -17,14 +17,16 @@ public function testErrors(): void
{
$report = self::checkFile(__DIR__ . '/data/disallowImplicitArrayCreationErrors.php');

self::assertSame(6, $report->getErrorCount());
self::assertSame(8, $report->getErrorCount());

self::assertSniffError($report, 3, DisallowImplicitArrayCreationSniff::CODE_IMPLICIT_ARRAY_CREATION_USED);
self::assertSniffError($report, 7, DisallowImplicitArrayCreationSniff::CODE_IMPLICIT_ARRAY_CREATION_USED);
self::assertSniffError($report, 13, DisallowImplicitArrayCreationSniff::CODE_IMPLICIT_ARRAY_CREATION_USED);
self::assertSniffError($report, 20, DisallowImplicitArrayCreationSniff::CODE_IMPLICIT_ARRAY_CREATION_USED);
self::assertSniffError($report, 27, DisallowImplicitArrayCreationSniff::CODE_IMPLICIT_ARRAY_CREATION_USED);
self::assertSniffError($report, 32, DisallowImplicitArrayCreationSniff::CODE_IMPLICIT_ARRAY_CREATION_USED);
self::assertSniffError($report, 30, DisallowImplicitArrayCreationSniff::CODE_IMPLICIT_ARRAY_CREATION_USED);
self::assertSniffError($report, 36, DisallowImplicitArrayCreationSniff::CODE_IMPLICIT_ARRAY_CREATION_USED);
self::assertSniffError($report, 41, DisallowImplicitArrayCreationSniff::CODE_IMPLICIT_ARRAY_CREATION_USED);
self::assertSniffError($report, 48, DisallowImplicitArrayCreationSniff::CODE_IMPLICIT_ARRAY_CREATION_USED);
}

}
15 changes: 15 additions & 0 deletions tests/Sniffs/Arrays/data/disallowImplicitArrayCreationErrors.php
Expand Up @@ -21,6 +21,15 @@ function differentScope()
})();
}

function differentScope2()
{
(function () {
$a = [];
})();

$a[] = 'a';
}

function parenthesesBefore()
{
$x = (10) + $value;
Expand All @@ -32,3 +41,9 @@ function variableReset()
$a[] = 'a';
$a = null;
}

function undefinedVariable()
{
$b = $a ? true : false;
$a[] = 2;
}

0 comments on commit 06d996b

Please sign in to comment.