Skip to content

Commit

Permalink
added new features and fixed minor performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
divineniiquaye committed Apr 20, 2020
1 parent 93e66fe commit 4df8457
Show file tree
Hide file tree
Showing 41 changed files with 1,814 additions and 69 deletions.
13 changes: 0 additions & 13 deletions .github/ISSUE_TEMPLATE/Support_us.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ Whether you are chief of IT company which benefits from Biurad, or developer who

Thank you!

> # Golden + Silver Donations ($180+ monthly)
- [AirLive Stream](https://airlive.com)
- [Code Academy](https://code-academy.net)
- [Spacely International](https://spacely.com)
- [Divine Niiquaye Ibok](https://divineniiquayeibok.com)

> # Bronze Donations ($50+ monthly)
- Trinity Ofusu
- Acheampong Obed
- Rosemond Koluh

> # Pledges ($5 - $50 one-time-payment)
- Ankrah Elvis
Expand Down
76 changes: 75 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,75 @@
# loader-manager
# This dependency is a robust package for loading files, classes, class aliases, annotations, and store data loader for saving and accessing data (scalar, object, array, etc)

This dependency provides a few fluent and convenient wrappers for working files, class aliases, annotations, classes with a data loader that collect's data (scalar, object, array) and then populate's the data into object mapping.

**`Please note that this documentation is currently work-in-progress. Feel free to contribute.`**

## Installation

The recommended way to install Loader Manager is via Composer:

```bash
composer require biurad/biurad-loader
```

It requires PHP version 7.0 and supports PHP up to 7.4. The dev-master version requires PHP 7.1.

## How To Use

Loader manager offers a very intuitive API for scalables, null, array and object manipulation. Before we show you the first example, we need to think about how to pack all our configurations into one collection and easily access it as string, object or and array without having to define configurations over and over. Including loading classes, class aliases, or annotations.

All Loader manager classes are very well optimized for performance and in the first place, it provides full atomicity of operations.

Before using this dependency, take some time to familiarize yourself with [Php ArrayAccess](http://php.net/manual/en/arrayaccess.php), [Doctrine Annotations](https://github.com/doctrine/annotations), [PHP class_alias function](http://php.net/manual/en/function.class-alias.php), [PHP RecursiveDirectoryIterator](http://php.net/manual/en/recursivedirectoryiterator.php) and [PHP SplFileInfo](http://php.net/manual/en/splfileinfo.php). and handling stored variables in php.

The Loader Manager has some useful classes and methods which you may require while working on a project.

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Testing

To run the tests you'll have to start the included node based server if any first in a separate terminal window.

With the server running, you can start testing.

```bash
vendor/bin/phpunit
```

## Security

If you discover any security related issues, please report using the issue tracker.
use our example [Issue Report](.github/ISSUE_TEMPLATE/Bug_report.md) template.

## Want to be listed on our projects website

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a message on our website, mentioning which of our package(s) you are using.

Post Here: [Project Patreons - https://patreons.biurad.com](https://patreons.biurad.com)

We publish all received request's on our website;

## Credits

- [Divine Niiquaye](https://github.com/divineniiquaye)
- [All Contributors](https://biurad.com/projects/biurad-loader/contributers)

## Support us

`Biurad Lap` is a technology agency in Accra, Ghana. You'll find an overview of all our open source projects [on our website](https://biurad.com/opensource).

Does your business depend on our contributions? Reach out and support us on to build more project's. We want to build over one hundred project's in two years. [Support Us](https://biurad.com/donate) achieve our goal.

Reach out and support us on [Patreon](https://www.patreon.com/biurad). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

[Thanks to all who made Donations and Pledges to Us.](.github/ISSUE_TEMPLATE/Support_us.md)

## License

The BSD-3-Clause . Please see [License File](LICENSE.md) for more information.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
291 changes: 291 additions & 0 deletions Tests/UniformResourceLocatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
<?php

/*
* This code is under BSD 3-Clause "New" or "Revised" License.
*
* PHP version 7 and above required
*
* @category LocatorManager
*
* @author Divine Niiquaye Ibok <divineibok@gmail.com>
* @copyright 2019 Biurad Group (https://biurad.com/)
* @license https://opensource.org/licenses/BSD-3-Clause License
*
* @link https://www.biurad.com/projects/locatormanager
* @since Version 0.1
*/

namespace BiuradPHP\Loader\Tests;

use PHPUnit\Framework\TestCase;
use BiuradPHP\Loader\UniformResourceLocator;
use BiuradPHP\Loader\UniformResourceIterator;
use BiuradPHP\Loader\RecursiveUniformResourceIterator;
use BiuradPHP\Loader\Interfaces\ResourceLocatorInterface;

/**
* @requires PHP 7.1.30
* @requires PHPUnit 7.5
*/
class UniformResourceLocatorTest extends TestCase
{
/**
* @var UniformResourceLocator
*/
static protected $locator;

public static function setUpBeforeClass(): void
{
// Share locator in all tests.
self::$locator = new UniformResourceLocator(__DIR__ . '/Fixtures');
}

public function testGetBase()
{
$this->assertEquals(str_replace('\\', '/', __DIR__ . '/Fixtures'), self::$locator->getBase());
}

/**
* @param $scheme
* @param $path
* @param $lookup
*
* @dataProvider addPathProvider
*/
public function testAddPath($scheme, $path, $lookup)
{
$locator = self::$locator;

$this->assertFalse($locator->schemeExists($scheme));

$locator->addPath($scheme, $path, $lookup);

$this->assertTrue($locator->schemeExists($scheme));
}

public function addPathProvider() {
return [
['base', '', 'base'],
['local', '', 'local'],
['override', '', 'override'],
['all', '', ['override://all', 'local://all', 'base://all']],
];
}

/**
* @depends testAddPath
*/
public function testGetSchemes()
{
$this->assertEquals(
['base', 'local', 'override', 'all'],
self::$locator->getSchemes()
);
}

/**
* @depends testAddPath
* @dataProvider getPathsProvider
*/
public function testGetPaths($scheme, $expected)
{
$locator = self::$locator;

$this->assertEquals($expected, $locator->getPaths($scheme));
}


public function getPathsProvider() {
return [
['base', ['' => ['base']]],
['local', ['' => ['local']]],
['override', ['' => ['override']]],
['all', ['' => [['override', 'all'], ['local', 'all'], ['base', 'all']]]],
['fail', []]
];
}

/**
* @depends testAddPath
*/
public function testSchemeExists()
{
$locator = self::$locator;

// Partially tested in addPath() tests.
$this->assertFalse($locator->schemeExists('foo'));
$this->assertFalse($locator->schemeExists('file'));
}

/**
* @depends testAddPath
*/
public function testGetIterator()
{
$locator = self::$locator;

$this->assertInstanceOf(
UniformResourceIterator::class,
$locator->getIterator('all://')
);

$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid resource fail://');
$locator->getIterator('fail://');
}

/**
* @depends testAddPath
*/
public function testGetRecursiveIterator()
{
$locator = self::$locator;

$this->assertInstanceOf(
RecursiveUniformResourceIterator::class,
$locator->getRecursiveIterator('all://')
);

$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid resource fail://');
$locator->getRecursiveIterator('fail://');
}

/**
* @depends testAddPath
*/
public function testIsStream($uri)
{
$locator = self::$locator;

// Existing file.
$this->assertEquals(true, $locator->isStream('all://base.txt'));
// Non-existing file.
$this->assertEquals(true, $locator->isStream('all://bar.txt'));
// Unknown uri type.
$this->assertEquals(false, $locator->isStream('fail://base.txt'));
// Bad uri.
$this->assertEquals(false, $locator->isStream('fail://../base.txt'));
}

/**
* @dataProvider normalizeProvider
*/
public function testNormalize($uri, $path)
{
$locator = self::$locator;

$this->assertEquals($path, $locator->normalize($uri));
}

/**
* @depends testAddPath
* @dataProvider findResourcesProvider
*/
public function testFindResource($uri, $paths)
{
$locator = self::$locator;
$path = $paths ? reset($paths) : false;
$fullPath = !$path ? false : __DIR__ . "/Fixtures/{$path}";

$this->assertEquals(str_replace('\\', '/', $fullPath), $locator->findResource($uri));
$this->assertEquals(str_replace('\\', '/', $path), $locator->findResource($uri, false));
}

/**
* @depends testAddPath
* @dataProvider findResourcesProvider
*/
public function testFindResources($uri, $paths)
{
$locator = self::$locator;

$this->assertEquals(str_replace('\\', '/', $paths), $locator->findResources($uri, false));
}

/**
* @depends testFindResource
* @dataProvider findResourcesProvider
*/
public function testInvoke($uri, $paths)
{
$locator = self::$locator;
$path = $paths ? reset($paths) : false;
$fullPath = !$path ? false : __DIR__ . "/Fixtures/{$path}";

$this->assertEquals(str_replace('\\', '/', $fullPath), $locator($uri));
}


public function normalizeProvider() {
return [
['', ''],
['./', ''],
['././/./', ''],
['././/../', false],
['/', '/'],
['//', '/'],
['///', '/'],
['/././', '/'],
['foo', 'foo'],
['/foo', '/foo'],
['//foo', '/foo'],
['/foo/', '/foo/'],
['//foo//', '/foo/'],
['path/to/file.txt', 'path/to/file.txt'],
['path/to/../file.txt', 'path/file.txt'],
['path/to/../../file.txt', 'file.txt'],
['path/to/../../../file.txt', false],
['/path/to/file.txt', '/path/to/file.txt'],
['/path/to/../file.txt', '/path/file.txt'],
['/path/to/../../file.txt', '/file.txt'],
['/path/to/../../../file.txt', false],
['c:\\', 'c:/'],
['c:\\path\\to\file.txt', 'c:/path/to/file.txt'],
['c:\\path\\to\../file.txt', 'c:/path/file.txt'],
['c:\\path\\to\../../file.txt', 'c:/file.txt'],
['c:\\path\\to\../../../file.txt', false],
['stream://path/to/file.txt', 'stream://path/to/file.txt'],
['stream://path/to/../file.txt', 'stream://path/file.txt'],
['stream://path/to/../../file.txt', 'stream://file.txt'],
['stream://path/to/../../../file.txt', false],

];
}
public function findResourcesProvider() {
return [
['all://base.txt', ['base/all/base.txt']],
['all://base_all.txt', ['override/all/base_all.txt', 'local/all/base_all.txt', 'base/all/base_all.txt']],
['all://base_local.txt', ['local/all/base_local.txt', 'base/all/base_local.txt']],
['all://base_override.txt', ['override/all/base_override.txt', 'base/all/base_override.txt']],
['all://local.txt', ['local/all/local.txt']],
['all://local_override.txt', ['override/all/local_override.txt', 'local/all/local_override.txt']],
['all://override.txt', ['override/all/override.txt']],
['all://asdf/../base.txt', ['base/all/base.txt']],
];
}

/**
* @depends testAddPath
*/
public function testMergeResources()
{
$locator = self::$locator;

$this->assertInstanceOf(ResourceLocatorInterface::class, $locator);
}

public function testReset()
{
$locator = self::$locator;

$this->assertInstanceOf(ResourceLocatorInterface::class, $locator);
}

public function testResetScheme()
{
$locator = self::$locator;

$this->assertInstanceOf(ResourceLocatorInterface::class, $locator);
}
}
Loading

0 comments on commit 4df8457

Please sign in to comment.