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

Commit a2cec18

Browse files
committed
Enhancement: Assert that locator ignores anonymous classes
1 parent e925fb2 commit a2cec18

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

test/ClassFileLocatorTest.php

+27-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* Zend Framework (http://framework.zend.com/)
44
*
55
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
6+
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
77
* @license http://framework.zend.com/license/new-bsd New BSD License
88
*/
99

1010
namespace ZendTest\File;
1111

1212
use Zend\File\ClassFileLocator;
1313
use Zend\File\Exception;
14+
use Zend\File\PhpClassFile;
1415

1516
/**
1617
* Test class for Zend\File\ClassFileLocator
@@ -147,4 +148,29 @@ public function testIterationShouldNotCountFQCNScalarResolutionConstantAsClass()
147148
$this->assertCount(1, $file->getClasses());
148149
}
149150
}
151+
152+
/**
153+
* @requires PHP 7.1
154+
*/
155+
public function testIgnoresAnonymousClasses()
156+
{
157+
$classFileLocator = new ClassFileLocator(__DIR__ . '/TestAsset/Anonymous');
158+
159+
$classFiles = \iterator_to_array($classFileLocator);
160+
161+
$this->assertCount(1, $classFiles);
162+
163+
$classNames = \array_reduce($classFiles, function (array $classNames, PhpClassFile $classFile) {
164+
return \array_merge(
165+
$classNames,
166+
$classFile->getClasses()
167+
);
168+
}, []);
169+
170+
$expected = [
171+
TestAsset\Anonymous\WithAnonymousClass::class,
172+
];
173+
174+
$this->assertEquals($expected, $classNames);
175+
}
150176
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Zend Framework (http://framework.zend.com/)
5+
*
6+
* @link https://github.com/zendframework/zend-file for the canonical source repository
7+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
8+
* @license https://github.com/zendframework/zend-file/blob/master/LICENSE.md New BSD License
9+
*/
10+
11+
namespace ZendTest\File\TestAsset\Anonymous;
12+
13+
final class WithAnonymousClass
14+
{
15+
private $anonymous;
16+
17+
public function __construct()
18+
{
19+
$this->anonymous = new class extends \stdClass {
20+
21+
};
22+
}
23+
}
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/**
4+
* Zend Framework (http://framework.zend.com/)
5+
*
6+
* @link https://github.com/zendframework/zend-file for the canonical source repository
7+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
8+
* @license https://github.com/zendframework/zend-file/blob/master/LICENSE.md New BSD License
9+
*/
10+
11+
$anonymous = new class extends \stdClass {
12+
13+
};

0 commit comments

Comments
 (0)