Ejemplo n.º 1
0
 /**
  * @test
  */
 public function canApplyInflections()
 {
     // Mocking argument resolver dependency.
     $resolver = Mockery::mock(ArgumentResolver::class);
     // Callback to be returned by ArgumentResolver::resolveArguments() method.
     // Expects $arguments array to contain 'value' key to merge.
     // Will return array of arguments for TestClass::setValue() method call.
     $callback = function (array $arguments) {
         return array_values(array_merge(['value' => 'to be replaced'], $arguments));
     };
     // Reflecting method to call on inflection.
     $reflection = new ReflectionMethod(TestClass::class, 'setValue');
     // Defining expectations.
     $resolver->shouldReceive('reflectCallable')->with([TestClass::class, 'setValue'])->andReturn($reflection)->once();
     $resolver->shouldReceive('resolveArguments')->with($reflection)->andReturn($callback)->once();
     // Creating inflector, setting resolver, adding inflection.
     $inflector = new ObjectInflector($resolver);
     $inflector->addInflection(TestClass::class, 'setValue', ['value' => 'value']);
     // Creating test object.
     $test = new TestClass(new stdClass());
     // At first value is empty.
     $this->assertNull($test->getValue());
     // Applying inflections.
     $inflector->applyInflections($test);
     // Now value was changed via TestClass::setValue() call.
     $this->assertSame('value', $test->getValue());
     // After first run inflection callable must be saved for better performance.
     $test2 = new TestClass(new stdClass());
     $inflector->applyInflections($test2);
     $this->assertSame($test->getValue(), $test2->getValue());
     // Inflection must be called only on TestClass instances.
     $inflector->applyInflections(Mockery::mock(stdClass::class)->shouldNotReceive('setValue')->getMock());
     Mockery::close();
 }
 /**
  * Tests returning a default option value when not set
  */
 public function testReturningADefaultOptionValueWhenNotSet()
 {
     $default = 'xyz';
     $o = new TestClass([]);
     $this->assertEquals($default, $o->getOption('notSet', $default));
     $this->markTestIncomplete();
 }
 public function testGetPropertyValue()
 {
     $class = new TestClass();
     $this->assertNull($class->getTestProperty());
     $this->assertNull(ReflectionClass::from($class)->getPropertyValue('test_property'));
     $class->setTestProperty('foo');
     $this->assertSame('foo', ReflectionClass::from($class)->getPropertyValue('test_property'));
 }
Ejemplo n.º 4
0
 public function testInitTrait()
 {
     $data = ['foo' => 'hello', 'bar' => 3247];
     $d = new TestClass();
     $d->initFromArray($data);
     $this->assertEquals('hello', $d->foo());
     $this->assertEquals(3249, $d->bar());
 }
Ejemplo n.º 5
0
function testFunc($count)
{
    $output = array();
    $cl = new TestClass();
    $cl->doStuff();
    for ($i = 0; $i < $count; $i++) {
        $output[] = $i;
    }
    return $output;
}
Ejemplo n.º 6
0
 public function testParseComplexObject()
 {
     $complexObject = new TestClass();
     $childObject = new TestClass();
     $childObject->setFoo(array('foobar', 'foo' => 'bar'));
     $childObject->setBar(new \stdClass());
     $complexObject->setFoo($childObject);
     $complexObject->setBar(23);
     $this->assertEquals(new Node\ObjectNode(array(new Node\AttributeNode(new Node\ObjectNode(array(new Node\AttributeNode(new Node\ArrayNode(array(new Node\ArrayElementNode(new Node\StringNode('foobar'), new Node\IntegerNode(0)), new Node\ArrayElementNode(new Node\StringNode('bar'), new Node\StringNode('foo')))), 'Qafoo\\SerPretty\\TestClass', 'foo', Node\AttributeNode::SCOPE_PRIVATE), new Node\AttributeNode(new Node\ObjectNode(array(), 'stdClass'), null, 'bar', Node\AttributeNode::SCOPE_PUBLIC), new Node\AttributeNode(new Node\BooleanNode(true), '*', 'baz', Node\AttributeNode::SCOPE_PROTECTED)), 'Qafoo\\SerPretty\\TestClass'), 'Qafoo\\SerPretty\\TestClass', 'foo', Node\AttributeNode::SCOPE_PRIVATE), new Node\AttributeNode(new Node\IntegerNode(23), null, 'bar', Node\AttributeNode::SCOPE_PUBLIC), new Node\AttributeNode(new Node\BooleanNode(true), '*', 'baz', Node\AttributeNode::SCOPE_PROTECTED)), 'Qafoo\\SerPretty\\TestClass'), $this->parser->parse(serialize($complexObject)));
 }
