Skip to content

Commit fd9de4b

Browse files
committed
ReferenceUsedNamesOnlySniff - test for $allowFullyQualifiedExceptions=false in file with namespace
1 parent f4c1d43 commit fd9de4b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

tests/Sniffs/Namespaces/ReferenceUsedNamesOnlySniffTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,31 @@ public function testCreatingObjectFromSpecialExceptionName()
5353
$this->assertNoSniffError($report, 12);
5454
}
5555

56+
public function testReportFullyQualifiedInFileWithNamespace()
57+
{
58+
$report = $this->checkFile(
59+
__DIR__ . '/data/shouldBeInUseStatement.php'
60+
);
61+
$this->assertSniffError(
62+
$report,
63+
13,
64+
ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME,
65+
'\Some\CommonException'
66+
);
67+
$this->assertSniffError(
68+
$report,
69+
14,
70+
ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME,
71+
'\Exception'
72+
);
73+
$this->assertSniffError(
74+
$report,
75+
15,
76+
ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME,
77+
'\Nette\Object'
78+
);
79+
}
80+
5681
public function testDoNotAllowFullyQualifiedExtends()
5782
{
5883
$report = $this->checkFile(

tests/Sniffs/Namespaces/data/shouldBeInUseStatement.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public function bar()
1010
new Lorem();
1111
$constant = \Some\ConstantClass::CONSTANT;
1212
new \Foo\SomeError();
13+
new \Some\CommonException();
14+
new \Exception();
15+
new \Nette\Object();
1316
}
1417

1518
}

0 commit comments

Comments
 (0)