implements hello_dolly

Download implements Hello_Dolly

Post on 15-Apr-2017

49 views

Category:

Software

0 download

Embed Size (px)

TRANSCRIPT

  • implementsHello_DollyImageCredit:KyonFlickrhttps://flic.kr/p/8x4bVQ

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    https://flic.kr/p/8x4bVQhttp://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • JonathanBrinley

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • "Hello,Dolly!"

    ImageCredit:ClassicFilmonFlickrhttps://flic.kr/p/KD7WWE

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    https://flic.kr/p/KD7WWEhttp://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • "Hello,Dolly!"

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • hello.php/***@packageHello_Dolly*@version1.6*//*PluginName:HelloDollyPluginURI:http://wordpress.org/plugins/hello-dolly/Description:Thisisnotjustaplugin,itsymbolizesthehopeandenthusiasmofanentiregenerationsummedupintwowordssungmostfamouslybyLouisArmstrong:Hello,Dolly.WhenactivatedyouwillrandomlyseealyricfromHello,Dollyintheupperrightofyouradminscreenoneverypage.Author:MattMullenwegVersion:1.6AuthorURI:http://ma.tt/*/

    functionhello_dolly_get_lyric(){ /**ThesearethelyricstoHelloDolly*/ $lyrics="Hello,DollyWell,hello,DollyIt'ssonicetohaveyoubackwhereyoubelongYou'relookin'swell,DollyIcantell,DollyYou'restillglowin',you'restillcrowin'You'restillgoin'strongWefeeltheroomswayin'Whiletheband'splayin'

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • Refactor!

    github.com/flightless/implements-hello-dollyImageCredit:ClassicFilmonFlickrhttps://flic.kr/p/LxazKW

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    https://github.com/flightless/implements-hello-dollyhttps://flic.kr/p/LxazKWhttp://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • implements-hello-dolly.php/*PluginName:implementsHello_DollyDescription:WestartwitheveryonesfavoriteWordPressplugin,Hello,Dolly.Withadramaticwaveofourhands,wespeakthemagicalword:Refactor!Letsseehowfarwecango.Author:JonathanBrinleyVersion:2.0Contributors:MattMullenweg*/

    namespaceHello_Dolly;

    //Startthepluginadd_action('plugins_loaded',function(){ require_once__DIR__.'/vendor/autoload.php'; Hello_Dolly_Plugin::init(); do_action('hello_dolly/init');},1,0);

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • Composer

    AutoloadingLibraries

    getcomposer.org

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    https://getcomposer.org/http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • Composercomposerinit

    {"name":"flightless/implements-hello-dolly","description":"WestartwitheveryonesfavoriteWordPressplugin,Hello,Dolly.Withadramaticwaveofourhands,wespeakthemagicalword:Refactor!Letsseehowfarwecango.""type":"wordpress-plugin","license":"GPL-2.0","authors":[{"name":"JonathanBrinley","email":"jonathan@tri.be"}]}

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • composer.json{"name":"flightless/implements-hello-dolly","description":"WestartwitheveryonesfavoriteWordPressplugin,Hello,Dolly.Withadramaticwaveofourhands,wespeakthemagicalword:Refactor!Letsseehowfarwecango.""type":"wordpress-plugin","license":"GPL-2.0","authors":[{"name":"JonathanBrinley","email":"jonathan@tri.be"}],"autoload":{"psr-4":{"Hello_Dolly\\":"src/"}}}

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • Codeceptioncomposerrequire--devlucatume/wp-browser

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • Codeception

    composerinstall--no-dev

    {"name":"flightless/implements-hello-dolly",/*...*/"autoload":{"psr-4":{"Hello_Dolly\\":"src/"}},"require-dev":{"lucatume/wp-browser":"^1.16"}}

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • WPLoadervendor/bin/wpceptbootstrap

    https://github.com/lucatume/wp-browser

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    https://github.com/lucatume/wp-browser#wploader-configurationhttp://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • tests/integration/Hello_Dolly/Hello_Dolly_Plugin_Test.phpnamespaceHello_Dolly;useCodeception\TestCase\WPTestCase;

    classHello_Dolly_Plugin_TestextendsWPTestCase{ publicfunctiontest_get_instance(){ $instance=Hello_Dolly_Plugin::instance(); $this->assertInstanceOf('Hello_Dolly\\Hello_Dolly_Plugin',$instance); }}

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • implements-hello-dolly.phpnamespaceHello_Dolly;

    //Startthepluginadd_action('plugins_loaded',function(){ require_once__DIR__.'/vendor/autoload.php'; Hello_Dolly_Plugin::init(); do_action('hello_dolly/init');},1,0);

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • src/Hello_Dolly_Plugin.phpnamespaceHello_Dolly;

    /***InitializestheHello,Dollyplugin*/classHello_Dolly_Plugin{ /**@varstatic*/ privatestatic$instance;

    /** *Initializetheplugin */ publicstaticfunctioninit(){ self::instance(); }

    /** *Gettheglobalinstanceoftheclass *@returnstatic */ publicstaticfunctioninstance(){ if(empty(static::$instance)){ static::$instance=newstatic(); } returnstatic::$instance;

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • FirstFivePrinciplesSingleresponsibilityprincipleOpen/closedprincipleLiskovsubstitutionprincipleInterfacesegregationprincipleDependencyinversionprinciple

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • SingleresponsibilityprincipleTurnastringoflyricsintoanarrayGetarandomlinefromthelyricsarrayTexturizealineoflyricsWraplyricsinaparagraphtagBuildlanguage-appropriateCSSrulesPrintthelyricstothebrowserPrintthestylerulestothebrowserHookintoWordPress

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • Lyrics\Lyric_CollectionResponsibility

    Fetchasinglelinefromanarrayoflyrics

    Whywoulditchange?

    Ifthealgorithmtofetchalinechanged

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • tests/integration/Hello_Dolly/Lyrics/Lyric_Collection_Test.phpnamespaceHello_Dolly\Lyrics;useCodeception\TestCase\WPTestCase;

    classLyric_Collection_TestextendsWPTestCase{ publicfunctiontest_get_lyric(){ $lyrics=[]; for($i=0;$iget_lyric(),$lyrics); } }}

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • Lyrics\Lyric_CollectionnamespaceHello_Dolly\Lyrics;

    classLyric_CollectionimplementsLyric_Collection_Interface{ /**@varstring[]*/ protected$lyrics;

    /**@varint*/ protected$count=0;

    /** *Lyric_Collectionconstructor. * *@paramarray$lyricsAnarrayofsingle-linestrings */ publicfunction__construct(array$lyrics){ $this->lyrics=array_values($lyrics); $this->count=count($this->lyrics); }

    publicfunctionget_lyric(){ return$this->get_random_lyric(); }

    /** *Getarandomitemfromthelistoflyrics

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • Lyrics\Lyric_Collection_InterfacenamespaceHello_Dolly\Lyrics;

    /***InterfaceLyric_Collection_Interface**Implementorswillreturnasinglelineoflyrics*/interfaceLyric_Collection_Interface{ /** *@returnstringAsinglelineoflyrics */ publicfunctionget_lyric();}

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • Lyrics\Lyric_Collection_FactoryResponsibility

    TransformastringoflyricsintoaLyric_CollectionWhywoulditchange?

    Ifthereturnvalueshouldbeadifferentclass

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • tests/integration/Hello_Dolly/Lyrics/Lyric_Collection_Factory_Test.php

    namespaceHello_Dolly\Lyrics;useCodeception\TestCase\WPTestCase;

    classLyric_Collection_Factory_TestextendsWPTestCase{ publicfunctiontest_create_collection(){ $lyrics=[]; for($i=0;$icreate_collection($string);

    $this->assertInstanceOf('Hello_Dolly\\Lyrics\\Lyric_Collection',$collection); }}

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

  • Lyrics\Lyric_Collection_FactorynamespaceHello_Dolly\Lyrics;

    /***ClassLyric_Collection_Factory**CreatesaLyric_Collectioninstancefrom*astringoflyrics.*/classLyric_Collection_FactoryimplementsLyric_Collection_Factory_Interface{ /** *@paramstring$lyrics *@returnLyric_Collection */ publicfunctioncreate_collection($lyrics){ $lyrics=explode("\n",$lyrics); returnnewLyric_Collection($lyrics); }}

    JonathanBrinley #wcorlSlides:@jbrinley flightless.us/wcorl2016

    http://twitter.com/jbrinleyhttp://flightless.us/wcorl2016/

Recommended

View more >