Skip to content

Commit b81ac84

Browse files
committed
Slevomat.Namespaces.ReferenceUsedNamesOnly: More tests
1 parent 8d3d569 commit b81ac84

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

tests/Sniffs/Namespaces/ReferenceUsedNamesOnlySniffTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,4 +1031,19 @@ public function testAttributes(): void
10311031
self::assertAllFixedInFile($report);
10321032
}
10331033

1034+
public function testWithSubNamespaces(): void
1035+
{
1036+
$report = self::checkFile(__DIR__ . '/data/referenceUsedNamesOnlyWithSubNamespaces.php', [
1037+
'searchAnnotations' => true,
1038+
'allowPartialUses' => true,
1039+
]);
1040+
1041+
self::assertSame(3, $report->getErrorCount());
1042+
1043+
self::assertSniffError($report, 12, ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME);
1044+
self::assertSniffError($report, 17, ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME);
1045+
1046+
self::assertAllFixedInFile($report);
1047+
}
1048+
10341049
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Whatever;
4+
5+
use F\Q\N;
6+
use Some\SubNamespace;
7+
use Some\SubNamespace\A;
8+
use Some\SubNamespace\B;
9+
10+
class Foo
11+
{
12+
13+
public function test()
14+
{
15+
return SubNamespace::class;
16+
}
17+
18+
public function test2()
19+
{
20+
/** @var A|B $test */
21+
$test = null;
22+
}
23+
24+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Whatever;
4+
5+
use F\Q\N;
6+
7+
class Foo
8+
{
9+
10+
public function test()
11+
{
12+
return \Some\SubNamespace::class;
13+
}
14+
15+
public function test2()
16+
{
17+
/** @var \Some\SubNamespace\A|\Some\SubNamespace\B $test */
18+
$test = null;
19+
}
20+
21+
}

0 commit comments

Comments
 (0)