PHP code example of habanero / spectre

1. Go to this page and download the library: Download habanero/spectre 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/ */

    

habanero / spectre example snippets




function sum($a, $b)
{
  return $a + $b;
}



ibe('sum()', function () {
  it('sums two numbers', function () {
    expect(sum(2, 2))->toBe(4);
  });
});

\Spectre\Base::customMatchers('toBeCustomValue', function ($expected, $value) {
  // test $value against $this->expected
  // then return true or false
  //
  // or for custom messages:
  //
  // return array(
  //   'result' => $expected === $value,
  //   'negative' => "Expected '{subject}' {verb} '{value}', but it did not",
  //   'positive' => "Did not expect '{subject}' {verb} '{value}', but it did",
  // );
});

// class
$stub = spy($namespace, $className)
    ->methods('testMethod')
    ->getMock();

$stub->expects($callback = any())
    ->method('testMethod')
    ->willReturn(42);

// function
$stub = fun($namespace, $function)
    ->expects($callback = any())
    ->willReturn(42);