-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathSocialFeed.php
More file actions
42 lines (38 loc) · 1.07 KB
/
SocialFeed.php
File metadata and controls
42 lines (38 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php namespace Example;
use Exception;
/**
* Retrieve formatted social network status updates
* in a number of different formats.
*/
class SocialFeed
{
/**
* Retrieve an array of social network status updates.
*
* @return array
*/
public function getArray()
{
// Boom, testing problems!
// ---------------------------------------------------
// We can't test this code because our social feed is
// too coupled to the code that retrieves messages
// from our social network of choice (Twitter).
return $this->getMessages();
}
/**
* Retrieve an array of messages from the Twitter API.
*
* @return array
*/
public function getMessages()
{
// Fail whale!
// ---------------------------------------------------
// Let's simulate a halted connection, and a failure
// by halting the application for ten seconds and
// then throwing a new exception.
sleep(10);
throw new Exception('Connection to twitter timed out.');
}
}