Skip to content

Commit 616f6f7

Browse files
committed
Use PhpSpecDataProviderExtension to improve specs readabilty
1 parent f519ef2 commit 616f6f7

File tree

3 files changed

+23
-41
lines changed

3 files changed

+23
-41
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"php": ">=5.3.0"
1818
},
1919
"require-dev": {
20-
"phpspec/phpspec": "2.0.*"
20+
"phpspec/phpspec": "2.0.*",
21+
"coduo/phpspec-data-provider-extension": "dev-master"
2122
},
2223
"autoload": {
2324
"psr-0": {"" : "src"}

phpspec.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
extensions:
2+
- Coduo\PhpSpec\DataProviderExtension

spec/Coduo/ToString/StringSpec.php

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,32 @@ public function __toString()
1414

1515
class StringSpec extends ObjectBehavior
1616
{
17-
function it_convert_double_to_string()
17+
/**
18+
* @dataProvider positiveConversionExamples
19+
*/
20+
function it_convert_values_to_string($value, $expectedValue)
1821
{
19-
$this->beConstructedWith(1.1);
20-
$this->__toString()->shouldReturn('1.1');
22+
$this->beConstructedWith($value);
23+
$this->__toString()->shouldReturn($expectedValue);
2124
}
2225

23-
function it_convert_double_to_string_for_specific_locale()
24-
{
25-
$this->beConstructedWith(1.1, 'pl');
26-
$this->__toString()->shouldReturn('1,1');
27-
}
28-
29-
function it_convert_integer_to_string()
26+
function positiveConversionExamples()
3027
{
31-
$this->beConstructedWith(20);
32-
$this->__toString()->shouldReturn('20');
28+
return array(
29+
array(1.1, '1.1'),
30+
array(20, '20'),
31+
array(true, 'true'),
32+
array(new \stdClass(), '\stdClass'),
33+
array(new Foo(), 'This is Foo'),
34+
array(array('foo', 'bar'), 'Array(2)'),
35+
array(function() {return 'test';}, '\Closure')
36+
);
3337
}
3438

35-
function it_convert_boolean_to_string()
36-
{
37-
$this->beConstructedWith(true);
38-
$this->__toString()->shouldReturn('true');
39-
}
40-
41-
function it_convert_object_to_string()
42-
{
43-
$this->beConstructedWith(new \stdClass());
44-
$this->__toString()->shouldReturn('\stdClass');
45-
}
46-
47-
function it_convert_object_with_toString_method_to_string()
48-
{
49-
$this->beConstructedWith(new Foo());
50-
$this->__toString()->shouldReturn('This is Foo');
51-
}
52-
53-
function it_convert_array_to_string()
39+
function it_convert_double_to_string_for_specific_locale()
5440
{
55-
$this->beConstructedWith(array('foo', 'bar'));
56-
$this->__toString()->shouldReturn('Array(2)');
41+
$this->beConstructedWith(1.1, 'pl');
42+
$this->__toString()->shouldReturn('1,1');
5743
}
5844

5945
function it_convert_resource_to_string()
@@ -64,11 +50,4 @@ function it_convert_resource_to_string()
6450
fclose($resource);
6551
unlink(sys_get_temp_dir() . "/foo");
6652
}
67-
68-
function it_convert_callback_string()
69-
{
70-
$func = function() {return 'test';};
71-
$this->beConstructedWith($func);
72-
$this->__toString()->shouldReturn('\Closure');
73-
}
7453
}

0 commit comments

Comments
 (0)