PHPUnit elevato alla Symfony2

eugenio pombi
eugenio pombiHead of Engineering at blur Group
PHPUnit elevato alla Symfony2




                 Eugenio Pombi
                  Symfony Day 05 October 2012



@euxpom                                         nerd2business.net
Symfony2 Functional testing tools

●   SymfonyBundleFrameworkBundleClient
●   SymfonyBundleFrameworkBundleCrawler
●   SymfonyComponentHttpKernelProfilerProfile
●   SymfonyBundleDoctrineFixturesBundle
Profiler
config                               time
   ->getBundles()                       ->getTotalTime()
   ->getEnv()                        memory
request                                 ->getMemory()
   ->getRouteParams()                router
   ->getController()                    ->getRedirect()
exception                            security
   ->hasException()                     ->getUser()
events
                                        ->getRoles()
   ->GetCalledListeners()
                                        ->isAuthenticated()
   ->getNotCalledListeners()
                                     swiftmailer
logger
                                        ->getMessageCount()
   ->CountErrors()
                                        ->getMessages()
   ->getLogs()
Doctrine profiler
db
     ->getQueryCount()
     ->getTime()
     ->getQueries()

               query
                      ['sql']
                      ['params']
                      ['types']
                      ['executionMS']
Stubbing



An example with Paypal
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
namespace JMSPaymentPaypalBundleClient;

class Client {
    [...]
    public function request(Request $request) {
        [...]
        // perform the request
        if (false === $returnTransfer = curl_exec($curl)) {
            throw new CommunicationException(
                'cURL Error: '.curl_error($curl), curl_errno($curl)
            );
        }
        [...]
        $response = new RawResponse(
            substr($returnTransfer, $headerSize),
            curl_getinfo($curl, CURLINFO_HTTP_CODE),
            $headers
        );
        curl_close($curl);
        return $response;
    }
}
namespace JMSPaymentPaypalBundleClient;

class Client {
    [...]
    public function request(Request $request) {
        [...]
        // perform the request
        if (false === $returnTransfer = curl_exec($curl)) {
            throw new CommunicationException(
                'cURL Error: '.curl_error($curl), curl_errno($curl)
            );
        }
        [...]
        $response = new RawResponse(
            substr($returnTransfer, $headerSize),
            curl_getinfo($curl, CURLINFO_HTTP_CODE),
            $headers
        );
        curl_close($curl);
        return $response;
    }
}
namespace JMSPaymentPaypalBundleClient;

class Client {
    [...]
    public function request(Request $request) {
        [...]
        // perform the request
        if (false === $returnTransfer = curl_exec($curl)) {
            throw new CommunicationException(
                'cURL Error: '.curl_error($curl), curl_errno($curl)
            );
        }
        [...]
        $response = new RawResponse(
            substr($returnTransfer, $headerSize),
            curl_getinfo($curl, CURLINFO_HTTP_CODE),
            $headers
        );
        curl_close($curl);
        return $response;
    }
}
namespace ACMEPaymentBundleTestsStub;

use JMSPaymentPaypalBundleClientClient;

class PaypalClientStub extends Client {
    public function request(Request $request)
    {
        $response = new RawResponse(
                "TOKEN=BlaBlaBlaBla",
                200,
                array(
                  'Date' => "Fri, 07 Sep 2012 15:21:00 GMT",
                  'Server' => "Apache",
                )
        );
        return $response;
    }
}
namespace ACMEPaymentBundleTestsStub;

use JMSPaymentPaypalBundleClientClient;

class PaypalClientStub extends Client {
    public function request(Request $request)
    {
        $response = new RawResponse(
                "TOKEN=BlaBlaBlaBla",
                200,
                array(
                  'Date' => "Fri, 07 Sep 2012 15:21:00 GMT",
                  'Server' => "Apache",
                )
        );
        return $response;
    }
}
services.xml

<parameter key="payment.paypal.client.class">
    JMSPaymentPaypalBundleClientClient
</parameter>




config_test.yml

parameters:
    payment.paypal.client.class:
ACMEPaymentBundleTestsStubPaypalClientStub
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
namespace JMSPaymentPaypalBundleClient;


class Client {
    [...]
    public function getAuthenticateExpressCheckoutTokenUrl($token) {
        $host = $this->isDebug ? 'www.sandbox.paypal.com':'www.paypal.com';


        return $host;
    }
}
namespace ACMEPaymentBundleTestsStub;
use JMSPaymentPaypalBundleClientClient;


class PaypalClientStub extends Client {
    public function getAuthenticateExpressCheckoutTokenUrl($token)
    {
        return '/payment/paypalFakeController';
    }
}
PHPUnit elevato alla Symfony2
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;
    }
}
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;
    }
}
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;
    }
}
Something is missing
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;
    }
}
What is “outside”?

