PHP code example of jokersk / lemon

1. Go to this page and download the library: Download jokersk/lemon library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jokersk / lemon example snippets



$obj = Lemon::createMock('foo->bar', 1);
$obj->foo->bar // 1


$lemon = Lemon::createMock('foo()->bar()->bob', 1);
$lemon->foo()->bar(12)->bob // 1


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'


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'

class Foo {
   protected function name() {
      return 'some one';
   }
}
$foo = Lemon::invade(new Foo);
$foo->name(); // 'some one'