PHP code example of ekvedaras / laravel-test-helpers
1. Go to this page and download the library: Download ekvedaras/laravel-test-helpers 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/ */
ekvedaras / laravel-test-helpers example snippets
// Creates PhpUnit mock wrapped with TestHelpersMock
$this->mock($mockClass, $injectorClass, $methods, $constructorArgs, $onlyForInjector);
// Creates Mockery mock
$this->mockery($mockClass, $injectorClass, $onlyForInjector);
// Creates spy mock
$this->spy($mockClass, $injectorClass, $onlyForInjector);
$this->assertSingleton(My::class);
$tester = $this->getCommandTester(MyCommand::class);
$tester->execute($input);
$out = $tester->getDisplay();
use BuildsMocks;
$mock = $this->mock(My::class);
// Using helpers
// Equivalent
$mock->once('someMethod');
$mock->expects($this->once())->method('someMethod');
$mock->once('someMethod', $foo, $bar);
$mock->expects($this->once())->method('someMethod')->with($foo, $bar);
$mock->twice('someMethod', $foo, $bar);
$mock->expects($this->exactly(2))->method('someMethod')->with($foo, $bar);
$mock->times(3, 'someMethod', $foo, $bar)->willReturn(true);
$mock->expects($this->exactly(3))->method('someMethod')->with($foo, $bar)->willReturn(true);
$mock->any('someMethod', $foo, $bar);
$mock->expects($this->any())->method('someMethod')->with($foo, $bar);
$mock->consecutiveTwice('someMethod', [$foo], [$bar]);
$mock->expects($this->exactly(2))->method('someMethod')->withConsecutive([$foo], [$bar]);
$mock->consecutive(3, 'someMethod', [$foo], [$bar], [$foo, $bar]);
$mock->expects($this->exactly(3)->method('someMethod')->withConsecutive([$foo], [$bar], [$foo, $bar]);
$mock->never('someMethod');
$mock->expects($this->never())->method('someMethod');
$mock->fail('someMethod', new \Exception());
$mock->expects($this->any())->method('someMethod')->willThrowException(new \Exception());
$mock->fail('someMethod', new \Exception(), $foo, $bar);
$mock->expects($this->any())->method('someMethod')->with($foo, $bar)->willThrowException(new \Exception());