●   External API
What is “outside”?

●   External API
●   OS services (time)
What is “outside”?

●   External API
●   OS services (time)
●   Systems that don't exist yet
What is “outside”?

●   External API
●   OS services (time)
●   Systems that don't exist yet
●   Systems that other people is working on
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)
The date/time case
●   A user can see the next three appointments
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
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
namespace ACMECoreBundleService;

class Time
{
    public static function getNow()
    {
        return new DateTime();
    }
}
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);
        }
    }
}
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);
        }
    }
}
Inside the fixtures

Use AcmeCoreBundleTestServiceTime;


public function load(ObjectManager $manager)
{
    $appointmentToday = new Appointment();
    $appointmentToday->setDateTime(new DateTime(Time::$referenceTime));
    [...]
}
Inside the test
Use AcmeCoreBundleTestServiceTime;

public function test_customerHome()
{
  AcmeCoreBundleTestServiceTime::$time = "2012-06-01";

    [...]
}
Different config states


$client =
   self::createClient(array('environment' => 'test_alternative'));
Thank You


            @euxpom
            nerd2business.net
1 of 40

Recommended

Adding Dependency Injection to Legacy Applications by
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
1.8K views77 slides
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need by
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needKacper Gunia
50.4K views140 slides
Models and Service Layers, Hemoglobin and Hobgoblins by
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsRoss Tuck
48.3K views284 slides
Database Design Patterns by
Database Design PatternsDatabase Design Patterns
Database Design PatternsHugo Hamon
11.4K views87 slides
Command Bus To Awesome Town by
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome TownRoss Tuck
7.2K views183 slides
Decoupling with Design Patterns and Symfony2 DIC by
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICKonstantin Kudryashov
6.5K views97 slides

More Related Content

What's hot

Design Patterns avec PHP 5.3, Symfony et Pimple by
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
6.1K views68 slides
Silex meets SOAP & REST by
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & RESTHugo Hamon
14.8K views62 slides
Min-Maxing Software Costs by
Min-Maxing Software CostsMin-Maxing Software Costs
Min-Maxing Software CostsKonstantin Kudryashov
879 views96 slides
Doctrine fixtures by
Doctrine fixturesDoctrine fixtures
Doctrine fixturesBill Chang
5K views12 slides
Symfony2, creare bundle e valore per il cliente by
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteLeonardo Proietti
1.3K views73 slides
Rich domain model with symfony 2.5 and doctrine 2.5 by
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
12K views90 slides

What's hot(20)

Design Patterns avec PHP 5.3, Symfony et Pimple by Hugo Hamon
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
Hugo Hamon6.1K views
Silex meets SOAP & REST by Hugo Hamon
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
Hugo Hamon14.8K views
Doctrine fixtures by Bill Chang
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
Bill Chang5K views
Symfony2, creare bundle e valore per il cliente by Leonardo Proietti
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
Leonardo Proietti1.3K views
Rich domain model with symfony 2.5 and doctrine 2.5 by Leonardo Proietti
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
Leonardo Proietti12K views
Things I Believe Now That I'm Old by Ross Tuck
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm Old
Ross Tuck6.6K views
Object Calisthenics Adapted for PHP by Chad Gray
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHP
Chad Gray991 views
international PHP2011_Bastian Feder_jQuery's Secrets by smueller_sandsmedia
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
Decoupling the Ulabox.com monolith. From CRUD to DDD by Aleix Vergés
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
Aleix Vergés1.8K views
Rich Model And Layered Architecture in SF2 Application by Kirill Chebunin
Rich Model And Layered Architecture in SF2 ApplicationRich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
Kirill Chebunin3.7K views
PHPCon 2016: PHP7 by Witek Adamus / XSolve by XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve1K views
The IoC Hydra - Dutch PHP Conference 2016 by Kacper Gunia
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
Kacper Gunia1.2K views
Advanced php testing in action by Jace Ju
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
Jace Ju2.1K views
Crafting beautiful software by Jorn Oomen
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful software
Jorn Oomen2K views
Object Calisthenics Applied to PHP by Guilherme Blanco
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHP
Guilherme Blanco22.5K views
SOLID: the core principles of success of the Symfony web framework and of you... by Vladyslav Riabchenko
SOLID: the core principles of success of the Symfony web framework and of you...SOLID: the core principles of success of the Symfony web framework and of you...
SOLID: the core principles of success of the Symfony web framework and of you...

Similar to PHPUnit elevato alla Symfony2

