PHP code example of dborsatto / phpspec-data-provider-extension
1. Go to this page and download the library: Download dborsatto/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/ */
dborsatto / phpspec-data-provider-extension example snippets
declare(strict_types=1);
namespace spec\DBorsatto\ToString;
use PhpSpec\ObjectBehavior;
class StringLibrarySpec extends ObjectBehavior
{
/**
* @dataProvider positiveConversionExamples
*/
public function it_convert_input_value_into_string($inputValue, $expectedValue): void
{
$this->beConstructedWith($inputValue);
$this->__toString()
->shouldReturn($expectedValue);
}
public function positiveConversionExamples(): array
{
return [
[1, '1'],
[1.1, '1.1'],
[new \DateTime, '\DateTime'],
[['foo', 'bar'], 'Array(2)']
];
}
}
declare(strict_types=1);
namespace DBorsatto\ToString;
class StringLibrary
{
private $value;
public function __construct($value)
{
$this->value = $value;
}
public function __toString(): string
{
$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;
}
}
}