Ejemplo n.º 7
0
function ref_other_class($t)
{
    $obj = new TestClass();
    $other = new OtherClass();
    $obj->other = $other;
    $obj->register_hook();
    $obj->other->register_hook();
    $r = $obj->run_hook(4);
    $t->is($r, 22);
    $obj->clear_hook();
    $other->clear_hook();
}
Ejemplo n.º 8
0
 private function test()
 {
     echo "\nCall Staticly:\n";
     TestClass::create('first', 'second');
     echo "\nCall Directly:\n";
     new TestClass('first', 'second');
 }
 public function testInstance()
 {
     $this->assertTrue(AutoLoader::instance() instanceof AutoLoader);
     $this->assertTrue(TestClass::isLoaded());
     $this->assertTrue(TestClass2::isLoaded());
     $this->assertTrue(TestClass3::isLoaded());
 }
Ejemplo n.º 10
0
 public function testGetCachedStaticMethod()
 {
     $this->assertCacheBackendSetUp();
     TestClass::resetStaticMethodCalls();
     $f = array('CachalotTest\\TestClass', 'staticMethod');
     foreach ($this->getCachedTestCases() as $test => $data) {
         $this->assertEquals($data[1], static::$cache->getCached($f, $data, self::ttl));
         $this->assertEquals($this->countHits('static-method', $test), TestClass::getStaticMethodCalls());
         $this->assertEquals($data[1], static::$cache->getCached($f, $data, self::ttl));
         $this->assertEquals($this->countHits('static-method', $test), TestClass::getStaticMethodCalls());
     }
 }
Ejemplo n.º 11
0
<?php

require '../lib/TestClass.php';
$array = TestClass::Elements();
var_dump($array);
Ejemplo n.º 12
0
    {
        return static::staticFunction();
    }
}
class ChildClass1 extends TestClass
{
    protected static $staticVar = 'ChildClassStatic';
    const CLASS_CONST = 'ChildClassConst';
    protected static function staticFunction()
    {
        return 'ChildClassFunction';
    }
}
class ChildClass2 extends TestClass
{
}
$testClass = new TestClass();
$childClass1 = new ChildClass1();
$childClass2 = new ChildClass2();
echo $testClass->testStaticVar() . "\n";
echo $testClass->testClassConst() . "\n";
echo $testClass->testStaticFunction() . "\n";
echo $childClass1->testStaticVar() . "\n";
echo $childClass1->testClassConst() . "\n";
echo $childClass1->testStaticFunction() . "\n";
echo $childClass2->testStaticVar() . "\n";
echo $childClass2->testClassConst() . "\n";
echo $childClass2->testStaticFunction() . "\n";
?>
==DONE==
Ejemplo n.º 13
0
<!DOCTYPE html>
<html>
	<head>
		<title><?php 
echo Configuration::$WebName;
?>
</title>
		<meta charset="utf-8" />
	</head>
	<body>
<?php 
$a = new TestClass();
$a->sayhello();
echo "<br />";
echo Configuration::$WebPath;
?>
	</body>
</html>
Ejemplo n.º 14
0
 static function __static()
 {
     self::$initializerCalled = TRUE;
 }
Ejemplo n.º 15
0
<?php

class TestClass
{
    function __construct()
    {
        self::Test1();
        $this->Test1();
    }
    static function Test1()
    {
        var_dump($this);
    }
    static function Test2($this)
    {
        var_dump($this);
    }
}
$obj = new TestClass();
TestClass::Test2(new stdClass());
?>
===DONE===
Ejemplo n.º 16
0
 public function subtract($value)
 {
     self::$currentValue = self::$currentValue - $value;
     return $this;
 }
Ejemplo n.º 17
0
<?php

