This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
class TestException extends Exception{
|
||||
|
||||
function __construct($message) {
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestFailException extends Exception {
|
||||
|
||||
function __construct($msg) {
|
||||
$this->message = "Error: ".$msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Service_ExceptionTest {
|
||||
|
||||
function __construct() {
|
||||
|
||||
}
|
||||
|
||||
public function TestTheFail() {
|
||||
$this->failAtThis();
|
||||
}
|
||||
|
||||
public function CatchAndThrow() {
|
||||
try {
|
||||
$this->failAtThis();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
throw new TestFailException("moep:D");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function internalCatch() {
|
||||
try {
|
||||
$this->failAtThis();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
}
|
||||
|
||||
function failAtThis() {
|
||||
throw new TestException("I had to do this. Please forgive me :/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$ExceptionTest = new Service_ExceptionTest;
|
||||
$ExceptionTest->CatchAndThrow();
|
||||
} catch (Exception $e){
|
||||
var_dump($e);
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Testclass
|
||||
* @author jpt
|
||||
*/
|
||||
class Foo {
|
||||
/**
|
||||
* @var array Instances of Bar.
|
||||
*/
|
||||
protected $pool;
|
||||
|
||||
function __construct() {
|
||||
$this->pool = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an Instance of Bar to the Pool.
|
||||
* @param Bar $bar
|
||||
* @return void
|
||||
*/
|
||||
public function addBar($bar) {
|
||||
array_push($this->pool, $bar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the internal instance of Bar for the specific ID.
|
||||
* @param int $id
|
||||
* @return Bar
|
||||
*/
|
||||
public function getBar($id) {
|
||||
return $this->pool[$id];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Outputs the current state of the bars in the pool.
|
||||
* @return void
|
||||
*/
|
||||
public function getTestResult() {
|
||||
foreach($this->pool AS $id=>$bar) {
|
||||
echo "ID: " . $id . ", Test: " . $bar->test . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testclass #2
|
||||
* @author jpt
|
||||
*/
|
||||
class Bar {
|
||||
/**
|
||||
* @var string Teststring.
|
||||
*/
|
||||
public $test;
|
||||
|
||||
/**
|
||||
* Default constructor. Initializes test variable.
|
||||
* @return void
|
||||
*/
|
||||
function __construct() {
|
||||
$this->test = "failed";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$f = new Foo();
|
||||
|
||||
$f->addBar(new Bar());
|
||||
$f->addBar(new Bar());
|
||||
$f->addBar(new Bar());
|
||||
$f->addBar(new Bar());
|
||||
|
||||
$f->getBar(1)->test = "success";
|
||||
|
||||
$f->getTestResult();
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Testclass in order to test phpdoc-stuff with the php reflection api
|
||||
* Shall help in order to find out how this stuff works.
|
||||
* @author jpt
|
||||
*/
|
||||
class TestClassForTestsWithReflection {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $public;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $protected;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $privateStatic;
|
||||
|
||||
/**
|
||||
* Testfunction
|
||||
* @param Klasse $objekt
|
||||
* @return void
|
||||
*/
|
||||
public function blablubblol(Klasse $objekt) {
|
||||
$objekt = new ReflectionObject($objekt);
|
||||
print $objekt->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getDocComment() method
|
||||
*
|
||||
* @param array $ray
|
||||
* @param int $zero
|
||||
* @return string
|
||||
* @specialtag
|
||||
*/
|
||||
protected function testfunctionWithCamelCase(array $ray, $zero = 0) {
|
||||
return "bla";
|
||||
}
|
||||
}
|
||||
|
||||
//TestClassForTestsWithReflection ends here.
|
||||
|
||||
//create ReflectionClass
|
||||
$class = new ReflectionClass("TestClassForTestsWithReflection");
|
||||
|
||||
//print class name
|
||||
echo "Information about: " . $class->name . "\n";
|
||||
|
||||
//getDocs for all methods
|
||||
foreach($class->getMethods() as $key=>$method) {
|
||||
var_dump($method->name, $method->getDocComment());
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
//getDocs for all properties
|
||||
foreach($class->getProperties() as $key=>$property) {
|
||||
var_dump($property->name, $property->getDocComment());
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user