Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit a97ef49

Browse files
committed
Merge branch 'hotfix/#3-support-instantiable-introspection-with-traits' into develop
Close #3 Forward port #3
2 parents 1cf4d81 + 6c806e1 commit a97ef49

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Scanner/ClassScanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function isTrait()
236236
public function isInstantiable()
237237
{
238238
$this->scan();
239-
return (!$this->isAbstract && !$this->isInterface);
239+
return (!$this->isAbstract && !$this->isInterface && !$this->isTrait);
240240
}
241241

242242
/**

test/Scanner/ClassScannerTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,36 @@ public function testGetMethodsThrowsExceptionOnDuplicateMethods()
274274

275275
$class->getMethods();
276276
}
277+
278+
public function testClassIsInstantiable()
279+
{
280+
$file = new FileScanner(__DIR__ . '/../TestAsset/FooBarClass.php');
281+
$class = $file->getClass('ZendTest_Code_TestAsset_FooBar');
282+
$this->assertFalse($class->isAbstract());
283+
$this->assertTrue($class->isInstantiable());
284+
}
285+
286+
public function testAbstractClassIsNotInstantiable()
287+
{
288+
$file = new FileScanner(__DIR__ . '/../TestAsset/FooClass.php');
289+
$class = $file->getClass('ZendTest\Code\TestAsset\FooClass');
290+
$this->assertTrue($class->isAbstract());
291+
$this->assertFalse($class->isInstantiable());
292+
}
293+
294+
public function testInterfaceIsNotInstantiable()
295+
{
296+
$file = new FileScanner(__DIR__ . '/../TestAsset/FooInterface.php');
297+
$class = $file->getClass('ZendTest\Code\TestAsset\FooInterface');
298+
$this->assertTrue($class->isInterface());
299+
$this->assertFalse($class->isInstantiable());
300+
}
301+
302+
public function testTraitIsNotInstantiable()
303+
{
304+
$file = new FileScanner(__DIR__ . '/../TestAsset/FooTrait.php');
305+
$class = $file->getClass('ZendTest\Code\TestAsset\FooTrait');
306+
$this->assertTrue($class->isTrait());
307+
$this->assertFalse($class->isInstantiable());
308+
}
277309
}

0 commit comments

Comments
 (0)