$db = new MySQLDalc();
$tc = new TestClass($db);
$ulist = $tc->testMethod();
echo '<pre>';
print_r($ulist);
echo '</pre>';
Ejemplo n.º 18
0
<?php

$c = new TestClass();
$c->testwithctx();
testnoctx();
function testnoctx()
{
    echo "testing from anonymous context\n";
    echo "testvar set before Req? " . isset($testvar) . "\n";
    require 'reqtests/mod.php';
    echo "testvar set after Req? " . isset($testvar) . "\n";
}
class TestClass
{
    private $var = 'hello';
    public function testwithctx()
    {
        echo "value of var before ReqOnce: " . $this->var . "\n";
        require_once 'reqtests/mod.php';
        echo "value of var after ReqOnce: " . $this->var . "\n";
        echo "testvar set after ReqOnce? " . isset($testvar) . "\n";
    }
}
 /** @test */
 public function it_allows_other_classes_to_call_method_to_get_paginated_load_more()
 {
     $testClass = new TestClass();
     $results = $testClass->paginatedLoadMore(9, 3, new Post());
     $this->assertTrue(is_array($results));
 }
Ejemplo n.º 20
0
 /**
  * Attaching handler test.
  * @return void
  */
 public function testAttachingHandler()
 {
     $obj = new TestClass();
     $var = (object) NULL;
     $obj->onPublic[] = 'handler';
     $obj->onPublic($var);
     $this->assertEquals(1, $var->counter);
     $obj->onPublic[] = new Handler();
     $obj->onPublic($var);
     $this->assertEquals(3, $var->counter);
 }
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php 
include './TestClass.php';
$test = new TestClass('testing');
echo $test->getTest();
//$test->
?>
    </body>
</html>
Ejemplo n.º 22
0
 public function getViewData(array $params = array())
 {
     $junitReportFile = $this->getPtrProjectBuild()->getBuildDir() . CINTIENT_JUNIT_REPORT_FILENAME;
     if (!is_file($junitReportFile)) {
         SystemEvent::raise(SystemEvent::ERROR, "Junit file not found. [PID={$this->getProjectId()}] [BUILD={$this->getProjectBuildId()}] [FILE={$junitReportFile}]", __METHOD__);
         return false;
     }
     try {
         $xml = new SimpleXMLElement($junitReportFile, 0, true);
     } catch (Exception $e) {
         SystemEvent::raise(SystemEvent::ERROR, "Problems processing Junit XML file. [PID={$this->getProjectId()}] [BUILD={$this->getProjectBuildId()}]", __METHOD__);
         return false;
     }
     // Apparently using call_user_func(__FUNCTION__) inside a closure,
     // doesn't work... Anyway I'm just going for a closure here, to
     // avoid the whole function definition crap here, inside a method.
     //
     // This closure takes a SimpleXMLElement loaded with the Junit report
     // and searches for the first element with a file attribute. That
     // level is the Class Test level, and what we want here is to iterate
     // over all class tests.
     $f = function ($node) use(&$parent, &$f) {
         if (isset($node->attributes()->file)) {
             return $parent->children();
         } else {
             $parent = $node;
             return $f($node->children());
         }
     };
     $parent = $xml;
     $classTestsXml = $f($xml->children());
     $classes = array();
     foreach ($classTestsXml as $node) {
         $imageFilename = '';
         $methodsNames = array();
         $methods = array();
         $class = new TestClass();
         $class->setName((string) $node->attributes()->name);
         $class->setFile((string) $node->attributes()->file);
         $class->setTests((string) $node->attributes()->tests);
         $class->setAssertions((string) $node->attributes()->assertions);
         $class->setFailures((string) $node->attributes()->failures);
         $class->setErrors((string) $node->attributes()->errors);
         $class->setTime((string) $node->attributes()->time);
         $class->setChartFilename(md5($this->getProjectId() . $this->getProjectBuildId() . $class->getFile()) . '.png');
         // Right here we're exactly at the test class (file) root level,
         // with level 1 being the unit test (method of the original class)
         // and level 2 being the various datasets used in the test (each a
         // test case).
         foreach ($node->children() as $methodXml) {
             $time = (double) $methodXml->attributes()->time * 1000;
             // to milliseconds
             $methodsNames[] = (string) $methodXml->attributes()->name;
             $f = (double) $methodXml->attributes()->failures * $time / (double) $methodXml->attributes()->assertions;
             $method = new TestMethod();
             $method->setName((string) $methodXml->attributes()->name);
             $method->setTests((string) $methodXml->attributes()->tests);
             $method->setAssertions((string) $methodXml->attributes()->assertions);
             $method->setFailures((string) $methodXml->attributes()->failures);
             $method->setErrors((string) $methodXml->attributes()->errors);
             $method->setTime((string) $methodXml->attributes()->time);
             $method->setCalculatedOks((double) $time - (double) $f);
             $method->setCalculatedFaileds($f);
             $methods[] = $method;
         }
         $class->setTestMethods($methods);
         $classes[] = $class;
     }
     $ret = array();
     $ret['project_buildJunit'] = $classes;
     return $ret;
 }
