jokersk / lemon
a small tool
0.0.8
2022-08-03 07:31 UTC
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^6.1
README
Still in beta version
Install
composer require jokersk/lemon --dev
Base Usage
$obj = Lemon::createMock('foo->bar', 1); $obj->foo->bar // 1
$lemon = Lemon::createMock('foo()->bar()->bob', 1); $lemon->foo()->bar(12)->bob // 1
Mock Class
class Foo {} $foo = Lemon::mockClass(Foo::class, [ 'id' => 2 ]); $foo instanceOf Foo // true $foo->id // 2
class Foo {} $foo = Lemon::mockClass(Foo::class, [ 'name()' => 'joe' ]); $foo instanceOf Foo // true $foo->name() // 'joe'
Override class method
class Foo { public $name = 'joe'; public function name() { return 'some one'; } } $foo = Lemon::mockClass(Foo::class, [ 'name()' => '' ]); $foo->setMethod('name', function() { return $this->name; <-- $this is pointing to Foo }); $foo->name() // 'joe'
Invade
Call protected method
class Foo { protected function name() { return 'some one'; } } $foo = Lemon::invade(new Foo); $foo->name(); // 'some one'