1
0
mirror of https://github.com/danog/class-finder.git synced 2024-11-30 04:29:03 +01:00

Add failing unit test proving that countMatchingSegments is misbehaving

This commit is contained in:
Hayden Pierce 2018-09-09 12:47:24 -05:00
parent 5a71485482
commit 8b67568fcd
4 changed files with 302 additions and 28 deletions

View File

@ -14,11 +14,13 @@
"ext-json": "*" "ext-json": "*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "4.8.36" "phpunit/phpunit": "4.8.36",
"mikey179/vfsStream": "^1.6"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"HaydenPierce\\ClassFinder\\": "src/" "HaydenPierce\\ClassFinder\\": "src/",
"HaydenPierce\\ClassFinder\\UnitTest\\": "test/unit"
} }
} }
} }

263
composer.lock generated
View File

@ -1,10 +1,10 @@
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "3b2eddc1d92027b147b147fcc217e83c", "content-hash": "f3f590855bb74189d0c049ef88784132",
"packages": [], "packages": [],
"packages-dev": [ "packages-dev": [
{ {
@ -62,38 +62,139 @@
"time": "2015-06-14T21:17:01+00:00" "time": "2015-06-14T21:17:01+00:00"
}, },
{ {
"name": "phpdocumentor/reflection-docblock", "name": "mikey179/vfsStream",
"version": "2.0.5", "version": "v1.6.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", "url": "https://github.com/mikey179/vfsStream.git",
"reference": "e6a969a640b00d8daa3c66518b0405fb41ae0c4b" "reference": "d5fec95f541d4d71c4823bb5e30cf9b9e5b96145"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/e6a969a640b00d8daa3c66518b0405fb41ae0c4b", "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
"reference": "e6a969a640b00d8daa3c66518b0405fb41ae0c4b", "reference": "d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.3" "php": ">=5.3.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.0" "phpunit/phpunit": "~4.5"
},
"suggest": {
"dflydev/markdown": "~1.0",
"erusev/parsedown": "~1.0"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.0.x-dev" "dev-master": "1.6.x-dev"
} }
}, },
"autoload": { "autoload": {
"psr-0": { "psr-0": {
"phpDocumentor": [ "org\\bovigo\\vfs\\": "src/main/php"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Frank Kleine",
"homepage": "http://frankkleine.de/",
"role": "Developer"
}
],
"description": "Virtual file system to mock the real file system in unit tests.",
"homepage": "http://vfs.bovigo.org/",
"time": "2017-08-01T08:02:14+00:00"
},
{
"name": "phpdocumentor/reflection-common",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionCommon.git",
"reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6",
"reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6",
"shasum": ""
},
"require": {
"php": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "^4.6"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"phpDocumentor\\Reflection\\": [
"src"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jaap van Otterdijk",
"email": "opensource@ijaap.nl"
}
],
"description": "Common reflection classes used by phpdocumentor to reflect the code structure",
"homepage": "http://www.phpdoc.org",
"keywords": [
"FQSEN",
"phpDocumentor",
"phpdoc",
"reflection",
"static analysis"
],
"time": "2017-09-11T18:02:19+00:00"
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "4.3.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "94fd0001232e47129dd3504189fa1c7225010d08"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08",
"reference": "94fd0001232e47129dd3504189fa1c7225010d08",
"shasum": ""
},
"require": {
"php": "^7.0",
"phpdocumentor/reflection-common": "^1.0.0",
"phpdocumentor/type-resolver": "^0.4.0",
"webmozart/assert": "^1.0"
},
"require-dev": {
"doctrine/instantiator": "~1.0.5",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^6.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
}
},
"autoload": {
"psr-4": {
"phpDocumentor\\Reflection\\": [
"src/" "src/"
] ]
} }
@ -105,10 +206,58 @@
"authors": [ "authors": [
{ {
"name": "Mike van Riel", "name": "Mike van Riel",
"email": "mike.vanriel@naenius.com" "email": "me@mikevanriel.com"
} }
], ],
"time": "2016-01-25T08:17:30+00:00" "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2017-11-30T07:14:17+00:00"
},
{
"name": "phpdocumentor/type-resolver",
"version": "0.4.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "9c977708995954784726e25d0cd1dddf4e65b0f7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7",
"reference": "9c977708995954784726e25d0cd1dddf4e65b0f7",
"shasum": ""
},
"require": {
"php": "^5.5 || ^7.0",
"phpdocumentor/reflection-common": "^1.0"
},
"require-dev": {
"mockery/mockery": "^0.9.4",
"phpunit/phpunit": "^5.2||^4.8.24"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"phpDocumentor\\Reflection\\": [
"src/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mike van Riel",
"email": "me@mikevanriel.com"
}
],
"time": "2017-07-14T14:27:02+00:00"
}, },
{ {
"name": "phpspec/prophecy", "name": "phpspec/prophecy",
@ -981,26 +1130,35 @@
}, },
{ {
"name": "symfony/yaml", "name": "symfony/yaml",
"version": "v2.8.45", "version": "v3.4.15",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/yaml.git", "url": "https://github.com/symfony/yaml.git",
"reference": "fbf876678e29dc634430dcf0096e216eb0004467" "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/fbf876678e29dc634430dcf0096e216eb0004467", "url": "https://api.github.com/repos/symfony/yaml/zipball/c2f4812ead9f847cb69e90917ca7502e6892d6b8",
"reference": "fbf876678e29dc634430dcf0096e216eb0004467", "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.9", "php": "^5.5.9|>=7.0.8",
"symfony/polyfill-ctype": "~1.8" "symfony/polyfill-ctype": "~1.8"
}, },
"conflict": {
"symfony/console": "<3.4"
},
"require-dev": {
"symfony/console": "~3.4|~4.0"
},
"suggest": {
"symfony/console": "For validating YAML files using the lint command"
},
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.8-dev" "dev-master": "3.4-dev"
} }
}, },
"autoload": { "autoload": {
@ -1027,7 +1185,57 @@
], ],
"description": "Symfony Yaml Component", "description": "Symfony Yaml Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-07-26T09:03:18+00:00" "time": "2018-08-10T07:34:36+00:00"
},
{
"name": "webmozart/assert",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/webmozart/assert.git",
"reference": "0df1908962e7a3071564e857d86874dad1ef204a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a",
"reference": "0df1908962e7a3071564e857d86874dad1ef204a",
"shasum": ""
},
"require": {
"php": "^5.3.3 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.6",
"sebastian/version": "^1.0.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.3-dev"
}
},
"autoload": {
"psr-4": {
"Webmozart\\Assert\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bernhard Schussek",
"email": "bschussek@gmail.com"
}
],
"description": "Assertions to validate method input/output with nice error messages.",
"keywords": [
"assert",
"check",
"validate"
],
"time": "2018-01-29T19:49:41+00:00"
} }
], ],
"aliases": [], "aliases": [],
@ -1035,6 +1243,9 @@
"stability-flags": [], "stability-flags": [],
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": {
"php": ">=5.3",
"ext-json": "*"
},
"platform-dev": [] "platform-dev": []
} }