Doctrine For Beginners by
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
1.5K views69 slides
Forget about Index.php and build you applications around HTTP - PHPers Cracow by
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowKacper Gunia
3.2K views127 slides
Phpne august-2012-symfony-components-friends by
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
2.8K views45 slides
Forget about index.php and build you applications around HTTP! by
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Kacper Gunia
5.7K views128 slides
WordPress REST API hacking by
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hackingJeroen van Dijk
3.7K views52 slides
Symfony components in the wild, PHPNW12 by
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Jakub Zalas
2.4K views51 slides

Similar to PHPUnit elevato alla Symfony2(20)

Doctrine For Beginners by Jonathan Wage
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage1.5K views
Forget about Index.php and build you applications around HTTP - PHPers Cracow by Kacper Gunia
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Kacper Gunia3.2K views
Phpne august-2012-symfony-components-friends by Michael Peacock
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock2.8K views
Forget about index.php and build you applications around HTTP! by Kacper Gunia
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
Kacper Gunia5.7K views
Symfony components in the wild, PHPNW12 by Jakub Zalas
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12
Jakub Zalas2.4K views
50 Laravel Tricks in 50 Minutes by Azim Kurtaliev
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
Azim Kurtaliev1.7K views
laravel tricks in 50minutes by Barang CK
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
Barang CK393 views
Mocking Dependencies in PHPUnit by mfrost503
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
mfrost503585 views
Your code sucks, let's fix it - DPC UnCon by Rafael Dohms
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
Rafael Dohms32.5K views
Symfony2 Building on Alpha / Beta technology by Daniel Knell
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
Daniel Knell750 views
Easy rest service using PHP reflection api by Matthieu Aubry
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection api
Matthieu Aubry42.5K views
Bag Of Tricks From Iusethis by Marcus Ramberg
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
Marcus Ramberg6.4K views
The Zen of Lithium by Nate Abele
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
Nate Abele2.6K views
(PHPers Wrocław #5) How to write valuable unit test? by RST Software Masters
(PHPers Wrocław #5) How to write valuable unit test?(PHPers Wrocław #5) How to write valuable unit test?
(PHPers Wrocław #5) How to write valuable unit test?
How Kris Writes Symfony Apps by Kris Wallsmith
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
Kris Wallsmith17.1K views

More from eugenio pombi

Parlo al mio codice by
Parlo al mio codiceParlo al mio codice
Parlo al mio codiceeugenio pombi
540 views21 slides
Processing one year of leading for Pug roma by
Processing one year of leading for Pug romaProcessing one year of leading for Pug roma
Processing one year of leading for Pug romaeugenio pombi
419 views16 slides
Datagrids with Symfony 2, Backbone and Backgrid by
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrideugenio pombi
684 views36 slides
Codemotion workshop by
Codemotion workshopCodemotion workshop
Codemotion workshopeugenio pombi
1.2K views76 slides
Arduino - il mio primo sketch by
Arduino - il mio primo sketchArduino - il mio primo sketch
Arduino - il mio primo sketcheugenio pombi
1.1K views44 slides
Appetite comes with testing by
Appetite comes with testingAppetite comes with testing
Appetite comes with testingeugenio pombi
456 views29 slides

More from eugenio pombi(7)

Processing one year of leading for Pug roma by eugenio pombi
Processing one year of leading for Pug romaProcessing one year of leading for Pug roma
Processing one year of leading for Pug roma
eugenio pombi419 views
Datagrids with Symfony 2, Backbone and Backgrid by eugenio pombi
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
eugenio pombi684 views
Arduino - il mio primo sketch by eugenio pombi
Arduino - il mio primo sketchArduino - il mio primo sketch
Arduino - il mio primo sketch
eugenio pombi1.1K views
Appetite comes with testing by eugenio pombi
Appetite comes with testingAppetite comes with testing
Appetite comes with testing
eugenio pombi456 views
breve introduzione a node.js by eugenio pombi
breve introduzione a node.jsbreve introduzione a node.js
breve introduzione a node.js
eugenio pombi616 views

Recently uploaded

Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...ShapeBlue
162 views25 slides
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc
176 views29 slides
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...ShapeBlue
141 views29 slides
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueShapeBlue
139 views15 slides
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...ShapeBlue
199 views20 slides
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...ShapeBlue
196 views62 slides

Recently uploaded(20)

Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue162 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc176 views
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue141 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue139 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue199 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue196 views
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ... by ShapeBlue
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
ShapeBlue129 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue164 views
LLMs in Production: Tooling, Process, and Team Structure by Aggregage
LLMs in Production: Tooling, Process, and Team StructureLLMs in Production: Tooling, Process, and Team Structure
LLMs in Production: Tooling, Process, and Team Structure
Aggregage57 views
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue108 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty65 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE84 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu437 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays36 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue265 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue208 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue183 views
Initiating and Advancing Your Strategic GIS Governance Strategy by Safe Software
Initiating and Advancing Your Strategic GIS Governance StrategyInitiating and Advancing Your Strategic GIS Governance Strategy
Initiating and Advancing Your Strategic GIS Governance Strategy
Safe Software184 views

PHPUnit elevato alla Symfony2

  • 1. PHPUnit elevato alla Symfony2 Eugenio Pombi Symfony Day 05 October 2012 @euxpom nerd2business.net
  • 2. Symfony2 Functional testing tools ● SymfonyBundleFrameworkBundleClient ● SymfonyBundleFrameworkBundleCrawler ● SymfonyComponentHttpKernelProfilerProfile ● SymfonyBundleDoctrineFixturesBundle
  • 3. Profiler config time ->getBundles() ->getTotalTime() ->getEnv() memory request ->getMemory() ->getRouteParams() router ->getController() ->getRedirect() exception security ->hasException() ->getUser() events ->getRoles() ->GetCalledListeners() ->isAuthenticated() ->getNotCalledListeners() swiftmailer logger ->getMessageCount() ->CountErrors() ->getMessages() ->getLogs()
  • 4. Doctrine profiler db ->getQueryCount() ->getTime() ->getQueries() query ['sql'] ['params'] ['types'] ['executionMS']
  • 10. namespace JMSPaymentPaypalBundleClient; class Client { [...] public function request(Request $request) { [...] // perform the request if (false === $returnTransfer = curl_exec($curl)) { throw new CommunicationException( 'cURL Error: '.curl_error($curl), curl_errno($curl) ); } [...] $response = new RawResponse( substr($returnTransfer, $headerSize), curl_getinfo($curl, CURLINFO_HTTP_CODE), $headers ); curl_close($curl); return $response; } }
  • 11. namespace JMSPaymentPaypalBundleClient; class Client { [...] public function request(Request $request) { [...] // perform the request if (false === $returnTransfer = curl_exec($curl)) { throw new CommunicationException( 'cURL Error: '.curl_error($curl), curl_errno($curl) ); } [...] $response = new RawResponse( substr($returnTransfer, $headerSize), curl_getinfo($curl, CURLINFO_HTTP_CODE), $headers ); curl_close($curl); return $response; } }
  • 12. namespace JMSPaymentPaypalBundleClient; class Client { [...] public function request(Request $request) { [...] // perform the request if (false === $returnTransfer = curl_exec($curl)) { throw new CommunicationException( 'cURL Error: '.curl_error($curl), curl_errno($curl) ); } [...] $response = new RawResponse( substr($returnTransfer, $headerSize), curl_getinfo($curl, CURLINFO_HTTP_CODE), $headers ); curl_close($curl); return $response; } }
  • 13. namespace ACMEPaymentBundleTestsStub; use JMSPaymentPaypalBundleClientClient; class PaypalClientStub extends Client { public function request(Request $request) { $response = new RawResponse( "TOKEN=BlaBlaBlaBla", 200, array( 'Date' => "Fri, 07 Sep 2012 15:21:00 GMT", 'Server' => "Apache", ) ); return $response; } }
  • 14. namespace ACMEPaymentBundleTestsStub; use JMSPaymentPaypalBundleClientClient; class PaypalClientStub extends Client { public function request(Request $request) { $response = new RawResponse( "TOKEN=BlaBlaBlaBla", 200, array( 'Date' => "Fri, 07 Sep 2012 15:21:00 GMT", 'Server' => "Apache", ) ); return $response; } }
  • 15. services.xml <parameter key="payment.paypal.client.class"> JMSPaymentPaypalBundleClientClient </parameter> config_test.yml parameters: payment.paypal.client.class: ACMEPaymentBundleTestsStubPaypalClientStub
  • 18. namespace JMSPaymentPaypalBundleClient; class Client { [...] public function getAuthenticateExpressCheckoutTokenUrl($token) { $host = $this->isDebug ? 'www.sandbox.paypal.com':'www.paypal.com'; return $host; } }
  • 19. namespace ACMEPaymentBundleTestsStub; use JMSPaymentPaypalBundleClientClient; class PaypalClientStub extends Client { public function getAuthenticateExpressCheckoutTokenUrl($token) { return '/payment/paypalFakeController'; } }
  • 21. 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; } }
  • 22. 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; } }
  • 23. 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; } }
  • 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; } }
  • 27. What is “outside”? ● External API ● OS services (time)
  • 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)
  • 31. The date/time case ● A user can see the next three appointments
  • 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
  • 34. namespace ACMECoreBundleService; class Time { public static function getNow() { return new DateTime(); } }
  • 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"; [...] }
  • 39. Different config states $client = self::createClient(array('environment' => 'test_alternative'));
  • 40. Thank You @euxpom nerd2business.net