Skip to content

Commit

Permalink
Slevomat.Namespaces.ReferenceUsedNamesOnly: More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Dec 7, 2021
1 parent 8d3d569 commit b81ac84
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/Sniffs/Namespaces/ReferenceUsedNamesOnlySniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1031,4 +1031,19 @@ public function testAttributes(): void
self::assertAllFixedInFile($report);
}

public function testWithSubNamespaces(): void
{
$report = self::checkFile(__DIR__ . '/data/referenceUsedNamesOnlyWithSubNamespaces.php', [
'searchAnnotations' => true,
'allowPartialUses' => true,
]);

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

self::assertSniffError($report, 12, ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME);
self::assertSniffError($report, 17, ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME);

self::assertAllFixedInFile($report);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Whatever;

use F\Q\N;
use Some\SubNamespace;
use Some\SubNamespace\A;
use Some\SubNamespace\B;

class Foo
{

public function test()
{
return SubNamespace::class;
}

public function test2()
{
/** @var A|B $test */
$test = null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Whatever;

use F\Q\N;

class Foo
{

public function test()
{
return \Some\SubNamespace::class;
}

public function test2()
{
/** @var \Some\SubNamespace\A|\Some\SubNamespace\B $test */
$test = null;
}

}

0 comments on commit b81ac84

Please sign in to comment.