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

Merge branch 'ci' into 'master'

Add support for CI; Fix PHP 5.3; Fix bug on Linux

See merge request hpierce1102/ClassFinder!1
This commit is contained in:
Hayden Pierce 2018-09-03 21:59:57 +00:00
commit 996911e775
13 changed files with 491 additions and 1319 deletions

7
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,7 @@
PHP 5.3 - PHPUnit:
script: "ci/php53.sh"
image: "registry.gitlab.com/hpierce1102/classfinder/php53"
PHP 7.2 - PHPUnit:
script: "ci/php72.sh"
image: "registry.gitlab.com/hpierce1102/classfinder/php72"

View File

@ -63,4 +63,5 @@ Documentation
**Internals**
* [How Testing Works](docs/testing.md)
* [How Testing Works](docs/testing.md)
* [Continuous Integration Notes](docs/ci.md)

4
ci/php53.sh Executable file
View File

@ -0,0 +1,4 @@
composer install --working-dir=/builds/hpierce1102/ClassFinder/test/app1 --quiet
composer install --working-dir=/builds/hpierce1102/ClassFinder --quiet
php --version
php /builds/hpierce1102/ClassFinder/vendor/bin/phpunit /builds/hpierce1102/ClassFinder/test/app1/src/ClassFinderTest.php

4
ci/php72.sh Executable file
View File

@ -0,0 +1,4 @@
composer install --working-dir=/builds/hpierce1102/ClassFinder/test/app1 --quiet
composer install --working-dir=/builds/hpierce1102/ClassFinder --quiet
php --version
php /builds/hpierce1102/ClassFinder/vendor/bin/phpunit /builds/hpierce1102/ClassFinder/test/app1/src/ClassFinderTest.php

View File

@ -2,16 +2,19 @@
"name": "haydenpierce/class-finder",
"type": "library",
"license": "MIT",
"version": "0.1.0",
"version": "0.1.1",
"authors": [
{
"name": "Hayden Pierce",
"email": "hayden@haydenpierce.com"
}
],
"require": {},
"require": {
"php": "^5.3",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "6.5"
"phpunit/phpunit": "4.8.36"
},
"autoload": {
"psr-4": {

877
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,11 @@
Version 0.1.1
-------------
* Fixed a Linux specific bug that caused absolute paths to fail to resolve and erroneously throw exceptions. If you were
affected by this bug, you would see errors like `Unknown namespace Acme\Whatever. Checked for files in , but that directory did not exist. [...]`
when that namespace does indeed exist.
* Support for PHP 5.3 is now under testing harness and should work now.
Version 0.1.0
-------------

14
docs/ci.md Normal file
View File

@ -0,0 +1,14 @@
Continuous Integration Notes
----------------------------
Docker containers are registered in the registry that contain an environment for various PHP versions. At the very least
there should be two versions, one of the oldest version of PHP we're supporting and one for the newest. In a perfect world,
we'd also have an image for a Windows server using PHP to gain some CI test coverage with Windows style absolute paths.
However, getting PHP running on a Windows container proved to be too complicated for the value. Until such a time where
we can get one created (contributions welcome), testing on Windows will be done manually.
The Dockerfiles used to create these images are contained in a different repository:
[ClassFinderTestContainers](https://gitlab.com/hpierce1102/ClassFinderTestContainers).
The CI scripts themselves are stored here in `/ci/*`, with the config in `/gitlab-ci.yml`.

View File

@ -38,7 +38,7 @@ class PSR4Namespace
public function countMatchingNamespaceSegments($namespace)
{
$namespaceFragments = explode('\\', $namespace);
$undefinedNamespaceFragments = [];
$undefinedNamespaceFragments = array();
while($namespaceFragments) {
$possibleNamespace = implode('\\', $namespaceFragments) . '\\';
@ -58,7 +58,9 @@ class PSR4Namespace
$relativePath = substr($namespace, strlen($this->namespace));
$directories = array_reduce($this->directories, function($carry, $directory) use ($relativePath, $namespace){
$realDirectory = realpath($directory . '/' . $relativePath);
// TODO: perhaps there should be a central place to normalize file paths. AppConfig? Some other Util?
$path = str_replace('\\', '/', $directory . '/' . $relativePath);
$realDirectory = realpath($path);
if ($realDirectory !== false) {
return array_merge($carry, array($realDirectory));
} else {

View File

@ -69,11 +69,12 @@ class PSR4NamespaceFactory
}
$self = $this;
$directories = array_map(function($directory) use ($self) {
$appConfig = $this->appConfig;
$directories = array_map(function($directory) use ($self, $appConfig) {
if ($self->isAbsolutePath($directory)) {
return $directory;
} else {
return $self->appConfig->getAppRoot() . $directory;
return $appConfig->getAppRoot() . $directory;
}
}, $directories);
@ -92,7 +93,7 @@ class PSR4NamespaceFactory
* @throws ClassFinderException
* @return bool
*/
private function isAbsolutePath($path) {
public function isAbsolutePath($path) {
if (!is_string($path)) {
$mess = sprintf('String expected but was given %s', gettype($path));
throw new ClassFinderException($mess);
@ -104,7 +105,7 @@ class PSR4NamespaceFactory
$regExp .= '(?<root>(?:[[:alpha:]]:[/\\\\]|/)?)';
// Actual path.
$regExp .= '(?<path>(?:[[:print:]]*))$%';
$parts = [];
$parts = array();
if (!preg_match($regExp, $path, $parts)) {
$mess = sprintf('Path is NOT valid, was given %s', $path);
throw new ClassFinderException($mess);

View File

@ -9,7 +9,7 @@
}
],
"require-dev": {
"phpunit/phpunit": "6.5",
"phpunit/phpunit": "4.8.36",
"haydenpierce/class-finder": "0.0.1",
"haydenpierce/sandbox-app":"0.1.2"
},

863
test/app1/composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,11 +5,9 @@ namespace TestApp1;
require_once __DIR__ . '/../vendor/autoload.php';
use HaydenPierce\ClassFinder\ClassFinder;
use \PHPUnit\Framework\TestCase;
// "vendor/bin/phpunit" "./test/app1/src/ClassFinderTest.php"
class ClassFinderTest extends TestCase
class ClassFinderTest extends \PHPUnit_Framework_TestCase
{
public function setup()
{