PHP code example of moave / phpspec-data-provider-extension
1. Go to this page and download the library: Download moave/phpspec-data-provider-extension 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/ */
moave / phpspec-data-provider-extension example snippets
namespace spec\Coduo\ToString;
use PhpSpec\ObjectBehavior;
class StringLibrarySpec extends ObjectBehavior
{
/**
* @dataProvider positiveConversionExamples
*/
function it_convert_input_value_into_string($inputValue, $expectedValue)
{
$this->beConstructedWith($inputValue);
$this->__toString()->shouldReturn($expectedValue);
}
public function positiveConversionExamples()
{
return array(
array(1, '1'),
array(1.1, '1.1'),
array(new \DateTime, '\DateTime'),
array(array('foo', 'bar'), 'Array(2)')
);
}
}
namespace Coduo\ToString;
class StringLibrary
{
private $value;
public function __construct($value)
{
$this->value = $value;
}
public function __toString()
{
$type = gettype($this->value);
switch ($type) {
case 'array':
return sprintf('Array(%d)', count($this->value));
case 'object':
return sprintf("\\%s", get_class($this->value));
default:
return (string) $this->value;
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.