SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
12.
namespace JMSPaymentPaypalBundleClient;
class Client {
[...]
public function getAuthenticateExpressCheckoutTokenUrl($token) {
$host = $this->isDebug ? 'www.sandbox.paypal.com':'www.paypal.com';
return $host;
}
}
13.
namespace ACMEPaymentBundleTestsStub;
use JMSPaymentPaypalBundleClientClient;
class PaypalClientStub extends Client {
public function getAuthenticateExpressCheckoutTokenUrl($token)
{
return '/payment/paypalFakeController';
}
}
14.
namespace ACMEPaymentBundleTestsStub;
use JMSPaymentPaypalBundleClientClient;
class PaypalClientStub extends Client {
public function request(Request $request)
{
if ($request->request->get('METHOD') == 'SetExpressCheckout') {
$response = new RawResponse(
"TOKEN=BlaBlaBla",
);
} elseif ($request->request->get('METHOD') == 'GetExpressCheckoutDetails')
{
$response = new RawResponse(
"CHECKOUTSTATUS=PaymentCompleted&ACK=Success",
);
} elseif ($request->request->get('METHOD') == 'DoExpressCheckoutPayment'){
$response = new RawResponse(
"PAYMENTINFO_0_PAYMENTSTATUS=Completed",
);
}
return $response;
}
}
15.
namespace ACMEPaymentBundleTestsStub;
use JMSPaymentPaypalBundleClientClient;
class PaypalClientStub extends Client {
public function request(Request $request)
{
if ($request->request->get('METHOD') == 'SetExpressCheckout') {
$response = new RawResponse(
"TOKEN=BlaBlaBla",
);
} elseif ($request->request->get('METHOD') == 'GetExpressCheckoutDetails')
{
$response = new RawResponse(
"CHECKOUTSTATUS=PaymentCompleted&ACK=Success",
);
} elseif ($request->request->get('METHOD') == 'DoExpressCheckoutPayment'){
$response = new RawResponse(
"PAYMENTINFO_0_PAYMENTSTATUS=Completed",
);
}
return $response;
}
}
16.
namespace ACMEPaymentBundleTestsStub;
use JMSPaymentPaypalBundleClientClient;
class PaypalClientStub extends Client {
public function request(Request $request)
{
if ($request->request->get('METHOD') == 'SetExpressCheckout') {
$response = new RawResponse(
"TOKEN=BlaBlaBla",
);
} elseif ($request->request->get('METHOD') == 'GetExpressCheckoutDetails')
{
$response = new RawResponse(
"CHECKOUTSTATUS=PaymentCompleted&ACK=Success",
);
} elseif ($request->request->get('METHOD') == 'DoExpressCheckoutPayment'){
$response = new RawResponse(
"PAYMENTINFO_0_PAYMENTSTATUS=Completed",
);
}
return $response;
}
}
18.
Control on the request
namespace ACMEPaymentBundleTestsStub;
use JMSPaymentPaypalBundleClientClient;
class PaypalClientStub extends Client {
public function request(Request $request)
{
if ($request != "OK STUFF") {
throw new Exception ("Wrong Request for Paypal
call");
}
[...]
return $response;
}
}
20.
What is “outside”?
● External API
● OS services (time)
21.
What is “outside”?
● External API
● OS services (time)
● Systems that don't exist yet
22.
What is “outside”?
● External API
● OS services (time)
● Systems that don't exist yet
● Systems that other people is working on
23.
What is “outside”?
● External API
● OS services (time)
● Systems that don't exist yet
● Systems that other people is working on
● Monsters from the inside(legacy code)
24.
The date/time case
● A user can see the next three appointments
25.
The date/time case
● A user can see the next three appointments
● A user is shown an alert in home page if she
has an appointment in the next 6 hours
26.
The date/time case
● A user can see the next three appointments
● A user is shown an alert in home page if she
has an appointment in the next 6 hours
● A user can take an appointment for the next
day, but if it is Friday the next eligible day will
be Monday
27.
namespace ACMECoreBundleService;
class Time
{
public static function getNow()
{
return new DateTime();
}
}
28.
namespace AcmeCoreBundleTestService;
class Time
{
public static $referenceTime = '2012-05-01 12:00:00';
public static $time = null;
public static function getNow()
{
if (is_null(self::$time)) {
return new DateTime(self::$referenceTime);
} else {
return new DateTime(self::$time);
}
}
}
29.
namespace AcmeCoreBundleTestService;
class Time
{
public static $referenceTime = '2012-05-01 12:00:00';
public static $time = null;
public static function getNow()
{
if (is_null(self::$time)) {
return new DateTime(self::$referenceTime);
} else {
return new DateTime(self::$time);
}
}
}
30.
Inside the fixtures
Use AcmeCoreBundleTestServiceTime;
public function load(ObjectManager $manager)
{
$appointmentToday = new Appointment();
$appointmentToday->setDateTime(new DateTime(Time::$referenceTime));
[...]
}
31.
Inside the test
Use AcmeCoreBundleTestServiceTime;
public function test_customerHome()
{
AcmeCoreBundleTestServiceTime::$time = "2012-06-01";
[...]
}
32.
Different config states
$client =
self::createClient(array('environment' => 'test_alternative'));