Permalink
Browse files

Commit for the Castalio Podcast

  • Loading branch information...
alganet committed Mar 2, 2013
1 parent cc2beb0 commit c1b6a473c62253725321eeb4a4125e3c25e709f1
View
@@ -1,5 +1,5 @@
{
"name": "Respect/Doc",
"name": "respect/doc",
"version": "0.1.0-alpha",
"type": "library",
"description": "Documentation for under engineered codes (in PHP).",
@@ -17,11 +17,13 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=5.3.0",
"phpunit/phpunit": "*",
"respect/test": "dev-master"
},
"autoload": {
"psr-0": {
"Respect\\Doc": "library"
}
}
}
}
@@ -8,7 +8,7 @@ class Methods extends AbstractDocument implements
e\ExplorationList,
e\MethodExploration
{
public static $considers = array();
public static $considers = array('/.*/');
public function __construct(ClassDocument $tested)
{
@@ -26,26 +26,23 @@ public static function considers($name)
public function doc()
{
return $this->getIterator();
return iterator_to_array($this);
}
public function getIterator()
{
$testedClass = $this->tested;
$allMethods = get_class_methods($testedClass->tested);
if (!static::$considers) {
return $allMethods;
$methodsInstances = array();
foreach ($allMethods as $method) {
if (empty(static::$considers) || static::considers($method)) {
$methodsInstances[$method] = new Method($this->tested, $method);
}
}
return array_values(array_filter(array_map(
function ($method) use ($testedClass) {
if (static::considers($method)) {
return $testedClass->methods[$method];
}
},
$allMethods
)));
return new \ArrayObject($methodsInstances);
}
public function offsetGet($name)
@@ -0,0 +1,9 @@
<?php
namespace Respect\Doc\Documents;
use Respect\Doc\Explorations as e;
class Project extends AbstractDocument implements e\Exploration
{
}
View
@@ -1,19 +1,32 @@
<?php
<?php /** a Courtesy of Respect/Foundation */
date_default_timezone_set('UTC');
$pear_path = trim(`pear config-get php_dir`);
set_include_path('../library'
. PATH_SEPARATOR . $pear_path
. PATH_SEPARATOR . get_include_path());
$paths = explode(PATH_SEPARATOR,get_include_path());
$paths[] = trim(`pear config-get php_dir`);
/**
* Autoloader that implements the PSR-0 spec for interoperability between
* PHP software.
*/
// See if composer is present then it should be picked up too
if (file_exists(dirname(__DIR__).'/vendor/composer')) {
$map = require dirname(__DIR__).'/vendor/composer/autoload_namespaces.php';
foreach ($map as $path)
$paths[] = $path;
}
natsort($paths);
array_unshift($paths, dirname(__DIR__) .'/library');
set_include_path(implode(PATH_SEPARATOR, array_unique($paths)));
/** Autoloader that implements the PSR-0 spec for interoperability between PHP software. */
spl_autoload_register(
function($className) {
$fileParts = explode('\\', ltrim($className, '\\'));
static $composerClassmap;
if (!isset($composerClassmap) && file_exists(dirname(__DIR__).'/vendor/composer'))
$composerClassmap = require dirname(__DIR__).'/vendor/composer/autoload_classmap.php';
// Also consider composer classMap of course
if (isset($composerClassmap[$className]))
return require $composerClassmap[$className];
$fileParts = explode('\\', ltrim($className, '\\'));
if (false !== strpos(end($fileParts), '_'))
array_splice($fileParts, -1, 1, explode('_', current($fileParts)));
@@ -5,8 +5,8 @@
/**
* Getting Information About Tested Classes
*
* ClassDocument allows you to explore a test case and find out information
* about how it works.
* ClassDocument allows you to explore a class and find out relevant document
* information about it.
*
* @covers Respect\Doc\Documents\ClassDocument
*/
@@ -54,9 +54,20 @@ public function testConstructorWithInstances()
'The variable $ClassDocument as string gets the test case class name'
);
}
public function testGettingMethods()
{
$classDocument = new ClassDocument(new \My\Sample);
$methods = $classDocument->methods;
$methodsDoc = $methods->doc();
$this->assertInstanceOf("Respect\\Doc\\Documents\\Methods", $methods);
}
}
namespace My;
class Sample
{
public function foo() {}
public function bar() {}
}
@@ -23,12 +23,13 @@ public function testConstructor($docResult, $stringResult, $pattern)
$Methods = new Methods($testedClass);
Methods::$considers = array($pattern);
$this->assertContains(
$this->assertArrayHasKey(
$docResult,
$Methods->doc(),
'$Methods->doc() should return an array with methods matching Methods::$considers'
);
$this->assertEquals(
$this->assertContains(
$stringResult,
(string) $Methods,
'$Methods->doc() should return an array with methods matching Methods::$considers'
@@ -44,6 +45,14 @@ public function provideMethodNames()
array("barBaz", "fooBar,barBaz", "/bar/i")
);
}
public function testGettingMethod()
{
$testedClass = new ClassDocument("My\\MethodsSampleTest");
$method = $testedClass->methods["barBaz"];
$this->assertInstanceOf("Respect\\Doc\\Documents\\Method", $method);
}
}
namespace My;
@@ -0,0 +1,29 @@
<?php
namespace Respect\Doc\Documents;
use Respect\Test\StreamWrapper;
/**
* Getting Information About A Project
*
*/
class ProjectTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
StreamWrapper::setStreamOverrides(array());
}
public function tearDown()
{
StreamWrapper::releaseOverrides();
}
public function test()
{
$project = new Project('/example/project');
}
}

0 comments on commit c1b6a47

Please sign in to comment.