View File

@ -13,6 +13,7 @@
</testsuite> </testsuite>
<testsuite name="psr4"> <testsuite name="psr4">
<file>test/app1/src/PSR4Test.php</file> <file>test/app1/src/PSR4Test.php</file>
<directory>test/unit/PSR4</directory>
</testsuite> </testsuite>
<testsuite name="classmap"> <testsuite name="classmap">
<file>test/app1/src/ClassmapTest.php</file> <file>test/app1/src/ClassmapTest.php</file>

View File

@ -0,0 +1,60 @@
<?php
namespace HaydenPierce\ClassFinder\UnitTest;
use HaydenPierce\ClassFinder\PSR4\PSR4Namespace;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
class PSR4NamespaceTest extends \PHPUnit_Framework_TestCase
{
/** @var vfsStreamDirectory */
private $root;
public function setUp()
{
$structure = $this->getTestStructure();
$this->root = vfsStream::setup('root', null, $structure);
}
public function getTestStructure()
{
return array(
'Baz' => array(
'Foo' => array(
'Fooa.php' => $this->getClassFileContents('PSR4\\Foo', 'Fooa'),
'Foob.php' => $this->getClassFileContents('PSR4\\Foo', 'Foob')
),
'Bar.php' => $this->getClassFileContents('PSR4', 'Bar'),
'Barb.php' => $this->getClassFileContents('PSR4', 'Barb')
)
);
}
public function getClassFileContents($namespace, $className)
{
$template = <<<EOL
<?php
namespace %s
class %s
{
}
EOL;
return sprintf($template, $namespace, $className);
}
public function testCountMatchingNamespaceSegments()
{
$namespace = new PSR4Namespace('MyPSR4Root\\Foot\\', $this->root->getChild('Baz')->path());
$this->assertEquals($namespace->countMatchingNamespaceSegments('MyPSR4Root\\Foot'), 2);
$this->assertEquals($namespace->countMatchingNamespaceSegments('MyPSR4Root'), 1);
$this->assertEquals($namespace->countMatchingNamespaceSegments('MyPSR4Root\\Foot\\Baz\\Foo'), 3);
$this->assertEquals($namespace->countMatchingNamespaceSegments('MyPSR4Root\\Foot\\Baz'), 3);
$this->assertEquals($namespace->countMatchingNamespaceSegments('Cactus'), 0);
$this->assertEquals($namespace->countMatchingNamespaceSegments('Cactus\\Foot'), 0);
}
}