Ejemplo n.º 23
0
<?php

class TestClass
{
    public static function createInstance()
    {
        return new static();
    }
}
class ChildClass extends TestClass
{
}
$testClass = TestClass::createInstance();
$childClass = ChildClass::createInstance();
echo get_class($testClass) . "\n";
echo get_class($childClass) . "\n";
?>
==DONE==
Ejemplo n.º 24
0
<?php

# Author: Benjamin Oakes <*****@*****.**>
$class = __CLASS__;
echo '$class: ' . $class . "\n";
class TestClass
{
    public static function test_static_function()
    {
        echo "Hello!\n";
        $class = __CLASS__;
        echo '$class: ' . $class . "\n";
    }
}
TestClass::test_static_function();
Ejemplo n.º 25
0
        {
            $this->events->trigger($this, __METHOD__, __CLASS__, __NAMESPACE__, null);
        }
    }
} catch (\Exception $e) {
    $success = false;
}
if ($success) {
    echo "Success!\n\n";
} else {
    echo "Failure...\n";
}
echo "    Instantiate Class -> ";
$testClass = null;
try {
    $testClass = new TestClass();
} catch (\Exception $e) {
    $success = false;
}
if ($success) {
    echo "Success!\n\n";
} else {
    echo "Failure...\n\n";
}
echo "Operations -- \n";
echo "    Instantiate Handler (And Attach as Listener) -> ";
$success = true;
$handler = null;
try {
    $handler = new Event\Handler(null, function ($e) {
        echo "\n";
Ejemplo n.º 26
0
<?php

error_reporting(E_ERROR | E_WARNING);
setlocale(LC_TIME, 'ru_RU.UTF-8');
// autoloader :-)
include_once 'cloader.php';
$results = array();
$am = new TestClass();
// for total time
$c = new Bench();
// 10 iterations for averages
for ($a = 1; $a <= 10; $a++) {
    // for one run bench
    $b = new Bench();
    for ($i = 1; $i <= 100000; $i++) {
        $nav = $am->generateMenu();
    }
    $results[] = $b->end(false);
}
echo '<pre>' . print_r($results, 1) . '</pre>';
$total = $c->end(false);
echo 'Total: ' . $total . ', Average: ' . $total / count($results);
Ejemplo n.º 27
0
 /**
  * @dataProvider numbers
  */
 public function testAdditionWorksAsExpected($x, $y, $z)
 {
     $obj = new TestClass();
     $this->assertEquals($obj->add($x, $y), $z);
 }
Ejemplo n.º 28
0
    public static function tests_pchart2()
    {
        /*
            $xmlStr = <<<EOT
        <testsuites>
        <testsuite2 name="whaever">
          <testsuite name="DatabaseTest" file="/Users/pfonseca/Dev/cintient/src/tests/DatabaseTest.php" tests="23" assertions="79" failures="0" errors="0" time="0.129403">
            <testsuite name="DatabaseTest::testExecuteNoParamsBinding" tests="5" assertions="15" failures="0" errors="0" time="0.028787">
              <testcase name="testExecuteNoParamsBinding with data set #0" assertions="3" time="0.010916"/>
              <testcase name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
              <testcase name="testExecuteNoParamsBinding with data set #2" assertions="3" time="0.004264"/>
              <testcase name="testExecuteNoParamsBinding with data set #3" assertions="3" time="0.004306"/>
              <testcase name="testExecuteNoParamsBinding with data set #4" assertions="3" time="0.004747"/>
            </testsuite>
            <testsuite name="DatabaseTest::testQueryNoParamsBinding" tests="1" assertions="3" failures="0" errors="0" time="0.004441">
              <testcase name="testQueryNoParamsBinding with data set #0" assertions="3" time="0.004441"/>
            </testsuite>
            <testsuite name="DatabaseTest::testQueryParamsBinding" tests="1" assertions="3" failures="0" errors="0" time="0.004417">
              <testcase name="testQueryParamsBinding with data set #0" assertions="3" time="0.004417"/>
            </testsuite>
            <testsuite name="DatabaseTest::testQueryParamsBindingExcessValues" tests="1" assertions="3" failures="0" errors="0" time="0.005673">
              <testcase name="testQueryParamsBindingExcessValues with data set #0" assertions="3" time="0.005673"/>
            </testsuite>
          </testsuite>
        </testsuite2>
        </testsuites>
        EOT;
        */
        $xmlStr = <<<EOT
<aa>
  <aa1>
    <aa2 name="DatabaseTest" file="/Users/pfonseca/Dev/cintient/src/tests/DatabaseTest.php" tests="23" assertions="79" failures="0" errors="0" time="0.129403">
      <aa3 name="DatabaseTest::testExecuteNoParamsBinding" tests="5" assertions="15" failures="3" errors="0" time="0.028787">
        <aa41 name="testExecuteNoParamsBinding with data set #0" assertions="3" time="0.010916"/>
        <aa42 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
        <aa43 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
        <aa44 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
        <aa45 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
        <aa46 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
      </aa3>
      <aa4 name="DatabaseTest::testExecuteParamsBinding" tests="5" assertions="12" failures="1" errors="0" time="0.010916">
        <aa41 name="testExecuteNoParamsBinding with data set #0" assertions="3" time="0.010916"/>
        <aa42 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
        <aa43 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
        <aa44 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
      </aa4>
      <aa5 name="DatabaseTest::testQuery" tests="5" assertions="4" failures="0" errors="0" time="0.004554">
        <aa51 name="testExecuteNoParamsBinding with data set #0" assertions="3" time="0.010916"/>
        <aa52 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
        <aa53 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
        <aa54 name="testExecuteNoParamsBinding with data set #1" assertions="3" time="0.004554"/>
      </aa5>
      <aa6 name="DatabaseTest::testInsert" tests="5" assertions="7" failures="6" errors="0" time="0.014587">
        <aa61 name="testExecuteNoParamsBinding with data set #0" assertions="3" time="0.010916"/>
      </aa6>
      <aa7 name="DatabaseTest::testBeginTransaction" tests="5" assertions="25" failures="4" errors="0" time="0.023787">
        <aa71 name="testExecuteNoParamsBinding with data set #0" assertions="3" time="0.010916"/>
      </aa7>
      <aa6 name="DatabaseTest::testInsert" tests="5" assertions="7" failures="6" errors="0" time="0.014587">
        <aa61 name="testExecuteNoParamsBinding with data set #0" assertions="3" time="0.010916"/>
      </aa6>
      <aa7 name="DatabaseTest::testBeginTransaction" tests="5" assertions="25" failures="4" errors="0" time="0.023787">
        <aa71 name="testExecuteNoParamsBinding with data set #0" assertions="3" time="0.010916"/>
      </aa7>
    </aa2>
    <ab2 name="DatabaseTest" file="/Users/pfonseca/Dev/cintient/src/tests/DatabaseTest.php" tests="23" assertions="79" failures="0" errors="0" time="0.129403">
      <ab6 name="DatabaseTest::testInsert" tests="5" assertions="7" failures="6" errors="0" time="0.018787">
        <ab61 name="testExecuteNoParamsBinding with data set #0" assertions="3" time="0.010916"/>
      </ab6>
      <ab7 name="DatabaseTest::testBeginTransaction" tests="5" assertions="25" failures="4" errors="0" time="0.028787">
        <ab71 name="testExecuteNoParamsBinding with data set #0" assertions="3" time="0.010916"/>
      </ab7>
    </ab2>
  </aa1>
</aa>
EOT;
        //
        // Access file testsuites directly (last level before testcases).
        // This can't be a closure because of its recursiveness.
        //
        function f($node)
        {
            if (isset($node->attributes()->file)) {
                return $node;
            } else {
                return f($node->children());
            }
        }
        $xml = new SimpleXMLElement($xmlStr);
        $classes = array();
        $xmls = $xml->children();
        /*
            foreach ($xmls as $node) {
              $getRootNode = f($node);
              $classXml = f($node);
              $class = new TestClass();
              $class->setName($classXml->getName());
              $class->setFile((string)$classXml->attributes()->file);
              $class->setTests((string)$classXml->attributes()->tests);
              $class->setAssertions((string)$classXml->attributes()->assertions);
              $class->setFailures((string)$classXml->attributes()->failures);
              $class->setErrors((string)$classXml->attributes()->errors);
              $class->setTime((string)$classXml->attributes()->time);
        
              $methods = array();
              foreach ($classXml->children() as $methodXml) {
                $method = new TestMethod();
                $method->setName($methodXml->getName());
                $method->setTests((string)$methodXml->attributes()->tests);
                $method->setAssertions((string)$methodXml->attributes()->assertions);
                $method->setFailures((string)$methodXml->attributes()->failures);
                $method->setErrors((string)$methodXml->attributes()->errors);
                $method->setTime((string)$methodXml->attributes()->time);
        
                $cases = array();
                foreach ($methodXml->children() as $caseXml) {
                  $case = new TestCase();
                  $case->setName((string)$caseXml->getName());
                  $case->setAssertions((string)$caseXml->attributes()->assertions);
                  $case->setTime((string)$caseXml->attributes()->time);
                  $cases[] = $case;
                }
                $method->setTestCases($cases);
                $methods[] = $method;
              }
              $class->setTestMethods($methods);
              $classes[] = $class;
            }*/
        foreach ($xmls as $node) {
            $assertions = 0;
            // total number of "test" points
            $successes = array();
            // assertions - failures
            $failures = array();
            $testMethods = array();
            $classXml = f($node);
            $class = new TestClass();
            $class->setName($classXml->getName());
            $class->setFile((string) $classXml->attributes()->file);
            $class->setTests((string) $classXml->attributes()->tests);
            $class->setAssertions((string) $classXml->attributes()->assertions);
            $class->setFailures((string) $classXml->attributes()->failures);
            $class->setErrors((string) $classXml->attributes()->errors);
            $class->setTime((string) $classXml->attributes()->time);
            $methods = array();
            $i = 0;
            foreach ($classXml->children() as $methodXml) {
                $method = new TestMethod();
                $method->setName($methodXml->getName());
                $method->setTests((string) $methodXml->attributes()->tests);
                $method->setAssertions((string) $methodXml->attributes()->assertions);
                $method->setFailures((string) $methodXml->attributes()->failures);
                $method->setErrors((string) $methodXml->attributes()->errors);
                $method->setTime((string) $methodXml->attributes()->time);
                /*
                $cases = array();
                foreach ($methodXml->children() as $caseXml) {
                  $case = new TestCase();
                  $case->setName((string)$caseXml->getName());
                  $case->setAssertions((string)$caseXml->attributes()->assertions);
                  $case->setTime((string)$caseXml->attributes()->time);
                  $cases[] = $case;
                }
                $method->setTestCases($cases);
                */
                $methods[] = $method;
                $time = (double) $methodXml->attributes()->time * 1000;
                // to milliseconds
                $testMethods[] = $methodXml->attributes()->name;
                $f = (double) $methodXml->attributes()->failures * $time / (double) $methodXml->attributes()->assertions;
                $successes[] = (double) $time - (double) $f;
                $failures[] = $f;
                $i++;
            }
            $chartWidth = 700;
            if ($i == 1) {
                $i++;
            }
            $chartHeight = 25 * $i + 60;
            /* pChart library inclusions */
            include 'lib/pChart/class/pData.class';
            include 'lib/pChart/class/pDraw.class';
            include 'lib/pChart/class/pImage.class';
            $MyData = new pData();
            $MyData->addPoints($successes, "Ok");
            $MyData->addPoints($failures, "Fail");
            $MyData->setPalette("Ok", array("R" => 124, "G" => 196, "B" => 0, "Alpha" => 100));
            $MyData->setPalette("Fail", array("R" => 254, "G" => 15, "B" => 0, "Alpha" => 100));
            $MyData->setAxisName(0, "Time (ms)");
            //$MyData->setAxisUnit(0,"ms");
            $MyData->addPoints($testMethods, " ");
            $MyData->setAbscissa(" ");
            /* Create the pChart object */
            //
            // ~40px for each test
            //
            $myPicture = new pImage($chartWidth, $chartHeight, $MyData);
            $myPicture->Antialias = false;
            $myPicture->drawGradientArea(0, 0, $chartWidth, $chartHeight, DIRECTION_VERTICAL, array("StartR" => 100, "StartG" => 100, "StartB" => 100, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100));
            /* Write the picture title */
            $myPicture->setFontProperties(array("FontName" => CINTIENT_INSTALL_DIR . "lib/pChart/fonts/pf_arma_five.ttf", "FontSize" => 6, "R" => 255, "G" => 255, "B" => 255));
            $myPicture->drawText(10, 13, "Unit tests on " . $classXml->getName(), array("R" => 255, "G" => 255, "B" => 255));
            /* Draw the scale and the chart */
            $myPicture->setGraphArea(240, 40, 640, $chartHeight - 20);
            $myPicture->drawFilledRectangle(240, 40, 640, $chartHeight - 20, array("R" => 255, "G" => 255, "B" => 255, "Surrounding" => -100, "Alpha" => 10));
            $myPicture->drawScale(array("Pos" => SCALE_POS_TOPBOTTOM, "Mode" => SCALE_MODE_ADDALL, "DrawSubTicks" => true, "MinDivHeight" => 20, 'GridTicks' => 2, 'DrawXLines' => true, 'DrawYLines' => ALL));
            $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
            $myPicture->drawStackedBarChart(array("Interleave" => 2, "Gradient" => false));
            $myPicture->drawLegend(15, $chartHeight - 15, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
            $myPicture->setShadow(FALSE);
            /* Write the chart legend */
            //$myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
            /* Render the picture (choose the best way) */
            $myPicture->autoOutput("pictures/example.drawStackedBarChart.png");
            $class->setTestMethods($methods);
            $classes[] = $class;
        }
        //
        // We're exactly at the test class (file) root level, with level 1 being
        // the unit test (method of the original class) and level 2 being
        // the various datasets used in the test (each a test case).
        //
        /* @ 700x230 Stacked bar chart drawing example. */
        exit;
    }
Ejemplo n.º 29
0
Debug::$consoleMode = FALSE;
Debug::enable();
class TestClass
{
    function test1(array $val)
    {
    }
    function test2(TestClass $val)
    {
    }
    function __toString()
    {
        return FALSE;
    }
}
$obj = new TestClass();
try {
    echo "Invalid argument #1\n";
    $obj->test1('hello');
} catch (Exception $e) {
    echo "{$e}\n\n";
}
try {
    echo "Invalid argument #2\n";
    $obj->test2('hello');
} catch (Exception $e) {
    echo "{$e}\n\n";
}
try {
    echo "Invalid toString\n";
    echo $obj;
Ejemplo n.º 30
0
        return static::CLASS_CONST;
    }
    public static function testStaticFunction()
    {
        return static::staticFunction();
    }
}
class ChildClass1 extends TestClass
{
    protected static $staticVar = 'ChildClassStatic';
    const CLASS_CONST = 'ChildClassConst';
    protected static function staticFunction()
    {
        return 'ChildClassFunction';
    }
}
class ChildClass2 extends TestClass
{
}
echo TestClass::testStaticVar() . "\n";
echo TestClass::testClassConst() . "\n";
echo TestClass::testStaticFunction() . "\n";
echo ChildClass1::testStaticVar() . "\n";
echo ChildClass1::testClassConst() . "\n";
echo ChildClass1::testStaticFunction() . "\n";
echo ChildClass2::testStaticVar() . "\n";
echo ChildClass2::testClassConst() . "\n";
echo ChildClass2::testStaticFunction() . "\n";
?>
==DONE==