Exemple #1
0
 public function TestAdd()
 {
     $a = new ClassA();
     $sum = $a->Add(2, 4);
     echo 'Sum: ', $sum, PHP_EOL;
     sleep(1);
     AssertEqual($sum, 6);
 }
Exemple #2
0
 /**
  * @covers AutoloadDir::isRebuilded
  */
 public function testIsRebuilded()
 {
     //Запросим путь к тестовому классу, чтобы он уже наверняка был найден на момент запроса.
     $this->assertNotNull(Autoload::inst()->getClassPath(ClassA::get__CLASS__()));
     //Мы должны найти нагш класс без перезагрузки, так как уже нашли его ранее
     $cpDir = new AutoloadDir(DirItem::inst(Autoload::DIR_TESTS));
     $this->assertNotNull($cpDir->getClassPath(ClassA::get__CLASS__()));
     $this->assertFalse($cpDir->isRebuilded());
 }
Exemple #3
0
class ClassB extends ClassA
{
    static $prop;
}
class ClassC extends ClassB
{
}
echo "===INIT===\n";
ClassA::$prop = 'A';
ClassB::$prop = 'B';
ClassC::$prop = 'C';
var_dump(ClassA::$prop);
var_dump(ClassB::$prop);
var_dump(ClassC::$prop);
echo "===SetA===\n";
ClassA::$prop = 'A2';
var_dump(ClassA::$prop);
var_dump(ClassB::$prop);
var_dump(ClassC::$prop);
echo "===SetB===\n";
ClassB::$prop = 'B2';
var_dump(ClassA::$prop);
var_dump(ClassB::$prop);
var_dump(ClassC::$prop);
echo "===SetC===\n";
ClassC::$prop = 'C2';
var_dump(ClassA::$prop);
var_dump(ClassB::$prop);
var_dump(ClassC::$prop);
?>
===DONE===
Exemple #4
0
 /**
  * @covers PsUtil::newReflectionMethod
  */
 public function testNewReflectionMethod()
 {
     PsUtil::assertInstanceOf(PsUtil::newReflectionMethod(ClassA::get__CLASS__(), 'get__FILE__'), 'ReflectionMethod');
     PsUtil::assertInstanceOf(PsUtil::newReflectionMethod(new ClassA(), 'private_final_method'), 'ReflectionMethod');
     try {
         PsUtil::newReflectionMethod(new ClassA(), self::NOT_ALLOWED_STR);
         $this->fail('ReflectionException is expected');
     } catch (ReflectionException $ex) {
         //OK
     }
 }
<?php

require_once __DIR__ . '/../vendor/autoload.php';
include 'Entity/ClassA.php';
/** @var \Silex\Application $app */
$app = (require_once 'bootstrap.php');
/** @var \Doctrine\ORM\EntityManager $em */
$em = $app['doctrine.orm.entity_manager'];
$obj = new ClassA();
$obj->setMessage('asdasd');
$em->persist($obj);
$em->flush();
$entities = $em->getRepository('ClassA')->findAll();
dump($entities);
Exemple #6
0
 public function __construct($name, $description)
 {
     parent::__construct($name);
 }
Exemple #7
0
require 'ClassA.php';
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php 
$a = new ClassA();
$b = new ClassB();
echo $a->sayHello("Anne");
echo "<br />";
echo $b->sayHello("Bob");
echo "<br />";
echo $a->add(3, 4);
echo "<br />";
echo $b->add(2.5, 8.1);
$a->setX(5);
$b->setX(7);
echo "<br />";
echo $a->getX();
echo "<br />";
echo $b->getX();
?>
Exemple #8
0
if (ClassA::getValue("CONST5") !== false) {
    throw new Exception();
}
if (ClassB::getValue("stR1", false) !== "test") {
    throw new Exception();
}
if (ClassB::getValue("stR1", true) !== false) {
    throw new Exception();
}
if (ClassB::getValue("STR1", true) !== "test") {
    throw new Exception();
}
if (ClassB::isValidName("CONST1")) {
    throw new Exception();
}
if (!ClassA::isValidName("const1")) {
    throw new Exception();
}
if (ClassAA::isValidName("const1", true)) {
    throw new Exception();
}
if (!ClassAA::isValidName("CONST1", true)) {
    throw new Exception();
}
if (!ClassAA::isValidValue("5", false)) {
    throw new Exception();
}
if (ClassAA::isValidValue("5", true)) {
    throw new Exception();
}
if (!ClassAA::isValidValue(5, true)) {
 public function testParent()
 {
     return parent::hello() . ' ' . parent::world();
 }
/**
 * Class B
 */
class ClassB
{
    public $helloWorld = 'This is a public Hello World!';
    protected $hello = 'Hello';
}
/**
 * Class C
 */
class ClassC
{
    protected $world = 'World!';
}
$class = new ClassA();
// Expected Output : Hello World!
echo $class->test();
// Expected Output : This is a public Hello World!
echo $class->helloWorld;
########################################
#
# Example 2 - Trying to access to
# protected properties from an invalid scope
#
#########################################
// ClassA - Throws Exception
echo $class->hello . ' ' . $class->world;
/**
 * Class Invalid
 */
Exemple #11
0
class ClassA
{
    public function method1()
    {
        echo ClassB::method2();
    }
}
class ClassB
{
    public static function method2()
    {
        return 'WOOT!';
    }
}
$cls_a = new ClassA();
$cls_a->method1();
// or alternatively, you don't even need to instantiate ClassA
echo ClassB::method2();
function foo()
{
    $numargs = func_num_args();
    echo "Number of arguments: {$numargs} \n";
    if ($numargs >= 2) {
        echo "Second argument is: " . func_get_arg(1) . "\n";
    }
    $arg_list = func_get_args();
    for ($i = 0; $i < $numargs; $i++) {
        echo "Argument {$i} is: " . $arg_list[$i] . "\n";
    }
}