-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for autoloader class name detection
- Loading branch information
Showing
7 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
/** | ||
* Tests for the \PHP_CodeSniffer\Util\Common::isCamelCaps method. | ||
* | ||
* @author Greg Sherwood <gsherwood@squiz.net> | ||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) | ||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | ||
*/ | ||
|
||
namespace PHP_CodeSniffer\Tests\Core\Autoloader; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class DetermineLoadedClassTest extends TestCase | ||
{ | ||
|
||
|
||
/** | ||
* Load the test files. | ||
* | ||
* @return void | ||
*/ | ||
public static function setUpBeforeClass() | ||
{ | ||
include __DIR__.'/TestFiles/Sub/C.inc'; | ||
|
||
}//end setUpBeforeClass() | ||
|
||
|
||
/** | ||
* Test for when class list is ordered. | ||
* | ||
* @return void | ||
*/ | ||
public function testOrdered() | ||
{ | ||
$classesBeforeLoad = [ | ||
'classes' => [], | ||
'interfaces' => [], | ||
'traits' => [], | ||
]; | ||
|
||
$classesAfterLoad = [ | ||
'classes' => [ | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\A', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\B', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\C', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', | ||
], | ||
'interfaces' => [], | ||
'traits' => [], | ||
]; | ||
|
||
$className = \PHP_CodeSniffer\Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); | ||
$this->assertEquals('PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', $className); | ||
|
||
}//end testOrdered() | ||
|
||
|
||
/** | ||
* Test for when class list is out of order. | ||
* | ||
* @return void | ||
*/ | ||
public function testUnordered() | ||
{ | ||
$classesBeforeLoad = [ | ||
'classes' => [], | ||
'interfaces' => [], | ||
'traits' => [], | ||
]; | ||
|
||
$classesAfterLoad = [ | ||
'classes' => [ | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\A', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\C', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\B', | ||
], | ||
'interfaces' => [], | ||
'traits' => [], | ||
]; | ||
|
||
$className = \PHP_CodeSniffer\Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); | ||
$this->assertEquals('PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', $className); | ||
|
||
$classesAfterLoad = [ | ||
'classes' => [ | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\A', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\C', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\B', | ||
], | ||
'interfaces' => [], | ||
'traits' => [], | ||
]; | ||
|
||
$className = \PHP_CodeSniffer\Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); | ||
$this->assertEquals('PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', $className); | ||
|
||
$classesAfterLoad = [ | ||
'classes' => [ | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\A', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\C', | ||
'PHP_CodeSniffer\Tests\Core\Autoloader\B', | ||
], | ||
'interfaces' => [], | ||
'traits' => [], | ||
]; | ||
|
||
$className = \PHP_CodeSniffer\Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); | ||
$this->assertEquals('PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', $className); | ||
|
||
}//end testUnordered() | ||
|
||
|
||
}//end class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
namespace PHP_CodeSniffer\Tests\Core\Autoloader; | ||
class A {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
namespace PHP_CodeSniffer\Tests\Core\Autoloader; | ||
require 'A.inc'; | ||
class B extends A {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
namespace PHP_CodeSniffer\Tests\Core\Autoloader; | ||
require 'B.inc'; | ||
class C extends B {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
namespace PHP_CodeSniffer\Tests\Core\Autoloader\Sub; | ||
require __DIR__.'/../C.inc'; | ||
use PHP_CodeSniffer\Tests\Core\Autoloader\C as ParentC; | ||
class C extends ParentC {} |