1. Go to this page and download the library: Download xaerodegreaz/phpspock 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/ */
xaerodegreaz / phpspock example snippets
protected function runTest()
{
if (\PhpSpock\Adapter\PhpUnitAdapter::isSpecification($this)) {
return \PhpSpock\Adapter\PhpUnitAdapter::runTest($this);
} else {
return parent::runTest();
}
}
namespace MyExamples;
use \PhpSpock\Adapter\PhpUnitAdapter as PhpSpock;
class WithoutIntegrationTest extends \PHPUnit_Framework_TestCase
{
protected function runTest()
{
if (\PhpSpock\Adapter\PhpUnitAdapter::isSpecification($this)) {
return \PhpSpock\Adapter\PhpUnitAdapter::runTest($this);
} else {
return parent::runTest();
}
}
...
}
/**
* @test
* @spec
*/
public function thisIsMySpecificationStyleTest()
{
...
}
/**
* @test
*/
public function thisIsAlsoBecauseItEndsWithSpec()
{
...
}
/**
* @spec
* @test
*/
public function parametrizationWithExternalValueSource()
{
/**
* @var $word
*/
setup:
$myDataProvider = function() {
return explode(' ', 'When in the Course of human events it becomes necessary for one people to dissolve the political bands which have connected them with another and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature\'s God entitle them, a decent respect to the opinions of mankind
/**
* @spec
* @expectedException Exception
*/
public function testIndex()
{
when:
throw new \Exception("test");
then:
$this->fail("Exception should be thrown!");
}
/**
* @spec
*/
public function testIndexWithThrown()
{
when:
throw new \Exception("test");
then:
thrown("Exception");
}
/**
* @spec
*/
public function testIndexWithThrown3()
{
when:
throw new \RuntimeException("test");
then:
thrown("RuntimeException");
}
/**
* @spec
*/
public function testExceptionCombination()
{
when:
1==1;
then:
notThrown("RuntimeException");
_when:
throw new \RuntimeException("test");
_then:
thrown("RuntimeException");
}