SlideShare a Scribd company logo
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

More Related Content

What's hot

The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
MongoDB
 
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 Pipeline
Jason 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
 
Rumus VB-2
Rumus VB-2Rumus VB-2
Rumus VB-2
T. Astari
 
Experiment no 2
Experiment no 2Experiment no 2
Experiment no 2
Ankit Dubey
 
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
Niels Berglund
 
Geospatial and MongoDB
Geospatial and MongoDBGeospatial and MongoDB
Geospatial and MongoDB
Norberto 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
 
Query 311216
Query 311216Query 311216
Query 311216
Kishen_Kumar
 
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
MongoDB
 
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
Bruce 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 Story
Rachael L Moore
 
CString of MFC skills
CString of MFC skillsCString of MFC skills
CString of MFC skills
Chris Wang
 

What's hot (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
 

Viewers also liked

Machinist-caching
Machinist-cachingMachinist-caching
Machinist-caching
SuccesSoft LTDA
 
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
Acepac
 
Haas lathe operator manual
Haas lathe operator manualHaas lathe operator manual
Haas lathe operator manual
azly11
 
Extraction Of Metals
Extraction Of MetalsExtraction Of Metals
Extraction Of Metalsguest2082ec7
 
Welding Inspection Cswip
Welding Inspection CswipWelding Inspection Cswip
Welding Inspection Cswipguest831c1e
 

Viewers also liked (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
 

Similar to PHP Machinist Presentation

Effective PHP. Part 1
Effective PHP. Part 1Effective PHP. Part 1
Effective PHP. Part 1
Vasily Kartashov
 
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
Achim D. Brucker
 
Bind me if you can
Bind me if you canBind me if you can
Bind me if you can
Ovidiu Farauanu
 
Data Binding in qooxdoo
Data Binding in qooxdooData Binding in qooxdoo
Data Binding in qooxdoo
Martin Wittemann
 
Graph abstraction
Graph abstractionGraph abstraction
Graph abstraction
openCypher
 
Codified PostgreSQL Schema
Codified PostgreSQL SchemaCodified PostgreSQL Schema
Codified PostgreSQL Schema
Sean 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
 
Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
Mehmet Çetin
 
DBIx::Class beginners
DBIx::Class beginnersDBIx::Class beginners
DBIx::Class beginners
leo 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 developers
Bartosz 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órdoba
Jose Mº Muñoz
 
PostgreSQL Open SV 2018
PostgreSQL Open SV 2018PostgreSQL Open SV 2018
PostgreSQL Open SV 2018
artgillespie
 
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
Holden Karau
 
No JS and DartCon
No JS and DartConNo JS and DartCon
No JS and DartCon
anandvns
 
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
 

Similar to 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]
 

More from 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.pptx
Adam Englander
 
Practical API Security - PyCon 2019
Practical API Security - PyCon 2019Practical API Security - PyCon 2019
Practical API Security - PyCon 2019
Adam Englander
 
Threat Modeling for Dummies
Threat Modeling for DummiesThreat Modeling for Dummies
Threat Modeling for Dummies
Adam Englander
 
ZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API SecurityZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API Security
Adam Englander
 
ZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in DepthZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in Depth
Adam 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 2018
Adam Englander
 
Dutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for BeginnersDutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for Beginners
Adam 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.2
Adam 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 future
Adam 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 2018
Adam Englander
 
Practical API Security - PyCon 2018
Practical API Security - PyCon 2018Practical API Security - PyCon 2018
Practical API Security - PyCon 2018
Adam Englander
 
Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018
Adam Englander
 
Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018
Adam Englander
 
Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018
Adam 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 Future
Adam 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 REST
Adam Englander
 
ZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for BeginnersZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for Beginners
Adam 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 Coming
Adam 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 Primer
Adam 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 Behat
Adam Englander
 

More from 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
 

Recently uploaded

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 

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