Merge branch 'test-format-method'
This commit is contained in:
commit
dca2081911
|
@ -24,7 +24,8 @@
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"FormatTalksBundle\\": "src/FormatTalksBundle"
|
"FormatTalksBundle\\": "src/FormatTalksBundle"
|
||||||
}
|
},
|
||||||
|
"files": ["src/helpers.php"]
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"merge-plugin": {
|
"merge-plugin": {
|
||||||
|
|
7
src/helpers.php
Normal file
7
src/helpers.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function tap($value, $callback) {
|
||||||
|
$callback($value);
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
|
@ -21,6 +21,63 @@ class FormatTalksTest extends PHPUnit_Framework_TestCase
|
||||||
$this->extension = new FormatTalksExtension();
|
$this->extension = new FormatTalksExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFormat()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'event_data' => [
|
||||||
|
'event-one' => [
|
||||||
|
'name' => 'Event One',
|
||||||
|
'location' => 'Somewhere',
|
||||||
|
'website' => 'http://event-one.com',
|
||||||
|
],
|
||||||
|
'event-two' => [
|
||||||
|
'name' => 'Event Two',
|
||||||
|
'location' => 'Somewhere else',
|
||||||
|
'website' => 'http://event-two.com',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'talks' => [
|
||||||
|
[
|
||||||
|
'title' => 'A talk',
|
||||||
|
'events' => [
|
||||||
|
['event' => 'event-one', 'date' => '2018-01-01', 'time' => '09:00'],
|
||||||
|
['event' => 'event-two', 'date' => '2018-01-30', 'time' => '12:00'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$results = $this->extension->format($data)->all();
|
||||||
|
|
||||||
|
tap($results[0], function ($result) {
|
||||||
|
$this->assertArrayHasKey('event', $result);
|
||||||
|
$this->assertArrayHasKey('talk', $result);
|
||||||
|
|
||||||
|
$this->assertEquals([
|
||||||
|
'date' => '2018-01-01',
|
||||||
|
'event' => 'event-one',
|
||||||
|
'location' => 'Somewhere',
|
||||||
|
'name' => 'Event One',
|
||||||
|
'time' => '09:00',
|
||||||
|
'website' => 'http://event-one.com',
|
||||||
|
], $result['event']);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap($results[1], function ($result) {
|
||||||
|
$this->assertArrayHasKey('event', $result);
|
||||||
|
$this->assertArrayHasKey('talk', $result);
|
||||||
|
|
||||||
|
$this->assertEquals([
|
||||||
|
'date' => '2018-01-30',
|
||||||
|
'event' => 'event-two',
|
||||||
|
'location' => 'Somewhere else',
|
||||||
|
'name' => 'Event Two',
|
||||||
|
'time' => '12:00',
|
||||||
|
'website' => 'http://event-two.com',
|
||||||
|
], $result['event']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getting all events.
|
* Test getting all events.
|
||||||
*/
|
*/
|
||||||
|
|
Reference in a new issue