By the sum of PHPUnit assertion power and Symfony2 functional testing tools the developer can obtain a deep control on the developed application.
Here you can find some suggestions on how to leverage that power.
25. 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;
}
}
28. What is “outside”?
● External API
● OS services (time)
● Systems that don't exist yet
29. What is “outside”?
● External API
● OS services (time)
● Systems that don't exist yet
● Systems that other people is working on
30. 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)
32. 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
33. 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
35. 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);
}
}
}
36. 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);
}
}
}
37. Inside the fixtures
Use AcmeCoreBundleTestServiceTime;
public function load(ObjectManager $manager)
{
$appointmentToday = new Appointment();
$appointmentToday->setDateTime(new DateTime(Time::$referenceTime));
[...]
}
38. Inside the test
Use AcmeCoreBundleTestServiceTime;
public function test_customerHome()
{
AcmeCoreBundleTestServiceTime::$time = "2012-06-01";
[...]
}