Beispiel #1
0
    /**
     * @test
     * @covers Cocur\Ea\ClassFactory::addHasser()
     * @covers Cocur\Ea\ClassFactory::generate()
     */
    public function addHasserAddsHasser()
    {
        $expected = <<<EOF
class Foobar {
    private \$foo;
    function hasFoo(\$key) { return isset(\$this->foo[\$key]); }
}
EOF;
        $p = new PropertyFactory('foo', 'private');
        $c = new ClassFactory('Foobar');
        $c->addProperty($p);
        $c->addHasser($p);
        $this->assertSame($expected, $c->generate());
    }
Beispiel #2
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Cocur\Ea\ClassFactory;
use Cocur\Ea\Ea;
use Cocur\Ea\PropertyFactory;
$name = PropertyFactory::create('name', 'private');
Ea::create()->addClass(ClassFactory::create('Foo', 'Foobar')->addProperty($name)->addGetter($name)->addSetter($name))->execute();
$foo = new Foobar\Foo();
$foo->setName('Florian');
echo "name: " . $foo->getName() . "\n";
Beispiel #3
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Cocur\Ea\ClassFactory;
use Cocur\Ea\Ea;
use Cocur\Ea\PropertyFactory;
Ea::create()->addClass(ClassFactory::create('Foo', 'Foobar')->addProperty(PropertyFactory::create('foo')))->execute();
$foo = new Foobar\Foo();
$foo->foo = 'foo';
echo "foo? foo=" . $foo->foo . "\n";