Merge branch 'feature/psr4-setup' into develop
This commit is contained in:
commit
a11ecf4140
8 changed files with 104 additions and 2 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,5 +2,4 @@
|
||||||
.htconfig.php
|
.htconfig.php
|
||||||
#*
|
#*
|
||||||
favicon.*
|
favicon.*
|
||||||
|
tests/coverage.html
|
||||||
|
|
||||||
|
|
2
Makefile
Normal file
2
Makefile
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
test:
|
||||||
|
cd tests && phpunit --coverage-html=coverage.html && x-www-browser ./coverage.html/index.html
|
41
autoload.php
Normal file
41
autoload.php
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
spl_autoload_register(function ($class) {
|
||||||
|
|
||||||
|
// the package namespace
|
||||||
|
$ns = 'Friendica\Directory';
|
||||||
|
|
||||||
|
// what prefixes should be recognized?
|
||||||
|
$prefixes = array(
|
||||||
|
"{$ns}\\" => array(
|
||||||
|
__DIR__ . '/src',
|
||||||
|
__DIR__ . '/tests/unit/src',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// go through the prefixes
|
||||||
|
foreach ($prefixes as $prefix => $dirs) {
|
||||||
|
|
||||||
|
// does the requested class match the namespace prefix?
|
||||||
|
$prefix_len = strlen($prefix);
|
||||||
|
if (substr($class, 0, $prefix_len) !== $prefix) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// strip the prefix off the class
|
||||||
|
$class = substr($class, $prefix_len);
|
||||||
|
|
||||||
|
// a partial filename
|
||||||
|
$part = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
|
||||||
|
|
||||||
|
// go through the directories to find classes
|
||||||
|
foreach ($dirs as $dir) {
|
||||||
|
$dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
|
||||||
|
$file = $dir . DIRECTORY_SEPARATOR . $part;
|
||||||
|
if (is_readable($file)) {
|
||||||
|
require $file;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
14
example.php
Normal file
14
example.php
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
//Add the auto loader. This makes sure that we can find the files we need for a class.
|
||||||
|
require_once('autoload.php');
|
||||||
|
|
||||||
|
//This says, we want Hello to mean Friendica\Directory\Example\Hello.
|
||||||
|
//It's a shortcut.
|
||||||
|
use Friendica\Directory\Example\Hello;
|
||||||
|
|
||||||
|
//Here we use the shortcut and create a new Hello object.
|
||||||
|
$instance = new Hello();
|
||||||
|
|
||||||
|
//Let the Hello object call
|
||||||
|
echo $instance->sayHello();
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once('autoload.php');
|
||||||
require_once('boot.php');
|
require_once('boot.php');
|
||||||
|
|
||||||
$a = new App;
|
$a = new App;
|
||||||
|
|
10
src/Example/Hello.php
Normal file
10
src/Example/Hello.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php namespace Friendica\Directory\Example;
|
||||||
|
|
||||||
|
class Hello
|
||||||
|
{
|
||||||
|
|
||||||
|
public function sayHello(){
|
||||||
|
return 'Hello world!';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
tests/phpunit.xml
Normal file
12
tests/phpunit.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<phpunit bootstrap="../autoload.php">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite>
|
||||||
|
<directory>unit/src</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||||
|
<directory>../src</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
</phpunit>
|
23
tests/unit/src/Example/HelloTest.php
Normal file
23
tests/unit/src/Example/HelloTest.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php namespace Friendica\Directory\Example;
|
||||||
|
|
||||||
|
class HelloTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the sayHello() method.
|
||||||
|
*/
|
||||||
|
public function testSayHello()
|
||||||
|
{
|
||||||
|
|
||||||
|
//Create a new Hello class instance.
|
||||||
|
$instance = new Hello();
|
||||||
|
|
||||||
|
//Call the method sayHello() that we want to test.
|
||||||
|
$output = $instance->sayHello();
|
||||||
|
|
||||||
|
//Check that it returns the message we expect.
|
||||||
|
$this->assertEquals("Hello world!", $output);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue