SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
PHP Machinist
 Testing Object Factory
Primary Contributors




Stephan Soileau                       Adam Englander
●   Former Employee                   ●   Selling Source Employee
●   Current lead developer on         ●   Current lead developer for CMG
    Cassandra 3.0                     ●   Famously rode on the shirt tails
●   Testing evangelist and BDD guru       of Stephan to BDD fame and
                                          glory
Why PHP Machinist Was Created
● Behat, a Cucumber port is born.
  ○ Factory Girl/Machinist port for handling relational
    data as Gherkin tables is needed.
● DBUnit, a PHP port of DBUnit is just as
  terrible as DBUnit.
  ○ XML data structure too verbose
  ○ Large relational datasets are unmanageable
● Phactory is almost good enough but would
  not handle compound primary keys.
  ○ Phactory blueprints are very similar but does not
    handle compound keys.
  ○ Only supports PDO data sources
Connecting to Your Data
PHP Machinist provides a standard interface
with the following provided implementations:
● PDO
  ○ SQLite
  ○ MySQL
● Doctrine ORM
● Experimental NoSQL available in doctrine-
  mongodb branch
  ● Doctrine MongoDB
  ● MongoDB
Connection Example: PDO SQLite
Easy way:
$pdo = new PDO("sqlite::memory:");
machinistMachinist::Store(SqlStore::fromPdo($pdo));



Hard way:
$pdo = new PDO("sqlite::memory:");
$store = new machinistdriverSqlite($pdo);
machinistMachinist::Store($store);
Blueprints Define Data Structures
Blueprints define the data structure by:
● Defining tables with aliases
● Define default values
● Define relationships
● Useable in PHPUnit tests and Behat context
Blueprints Example
Create a blueprint called "cardboardbox" on table "box" and default the "type"
to "cardboard"
$cbBox = Machinist::Blueprint("cardboardbox", "box", array("type" => "cardboard"));

Create a blueprint called "plasticbox" on table "box" and default the "type" to
"plastic"
$plBox = Machinist::Blueprint("plasticbox", "box", array("type" => "plastic"));

Create a blueprint called "crayon" on table "stuff" with "name" defaulted to
"crayon" and a relationship called box that references the the "box_id" column
in the "stuff" table. If foreign method is not called, the primary key for the
foreign key is assumed.
Machinist::Blueprint("crayon", "stuff"
   array(
      "name" => "crayon",
      "box" => Machinist::Relationship($cbBox)->local("box_id"),
   )
);
make() Stores Data
● Make stores data in the tables.
● It will use default data.
● It will override the default data with data
  provided in the make call.
● Relationship data, if provided will be
  associated or added if it does not exist.
● Relationship data will use defaults for data
  not provided in the make call.
make() Example: Save Data
$cbBox = Machinist::Blueprint("cardboardbox", "box", array("type" => "cardboard"));
$plBox = Machinist::Blueprint("plasticbox", "box", array("type" => "plastic"));

Machinist::Blueprint("crayon", "stuff"
   array(
      "name" => "crayon"
      "box" => Machinist::Relationship($cbBox)->local("box_id"),
   )
);


Make a crayon with the "name" defaulted to "crayon"
Machinist::Blueprint("crayon")->make();


Make a crayon with the "name"of "red crayon" and "color" of "red"
Machinist::Blueprint("crayon")->make(array(
     "name" => "red crayon",
     "color" => "red"
);
make() Example: Save Related Data
$cbBox = Machinist::Blueprint("cardboardbox", "box", array("type" => "cardboard"));
$plBox = Machinist::Blueprint("plasticbox", "box", array("type" => "plastic"));
Machinist::Blueprint("crayon", "stuff"
   array(
      "name" => "crayon"
      "box" => Machinist::Relationship($cbBox)->local("box_id"),
   )
);


Make a crayon with the no associated box
Machinist::Blueprint("crayon")->make();


Make a crayon with a box and create the box as none exists
Machinist::Blueprint("crayon")->make(array("box" => array("type" => "new type")));


Make a new crayon with a box and use the same box as it exists
Machinist::Blueprint("crayon")->make(array("box" => array("type" => "new type")));
find() Retrieves Data data
Find finds all rows by criteria.
FindOne finds one row by criteria
FindOrCreate finds one row by criteria or
creates a row using the criteria as data.
Find retrieves data by:
● Primary key
● Column/Value array
● Foreign key relationship data
Find populates relationship data if relational
data exists.
Machine objects are returned by Find*
find() Example
$cbBox = Machinist::Blueprint("cardboardbox", "box", array("type" => "cardboard"));
$plBox = Machinist::Blueprint("plasticbox", "box", array("type" => "plastic"));
Machinist::Blueprint("crayon", "stuff"
   array(
      "name" => "crayon"
      "box" => Machinist::Relationship($cbBox)->local("box_id"),
   )
);
Machinist::Blueprint("crayon")->make();
Machinist::Blueprint("crayon")->make(array("box" => array()));
$boxes = Machinist::Blueprint("crayon")->find("name" => "crayon")->toArray();
Result
array(
    array("name" => "crayon", ...) ,
    array("name" => "crayon", "box" => array("type" => "cardboard",...),...)
)
wipe() Cleans Up Test Data
● Wipe is available at two levels:
   ○ Blueprints can perform a wipe to remove all data in
     the related table.
   ○ Machinist instance method can clean up data for
     tables related to all defined machines.
   ○ Machinst static method can clean up data for one or
     more machines.
● Wipe can delete data or truncate tables if the
  Store implentation supports the feature.
● Machinist level wipe can specify exclusions
  as an array of blueprint names
wipe() Examples
Truncate the "crayon" blueprint's table

machinistMachinist::wipe("crayon", true);
machinistMachinist::Blueprint("crayon", true);


Truncate all blueprints tables but the "cbBox" blueprint's
table

machinistMachinist::wipe(null, true, array("cbBox"));
machinistMachinist::instance()->wipe(true, array("cbBox"));
Behat Usage
PHP Machinist is designed to be utilized within
Behat features with little to no additional work.
It supplies:
● Feature context that can be added to the
    default feature context
● Steps for populating data as well as
    validating data
● Easy Gherkin table interface
Behat Example: Feature Context
class FeatureContext extends BehatContext implements ClosuredContextInterface {


  public function __construct(array $parameters) {
      $config = array(
           "database" => array(
               "default" => array("dsn" => "sqlite::memory:")
           )
      );


      $context = new machinistbehatMachinistContext($config);
      $this->useContext('machinist', $this->getMachinistContext());
  }
Behat Example
Feature: Cardboard Box
    As a crayon
    I should be able to have a cardboard box
Background:
 Given there are no machines
 And the following crayons exists:
    | color | box          |
    | red   | type: plastic |



● Performed a wipe on all Blueprints
● Performed a make on the "crayon" blueprint with the
      "color" column set to red
●     Performed a findOrCreate on the blueprint in the "box"
      association, "cbBox", with a type of plastic

Weitere ähnliche Inhalte

Was ist angesagt?

The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation FrameworkMongoDB
 
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013PostgresOpen
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineJason Terpko
 
Aggregation Framework
Aggregation FrameworkAggregation Framework
Aggregation FrameworkMongoDB
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkTyler Brock
 
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...MongoDB
 
Queuing Sql Server: Utilise queues to increase performance in SQL Server
Queuing Sql Server: Utilise queues to increase performance in SQL ServerQueuing Sql Server: Utilise queues to increase performance in SQL Server
Queuing Sql Server: Utilise queues to increase performance in SQL ServerNiels Berglund
 
Geospatial and MongoDB
Geospatial and MongoDBGeospatial and MongoDB
Geospatial and MongoDBNorberto Leite
 
Building Applications with MongoDB - an Introduction
Building Applications with MongoDB - an IntroductionBuilding Applications with MongoDB - an Introduction
Building Applications with MongoDB - an IntroductionMongoDB
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)Mike Dirolf
 
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & AggregationWebinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & AggregationMongoDB
 
Do something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databasesDo something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databasesBruce McPherson
 
Geospatial Enhancements in MongoDB 2.4
Geospatial Enhancements in MongoDB 2.4Geospatial Enhancements in MongoDB 2.4
Geospatial Enhancements in MongoDB 2.4MongoDB
 
Refresh Tallahassee: The RE/MAX Front End Story
Refresh Tallahassee: The RE/MAX Front End StoryRefresh Tallahassee: The RE/MAX Front End Story
Refresh Tallahassee: The RE/MAX Front End StoryRachael L Moore
 
CString of MFC skills
CString of MFC skillsCString of MFC skills
CString of MFC skillsChris Wang
 

Was ist angesagt? (20)

The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
 
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
Aggregation Framework
Aggregation FrameworkAggregation Framework
Aggregation Framework
 
Tricks
TricksTricks
Tricks
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...
 
Rumus VB-2
Rumus VB-2Rumus VB-2
Rumus VB-2
 
Experiment no 2
Experiment no 2Experiment no 2
Experiment no 2
 
Queuing Sql Server: Utilise queues to increase performance in SQL Server
Queuing Sql Server: Utilise queues to increase performance in SQL ServerQueuing Sql Server: Utilise queues to increase performance in SQL Server
Queuing Sql Server: Utilise queues to increase performance in SQL Server
 
Geospatial and MongoDB
Geospatial and MongoDBGeospatial and MongoDB
Geospatial and MongoDB
 
Building Applications with MongoDB - an Introduction
Building Applications with MongoDB - an IntroductionBuilding Applications with MongoDB - an Introduction
Building Applications with MongoDB - an Introduction
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
 
Query 311216
Query 311216Query 311216
Query 311216
 
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & AggregationWebinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
 
Do something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databasesDo something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databases
 
Geospatial Enhancements in MongoDB 2.4
Geospatial Enhancements in MongoDB 2.4Geospatial Enhancements in MongoDB 2.4
Geospatial Enhancements in MongoDB 2.4
 
Refresh Tallahassee: The RE/MAX Front End Story
Refresh Tallahassee: The RE/MAX Front End StoryRefresh Tallahassee: The RE/MAX Front End Story
Refresh Tallahassee: The RE/MAX Front End Story
 
Lab 13
Lab 13Lab 13
Lab 13
 
CString of MFC skills
CString of MFC skillsCString of MFC skills
CString of MFC skills
 

Andere mochten auch

Green Metal Formwork for construction of hi-rise building
Green Metal Formwork for construction of hi-rise buildingGreen Metal Formwork for construction of hi-rise building
Green Metal Formwork for construction of hi-rise buildingAcepac
 
Haas lathe operator manual
Haas lathe operator manualHaas lathe operator manual
Haas lathe operator manualazly11
 
Extraction Of Metals
Extraction Of MetalsExtraction Of Metals
Extraction Of Metalsguest2082ec7
 
Welding Inspection Cswip
Welding Inspection CswipWelding Inspection Cswip
Welding Inspection Cswipguest831c1e
 

Andere mochten auch (6)

Machinist-caching
Machinist-cachingMachinist-caching
Machinist-caching
 
Green Metal Formwork for construction of hi-rise building
Green Metal Formwork for construction of hi-rise buildingGreen Metal Formwork for construction of hi-rise building
Green Metal Formwork for construction of hi-rise building
 
Haas lathe operator manual
Haas lathe operator manualHaas lathe operator manual
Haas lathe operator manual
 
Lathe machine
Lathe machineLathe machine
Lathe machine
 
Extraction Of Metals
Extraction Of MetalsExtraction Of Metals
Extraction Of Metals
 
Welding Inspection Cswip
Welding Inspection CswipWelding Inspection Cswip
Welding Inspection Cswip
 

Ähnlich wie PHP Machinist Presentation

Formalizing (Web) Standards: An Application of Test and Proof
Formalizing (Web) Standards: An Application of Test and ProofFormalizing (Web) Standards: An Application of Test and Proof
Formalizing (Web) Standards: An Application of Test and ProofAchim D. Brucker
 
Graph abstraction
Graph abstractionGraph abstraction
Graph abstractionopenCypher
 
Codified PostgreSQL Schema
Codified PostgreSQL SchemaCodified PostgreSQL Schema
Codified PostgreSQL SchemaSean Chittenden
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)MongoSF
 
DBIx::Class beginners
DBIx::Class beginnersDBIx::Class beginners
DBIx::Class beginnersleo lapworth
 
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Databricks
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersBartosz Kosarzycki
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation Amit Ghosh
 
how to hack with pack and unpack
how to hack with pack and unpackhow to hack with pack and unpack
how to hack with pack and unpackDavid Lowe
 
Spark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest CórdobaSpark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest CórdobaJose Mº Muñoz
 
PostgreSQL Open SV 2018
PostgreSQL Open SV 2018PostgreSQL Open SV 2018
PostgreSQL Open SV 2018artgillespie
 
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016Apache Spark Structured Streaming for Machine Learning - StrataConf 2016
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016Holden Karau
 
No JS and DartCon
No JS and DartConNo JS and DartCon
No JS and DartConanandvns
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]testduser1
 

Ähnlich wie PHP Machinist Presentation (20)

Effective PHP. Part 1
Effective PHP. Part 1Effective PHP. Part 1
Effective PHP. Part 1
 
Formalizing (Web) Standards: An Application of Test and Proof
Formalizing (Web) Standards: An Application of Test and ProofFormalizing (Web) Standards: An Application of Test and Proof
Formalizing (Web) Standards: An Application of Test and Proof
 
Bind me if you can
Bind me if you canBind me if you can
Bind me if you can
 
Data Binding in qooxdoo
Data Binding in qooxdooData Binding in qooxdoo
Data Binding in qooxdoo
 
Graph abstraction
Graph abstractionGraph abstraction
Graph abstraction
 
Mongo db
Mongo dbMongo db
Mongo db
 
Codified PostgreSQL Schema
Codified PostgreSQL SchemaCodified PostgreSQL Schema
Codified PostgreSQL Schema
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)
 
Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
 
DBIx::Class beginners
DBIx::Class beginnersDBIx::Class beginners
DBIx::Class beginners
 
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
 
Latinoware
LatinowareLatinoware
Latinoware
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
 
how to hack with pack and unpack
how to hack with pack and unpackhow to hack with pack and unpack
how to hack with pack and unpack
 
Spark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest CórdobaSpark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest Córdoba
 
PostgreSQL Open SV 2018
PostgreSQL Open SV 2018PostgreSQL Open SV 2018
PostgreSQL Open SV 2018
 
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016Apache Spark Structured Streaming for Machine Learning - StrataConf 2016
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016
 
No JS and DartCon
No JS and DartConNo JS and DartCon
No JS and DartCon
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]
 

Mehr von Adam Englander

Making PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxAdam Englander
 
Practical API Security - PyCon 2019
Practical API Security - PyCon 2019Practical API Security - PyCon 2019
Practical API Security - PyCon 2019Adam Englander
 
Threat Modeling for Dummies
Threat Modeling for DummiesThreat Modeling for Dummies
Threat Modeling for DummiesAdam Englander
 
ZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API SecurityZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API SecurityAdam Englander
 
ZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in DepthZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in DepthAdam Englander
 
Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018Adam Englander
 
Dutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for BeginnersDutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for BeginnersAdam Englander
 
php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2Adam Englander
 
php[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the futurephp[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the futureAdam Englander
 
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018Adam Englander
 
Practical API Security - PyCon 2018
Practical API Security - PyCon 2018Practical API Security - PyCon 2018
Practical API Security - PyCon 2018Adam Englander
 
Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018Adam Englander
 
Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018Adam Englander
 
Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018Adam Englander
 
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the FutureConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the FutureAdam Englander
 
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your RESTCon Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your RESTAdam Englander
 
ZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for BeginnersZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for BeginnersAdam Englander
 
ZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is ComingZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is ComingAdam Englander
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerAdam Englander
 
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and BehatSymfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and BehatAdam Englander
 

Mehr von Adam Englander (20)

Making PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptx
 
Practical API Security - PyCon 2019
Practical API Security - PyCon 2019Practical API Security - PyCon 2019
Practical API Security - PyCon 2019
 
Threat Modeling for Dummies
Threat Modeling for DummiesThreat Modeling for Dummies
Threat Modeling for Dummies
 
ZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API SecurityZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API Security
 
ZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in DepthZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in Depth
 
Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018
 
Dutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for BeginnersDutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for Beginners
 
php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2
 
php[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the futurephp[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the future
 
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
 
Practical API Security - PyCon 2018
Practical API Security - PyCon 2018Practical API Security - PyCon 2018
Practical API Security - PyCon 2018
 
Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018
 
Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018
 
Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018
 
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the FutureConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
 
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your RESTCon Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
 
ZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for BeginnersZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for Beginners
 
ZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is ComingZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is Coming
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
 
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and BehatSymfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
 

Kürzlich hochgeladen

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Kürzlich hochgeladen (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

PHP Machinist Presentation

  • 1. PHP Machinist Testing Object Factory
  • 2. Primary Contributors Stephan Soileau Adam Englander ● Former Employee ● Selling Source Employee ● Current lead developer on ● Current lead developer for CMG Cassandra 3.0 ● Famously rode on the shirt tails ● Testing evangelist and BDD guru of Stephan to BDD fame and glory
  • 3. Why PHP Machinist Was Created ● Behat, a Cucumber port is born. ○ Factory Girl/Machinist port for handling relational data as Gherkin tables is needed. ● DBUnit, a PHP port of DBUnit is just as terrible as DBUnit. ○ XML data structure too verbose ○ Large relational datasets are unmanageable ● Phactory is almost good enough but would not handle compound primary keys. ○ Phactory blueprints are very similar but does not handle compound keys. ○ Only supports PDO data sources
  • 4. Connecting to Your Data PHP Machinist provides a standard interface with the following provided implementations: ● PDO ○ SQLite ○ MySQL ● Doctrine ORM ● Experimental NoSQL available in doctrine- mongodb branch ● Doctrine MongoDB ● MongoDB
  • 5. Connection Example: PDO SQLite Easy way: $pdo = new PDO("sqlite::memory:"); machinistMachinist::Store(SqlStore::fromPdo($pdo)); Hard way: $pdo = new PDO("sqlite::memory:"); $store = new machinistdriverSqlite($pdo); machinistMachinist::Store($store);
  • 6. Blueprints Define Data Structures Blueprints define the data structure by: ● Defining tables with aliases ● Define default values ● Define relationships ● Useable in PHPUnit tests and Behat context
  • 7. Blueprints Example Create a blueprint called "cardboardbox" on table "box" and default the "type" to "cardboard" $cbBox = Machinist::Blueprint("cardboardbox", "box", array("type" => "cardboard")); Create a blueprint called "plasticbox" on table "box" and default the "type" to "plastic" $plBox = Machinist::Blueprint("plasticbox", "box", array("type" => "plastic")); Create a blueprint called "crayon" on table "stuff" with "name" defaulted to "crayon" and a relationship called box that references the the "box_id" column in the "stuff" table. If foreign method is not called, the primary key for the foreign key is assumed. Machinist::Blueprint("crayon", "stuff" array( "name" => "crayon", "box" => Machinist::Relationship($cbBox)->local("box_id"), ) );
  • 8. make() Stores Data ● Make stores data in the tables. ● It will use default data. ● It will override the default data with data provided in the make call. ● Relationship data, if provided will be associated or added if it does not exist. ● Relationship data will use defaults for data not provided in the make call.
  • 9. make() Example: Save Data $cbBox = Machinist::Blueprint("cardboardbox", "box", array("type" => "cardboard")); $plBox = Machinist::Blueprint("plasticbox", "box", array("type" => "plastic")); Machinist::Blueprint("crayon", "stuff" array( "name" => "crayon" "box" => Machinist::Relationship($cbBox)->local("box_id"), ) ); Make a crayon with the "name" defaulted to "crayon" Machinist::Blueprint("crayon")->make(); Make a crayon with the "name"of "red crayon" and "color" of "red" Machinist::Blueprint("crayon")->make(array( "name" => "red crayon", "color" => "red" );
  • 10. make() Example: Save Related Data $cbBox = Machinist::Blueprint("cardboardbox", "box", array("type" => "cardboard")); $plBox = Machinist::Blueprint("plasticbox", "box", array("type" => "plastic")); Machinist::Blueprint("crayon", "stuff" array( "name" => "crayon" "box" => Machinist::Relationship($cbBox)->local("box_id"), ) ); Make a crayon with the no associated box Machinist::Blueprint("crayon")->make(); Make a crayon with a box and create the box as none exists Machinist::Blueprint("crayon")->make(array("box" => array("type" => "new type"))); Make a new crayon with a box and use the same box as it exists Machinist::Blueprint("crayon")->make(array("box" => array("type" => "new type")));
  • 11. find() Retrieves Data data Find finds all rows by criteria. FindOne finds one row by criteria FindOrCreate finds one row by criteria or creates a row using the criteria as data. Find retrieves data by: ● Primary key ● Column/Value array ● Foreign key relationship data Find populates relationship data if relational data exists. Machine objects are returned by Find*
  • 12. find() Example $cbBox = Machinist::Blueprint("cardboardbox", "box", array("type" => "cardboard")); $plBox = Machinist::Blueprint("plasticbox", "box", array("type" => "plastic")); Machinist::Blueprint("crayon", "stuff" array( "name" => "crayon" "box" => Machinist::Relationship($cbBox)->local("box_id"), ) ); Machinist::Blueprint("crayon")->make(); Machinist::Blueprint("crayon")->make(array("box" => array())); $boxes = Machinist::Blueprint("crayon")->find("name" => "crayon")->toArray(); Result array( array("name" => "crayon", ...) , array("name" => "crayon", "box" => array("type" => "cardboard",...),...) )
  • 13. wipe() Cleans Up Test Data ● Wipe is available at two levels: ○ Blueprints can perform a wipe to remove all data in the related table. ○ Machinist instance method can clean up data for tables related to all defined machines. ○ Machinst static method can clean up data for one or more machines. ● Wipe can delete data or truncate tables if the Store implentation supports the feature. ● Machinist level wipe can specify exclusions as an array of blueprint names
  • 14. wipe() Examples Truncate the "crayon" blueprint's table machinistMachinist::wipe("crayon", true); machinistMachinist::Blueprint("crayon", true); Truncate all blueprints tables but the "cbBox" blueprint's table machinistMachinist::wipe(null, true, array("cbBox")); machinistMachinist::instance()->wipe(true, array("cbBox"));
  • 15. Behat Usage PHP Machinist is designed to be utilized within Behat features with little to no additional work. It supplies: ● Feature context that can be added to the default feature context ● Steps for populating data as well as validating data ● Easy Gherkin table interface
  • 16. Behat Example: Feature Context class FeatureContext extends BehatContext implements ClosuredContextInterface { public function __construct(array $parameters) { $config = array( "database" => array( "default" => array("dsn" => "sqlite::memory:") ) ); $context = new machinistbehatMachinistContext($config); $this->useContext('machinist', $this->getMachinistContext()); }
  • 17. Behat Example Feature: Cardboard Box As a crayon I should be able to have a cardboard box Background: Given there are no machines And the following crayons exists: | color | box | | red | type: plastic | ● Performed a wipe on all Blueprints ● Performed a make on the "crayon" blueprint with the "color" column set to red ● Performed a findOrCreate on the blueprint in the "box" association, "cbBox", with a type of plastic