3 * This file is part of the PHP_TokenStream package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Tests for the PHP_Token_CLASS class.
14 * @package PHP_TokenStream
16 * @author Laurent Laville <pear@laurent-laville.org>
17 * @copyright Sebastian Bergmann <sebastian@phpunit.de>
18 * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
19 * @version Release: @package_version@
20 * @link http://github.com/sebastianbergmann/php-token-stream/
21 * @since Class available since Release 1.0.2
23 class PHP_Token_ClassTest extends PHPUnit_Framework_TestCase
28 protected function setUp()
30 $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source2.php');
32 foreach ($ts as $token) {
33 if ($token instanceof PHP_Token_CLASS) {
34 $this->class = $token;
37 if ($token instanceof PHP_Token_FUNCTION) {
38 $this->function = $token;
45 * @covers PHP_Token_CLASS::getKeywords
47 public function testGetClassKeywords()
49 $this->assertEquals('abstract', $this->class->getKeywords());
53 * @covers PHP_Token_FUNCTION::getKeywords
55 public function testGetFunctionKeywords()
57 $this->assertEquals('abstract,static', $this->function->getKeywords());
61 * @covers PHP_Token_FUNCTION::getVisibility
63 public function testGetFunctionVisibility()
65 $this->assertEquals('public', $this->function->getVisibility());
68 public function testIssue19()
70 $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'issue19.php');
72 foreach ($ts as $token) {
73 if ($token instanceof PHP_Token_CLASS) {
74 $this->assertFalse($token->hasInterfaces());
79 public function testIssue30()
81 $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'issue30.php');
82 $this->assertCount(1, $ts->getClasses());
88 public function testAnonymousClassesAreHandledCorrectly()
90 $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_that_declares_anonymous_class.php');
92 $classes = $ts->getClasses();
94 $this->assertEquals(array('class_with_method_that_declares_anonymous_class'), array_keys($classes));
99 * @ticket https://github.com/sebastianbergmann/php-token-stream/issues/52
101 public function testAnonymousClassesAreHandledCorrectly2()
103 $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_that_declares_anonymous_class2.php');
105 $classes = $ts->getClasses();
107 $this->assertEquals(array('Test'), array_keys($classes));
108 $this->assertEquals(array('methodOne', 'methodTwo'), array_keys($classes['Test']['methods']));
110 $this->assertEmpty($ts->getFunctions());
116 public function testImportedFunctionsAreHandledCorrectly()
118 $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'classUsesNamespacedFunction.php');
120 $this->assertEmpty($ts->getFunctions());
121 $this->assertCount(1, $ts->getClasses());