Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Mar 25, 2020
1 parent 6d6abc1 commit fe75d2d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
23 changes: 18 additions & 5 deletions tests/Helpers/ClassHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use function array_values;
use const T_ANON_CLASS;
use const T_USE;
use const T_WHITESPACE;

class ClassHelperTest extends TestCase
{
Expand Down Expand Up @@ -55,21 +57,32 @@ public function testGetAllNamesWithNoClass(): void
public function testGetClassPointerWithoutClass(): void
{
$phpcsFile = $this->getCodeSnifferFile(__DIR__ . '/data/namespacedFile.php');
self::assertNull(ClassHelper::getClassPointer($phpcsFile, 5));

$usePointer = $this->findPointerByLineAndType($phpcsFile, 5, T_USE);
self::assertNotNull($usePointer);
self::assertNull(ClassHelper::getClassPointer($phpcsFile, $usePointer));
}

public function testGetClassPointerWithClass(): void
{
$phpcsFile = $this->getCodeSnifferFile(__DIR__ . '/data/classWithoutNamespace.php');
self::assertEquals(2, ClassHelper::getClassPointer($phpcsFile, 5));

$whitespacePointer = $this->findPointerByLineAndType($phpcsFile, 5, T_WHITESPACE);
self::assertNotNull($whitespacePointer);
self::assertSame(2, ClassHelper::getClassPointer($phpcsFile, $whitespacePointer));
}

public function testGetClassPointerWithMultipleClasses(): void
{
$phpcsFile = $this->getCodeSnifferFile(__DIR__ . '/data/multipleClasses.php');
self::assertEquals(2, ClassHelper::getClassPointer($phpcsFile, 5));
self::assertEquals(26, ClassHelper::getClassPointer($phpcsFile, 30));
self::assertEquals(51, ClassHelper::getClassPointer($phpcsFile, 52));

$methodInFooPointer = $this->findFunctionPointerByName($phpcsFile, 'methodInFoo');
self::assertNotNull($methodInFooPointer);
self::assertSame(2, ClassHelper::getClassPointer($phpcsFile, $methodInFooPointer));

$methodInBarPointer = $this->findFunctionPointerByName($phpcsFile, 'methodInBar');
self::assertNotNull($methodInBarPointer);
self::assertSame(28, ClassHelper::getClassPointer($phpcsFile, $methodInBarPointer));
}

}
19 changes: 6 additions & 13 deletions tests/Helpers/data/multipleClasses.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
<?php

class Foo {
public function test()
class Foo
{

public function methodInFoo()
{
}

}

class Bar
{
public function test()
{
}
}


class Zoo
{
public function test()
public function methodInBar()
{
}

public function test1()
{
}
}

0 comments on commit fe75d2d

Please sign in to comment.