SlideShare uma empresa Scribd logo
1 de 53
Baixar para ler offline
Proposal for xSpec
 BDD Framework
     for PHP
   Beyond PHPUnit and PHPSpec

     @yuya_takeyama
Recent Activities
• Making DSL with [] (#phpcon2011 LT)
  http://blog.yuyat.jp/archives/1355

• PHPUnit でよりよくテストを書くために
  http://blog.yuyat.jp/archives/1386

• phpenv で複数の PHP 環境を管理する
  http://blog.yuyat.jp/archives/1446

• Building Development Environment
  with php-build and phpenv
  http://blog.yuyat.jp/archives/1461

• 例えば, Singleton を避ける (New! #TddAdventJp)
  http://blog.yuyat.jp/archives/1500
xSpec?
xUnit?
xUnit (Unit Testing Frameworks)
•  SUnit (Smalltalk)

• JUnit (Java)

• Test::Unit (Ruby)

• PHPUnit (PHP)
xSpec?
   reprise
xSpec (Testing Frameworks for BDD)
  •  RSpec (Ruby)

  • Jasmine       (JavaScript)


  • specs     (Scala)


  • PHPSpec        (PHP)
BDD?
BDD (Behaviour Driven Development)
• Not test, specify!

•  It should ...

• Expressive

• Test as Documentation
RSpec example
describe Bowling do
  describe '#score' do
    context 'all gutter game' do
      before do
        @bowling = Bowling.new
        20.times { @bowling.hit(0) }
      end

      it 'should equal 0' do
        @bowling.score.should eq(0)
      end
    end
  end
end
RSpec example
describe Bowling do
  describe '#score' do
    context 'all gutter game' do
      before do
        @bowling = Bowling.new
        20.times { @bowling.hit(0) }
      end

      it 'should equal 0' do
        @bowling.score.should eq(0)
      end
    end
  end
end              Not Test, Specify
RSpec example
describe Bowling do
  describe '#score' do
    context 'all gutter game' do
      before do
        @bowling = Bowling.new
        20.times { @bowling.hit(0) }
      end

      it 'should equal 0' do
        @bowling.score.should eq(0)
      end
    end
  end
end                   It should ...
RSpec example
describe Bowling do
  describe '#score' do
    context 'all gutter game' do
      before do
        @bowling = Bowling.new
        20.times { @bowling.hit(0) }
      end

      it 'should equal 0' do
        @bowling.score.should eq(0)
      end
    end
  end
end                  Expressive
RSpec example
describe Bowling do
  describe '#score' do

           Test a
    context 'all gutter game' do


                  s
      before do



Docum
        @bowling = Bowling.new
        20.times { @bowling.hit(0) }



              entati
      end




                     o           n
      it 'should equal 0' do
        @bowling.score.should eq(0)
      end
    end
  end
end
I ❤
RSpec
PHPUnit example
class BowlingTest extends PHPUnit_Framwork_TestCase
{
    private $_bowling;

    public function setUp()
    {
        $this->_bowling = new Bowling;
    }

    public function testScore0ForAllGutterGame()
    {
        for ($i = 0; $i <= 20; $i++) {
            $this->_bowling->hit(0);
        }
        $this->assertEquals(0, $this->_bowling->score);
    }
}
PHPSpec example
class DescribeBowling extends PHPSpecContext
{
    private $_bowling;

    public function before()
    {
        $this->_bowling = $this->spec(new Bowling);
    }

    public function itShouldScore0ForAllGutterGame()
    {
        for ($i=1; $i<=20; $i++) {
            $this->_bowling->hit(0);
        }
        $this->_bowling->score->should->equal(0);
    }
}
PHPSpec example
class DescribeBowling extends PHPSpecContext
{
    private $_bowling;

    public function before()
    {
        $this->_bowling = $this->spec(new Bowling);
    }

    public function itShouldScore0ForAllGutterGame()
    {
        for ($i=1; $i<=20; $i++) {
            $this->_bowling->hit(0);
        }
        $this->_bowling->score->should->equal(0);
    }
}
                         Not Test, Specify
PHPSpec example
class DescribeBowling extends PHPSpecContext
{
    private $_bowling;

    public function before()
    {
        $this->_bowling = $this->spec(new Bowling);
    }

    public function itShouldScore0ForAllGutterGame()
    {
        for ($i=1; $i<=20; $i++) {
            $this->_bowling->hit(0);
        }
        $this->_bowling->score->should->equal(0);
    }
}
                              It should ...
PHPSpec example
class DescribeBowling extends PHPSpecContext
{
    private $_bowling;

    public function before()
    {
        $this->_bowling = $this->spec(new Bowling);
    }

    public function itShouldScore0ForAllGutterGame()
    {
        for ($i=1; $i<=20; $i++) {
            $this->_bowling->hit(0);
        }
        $this->_bowling->score->should->equal(0);
    }
}
                              Expressive
PHPSpec example
class DescribeBowling extends PHPSpecContext
{


                 Test a
    private $_bowling;




Docum                   s
    public function before()
    {
        $this->_bowling = $this->spec(new Bowling);




                     entati
    }

    public function itShouldScore0ForAllGutterGame()




                            o                n
    {
        for ($i=1; $i<=20; $i++) {
            $this->_bowling->hit(0);
        }
        $this->_bowling->score->should->equal(0);
    }
}
I ❤
PHPSpec
I ❤
PHPUnit
But...
Issue of PHPUnit/PHPSpec


•No nested context

•Specification with
 camelCase or
 lower_case_with_underscore
Issue of PHPUnit/PHPSpec


•   I want
             more
 No nested context

• exp
     ressiv
  Specification with

            eness!
 camelCase or
 lower_case_with_underscore
I
solved
Speciphy
   https://github.com/yuya-takeyama/Speciphy

•Nested context

• Specification with string

• PHPSpec matchers
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(
    describe('->score', array(
        context('all gutter game', array(
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {
                    $bowling->hit(0);
                }
                return $bowling;
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),
));
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(
    describe('->score', array(
        context('all gutter game', array(
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {
                    $bowling->hit(0);
                }
                return $bowling;
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),                   Not Test, Specify
));
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(
    describe('->score', array(
        context('all gutter game', array(
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {
                    $bowling->hit(0);
                }
                return $bowling;
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),                         It should...
));
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(
    describe('->score', array(
        context('all gutter game', array(
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {
                    $bowling->hit(0);
                }
                return $bowling;
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),                        Expressive
));
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(


                  Test a
    describe('->score', array(
        context('all gutter game', array(




Docum                    s
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {




                    entati
                    $bowling->hit(0);
                }
                return $bowling;




                                         on?
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),
));
Proposal #1
 Use function
in namespace,
  Not method
    in class
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(
    describe('->score', array(
        context('all gutter game', array(
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {
                    $bowling->hit(0);
                }
                return $bowling;
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),                  SpeciphyDSLdescribe
));
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(
    describe('->score', array(
        context('all gutter game', array(
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {
                    $bowling->hit(0);
                }
                return $bowling;
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),                   SpeciphyDSLcontext
));
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(
    describe('->score', array(
        context('all gutter game', array(
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {
                    $bowling->hit(0);
                }
                return $bowling;
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),                       SpeciphyDSLit
));
Proposal #2

  Use array
    to build
nested context.
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(
    describe('->score', array(
        context('all gutter game', array(
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {
                    $bowling->hit(0);
                }
                return $bowling;
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),                        Nested context
));
Array,
  A Strange
Data Structure
[
	 	 "foo",
	 	 "bar",
	 	 "hoge"	 =>	 "piyo"
]
array(3)	 {
	 	 [0]=>
	 	 string(3)	 "foo"
	 	 [1]=>
	 	 string(3)	 "bar"
	 	 ["hoge"]=>
	 	 string(4)	 "piyo"
}
Like
 keyword
arguments
Model Definition
public	 $id	 =	 [
	 	 'int',
	 	 'primary'	 =>	 true,	 
	 	 'serial'	 	 =>	 true
];
public	 $name	 =	 [
	 	 'string',
	 	 'required'	 =>	 true,
	 	 'unique'	 	 	 =>	 true
];
public	 $birthday	 =	 ['date'];
Paml
   https://github.com/yuya-takeyama/php-HTML_Paml

["div",
  ["ul",
    ["li", "Foo"]
    ["li", "Bar"]
    ["li", "Baz"]]]
HTML Generation
<div>
  <ul>
    <li>Foo</li>
    <li>Bar</li>
    <li>Baz</li>
  </ul>
</div>
LisPHP
          https://github.com/yuya-takeyama/LisPHP
['begin',
	 	 ['define',
	 	 	 	 'fib',
	 	 	 	 ['lambda',
	 	 	 	 	 	 ['x'],
	 	 	 	 	 	 ['if',
	 	 	 	 	 	 	 	 ['<',	 ':x',	 2],
	 	 	 	 	 	 	 	 ':x',
	 	 	 	 	 	 	 	 ['+',
	 	 	 	 	 	 	 	 	 	 ['fib',	 ['-',	 ':x',	 2]],
	 	 	 	 	 	 	 	 	 	 ['fib',	 ['-',	 ':x',	 1]]]]]],
	 	 ['print',	 'fib(10)	 =	 '],
	 	 ['println',	 ['fib',	 10]]]
	 	 =>	 fib(10)	 =	 55
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(
    describe('->score', array(
        context('all gutter game', array(
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {
                    $bowling->hit(0);
                }
                return $bowling;
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),                         $arr[ subject ]
));
Speciphy example
namespace SpeciphyDSL;

return describe('Bowling', array(
    describe('->score', array(
        context('all gutter game', array(
            'subject' => function () {
                $bowling = new Bowling;
                for ($i = 1; $i <= 20; $i++) {
                    $bowling->hit(0);
                }
                return $bowling;
            },

            it('should equal 0', function ($bowling) {
                $bowling->score->should->equal(0);
            }),
        )),
    )),                             $arr[0]
));
Conclusion
•Use function in namespace,
 Not method in class

•Use array to build nested
 structure

•Enjoy BDD with xSpec
Questions?
    or
 Claims?

Mais conteúdo relacionado

Mais procurados

R57shell
R57shellR57shell
R57shell
ady36
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
Bill Chang
 

Mais procurados (20)

Generated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsGenerated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 Generators
 
PHP for Python Developers
PHP for Python DevelopersPHP for Python Developers
PHP for Python Developers
 
R57shell
R57shellR57shell
R57shell
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of Transduction
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
 
Web lab programs
Web lab programsWeb lab programs
Web lab programs
 
PHP Tutorial (funtion)
PHP Tutorial (funtion)PHP Tutorial (funtion)
PHP Tutorial (funtion)
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model
 
Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm Old
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
PhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesPhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examples
 
Ae internals
Ae internalsAe internals
Ae internals
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介
 

Semelhante a Proposal for xSpep BDD Framework for PHP

New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmann
dpc
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To Moco
Naoya Ito
 

Semelhante a Proposal for xSpep BDD Framework for PHP (20)

CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
DBI
DBIDBI
DBI
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmann
 
PHPSpec BDD Framework
PHPSpec BDD FrameworkPHPSpec BDD Framework
PHPSpec BDD Framework
 
Parsing with Perl6 Grammars
Parsing with Perl6 GrammarsParsing with Perl6 Grammars
Parsing with Perl6 Grammars
 
Wp query
Wp queryWp query
Wp query
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
 
07-PHP.pptx
07-PHP.pptx07-PHP.pptx
07-PHP.pptx
 
07-PHP.pptx
07-PHP.pptx07-PHP.pptx
07-PHP.pptx
 
overview of php php basics datatypes arrays
overview of php php basics datatypes arraysoverview of php php basics datatypes arrays
overview of php php basics datatypes arrays
 
Power shell voor developers
Power shell voor developersPower shell voor developers
Power shell voor developers
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To Moco
 

Mais de Yuya Takeyama

Reactor Pattern and React
Reactor Pattern and ReactReactor Pattern and React
Reactor Pattern and React
Yuya Takeyama
 
PHP と MySQL で 1 カチャカチャカチャ...ッターン! MapReduce (@ニコニコ超会議)
PHP と MySQL で 1 カチャカチャカチャ...ッターン! MapReduce (@ニコニコ超会議)PHP と MySQL で 1 カチャカチャカチャ...ッターン! MapReduce (@ニコニコ超会議)
PHP と MySQL で 1 カチャカチャカチャ...ッターン! MapReduce (@ニコニコ超会議)
Yuya Takeyama
 
PHP と MySQL でカジュアルに MapReduce する
PHP と MySQL でカジュアルに MapReduce するPHP と MySQL でカジュアルに MapReduce する
PHP と MySQL でカジュアルに MapReduce する
Yuya Takeyama
 
PHPUnit でテスト駆動開発を始めよう
PHPUnit でテスト駆動開発を始めようPHPUnit でテスト駆動開発を始めよう
PHPUnit でテスト駆動開発を始めよう
Yuya Takeyama
 
MySQL 入門的なはなし
MySQL 入門的なはなしMySQL 入門的なはなし
MySQL 入門的なはなし
Yuya Takeyama
 
HashTable と HashDos
HashTable と HashDosHashTable と HashDos
HashTable と HashDos
Yuya Takeyama
 
Building Development Environment with php-build and phpenv
Building Development Environment with php-build and phpenvBuilding Development Environment with php-build and phpenv
Building Development Environment with php-build and phpenv
Yuya Takeyama
 
LIMIT 付きで UPDATE を行うと何故怒られるか
LIMIT 付きで UPDATE を行うと何故怒られるかLIMIT 付きで UPDATE を行うと何故怒られるか
LIMIT 付きで UPDATE を行うと何故怒られるか
Yuya Takeyama
 

Mais de Yuya Takeyama (16)

5分でわかる? 関数型 PHP の潮流
5分でわかる? 関数型 PHP の潮流5分でわかる? 関数型 PHP の潮流
5分でわかる? 関数型 PHP の潮流
 
Good Parts of PHP and the UNIX Philosophy
Good Parts of PHP and the UNIX PhilosophyGood Parts of PHP and the UNIX Philosophy
Good Parts of PHP and the UNIX Philosophy
 
Reactor Pattern and React
Reactor Pattern and ReactReactor Pattern and React
Reactor Pattern and React
 
PHP と MySQL で 1 カチャカチャカチャ...ッターン! MapReduce (@ニコニコ超会議)
PHP と MySQL で 1 カチャカチャカチャ...ッターン! MapReduce (@ニコニコ超会議)PHP と MySQL で 1 カチャカチャカチャ...ッターン! MapReduce (@ニコニコ超会議)
PHP と MySQL で 1 カチャカチャカチャ...ッターン! MapReduce (@ニコニコ超会議)
 
PHP と MySQL でカジュアルに MapReduce する (Short Version)
PHP と MySQL でカジュアルに MapReduce する (Short Version)PHP と MySQL でカジュアルに MapReduce する (Short Version)
PHP と MySQL でカジュアルに MapReduce する (Short Version)
 
PHP と MySQL でカジュアルに MapReduce する
PHP と MySQL でカジュアルに MapReduce するPHP と MySQL でカジュアルに MapReduce する
PHP と MySQL でカジュアルに MapReduce する
 
PHPUnit でテスト駆動開発を始めよう
PHPUnit でテスト駆動開発を始めようPHPUnit でテスト駆動開発を始めよう
PHPUnit でテスト駆動開発を始めよう
 
MySQL 入門的なはなし
MySQL 入門的なはなしMySQL 入門的なはなし
MySQL 入門的なはなし
 
HashTable と HashDos
HashTable と HashDosHashTable と HashDos
HashTable と HashDos
 
Building Development Environment with php-build and phpenv
Building Development Environment with php-build and phpenvBuilding Development Environment with php-build and phpenv
Building Development Environment with php-build and phpenv
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
 
Making DSL with []
Making DSL with []Making DSL with []
Making DSL with []
 
LIMIT 付きで UPDATE を行うと何故怒られるか
LIMIT 付きで UPDATE を行うと何故怒られるかLIMIT 付きで UPDATE を行うと何故怒られるか
LIMIT 付きで UPDATE を行うと何故怒られるか
 
GOOS #1
GOOS #1GOOS #1
GOOS #1
 
Ruby 同好会宣言
Ruby 同好会宣言Ruby 同好会宣言
Ruby 同好会宣言
 
第一回 社内勉強会 PHP Application Security Checklist に学ぶ PHP セキュリティ (Excerpt)
第一回 社内勉強会 PHP Application Security Checklist に学ぶ PHP セキュリティ (Excerpt)第一回 社内勉強会 PHP Application Security Checklist に学ぶ PHP セキュリティ (Excerpt)
第一回 社内勉強会 PHP Application Security Checklist に学ぶ PHP セキュリティ (Excerpt)
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Proposal for xSpep BDD Framework for PHP

  • 1. Proposal for xSpec BDD Framework for PHP Beyond PHPUnit and PHPSpec @yuya_takeyama
  • 2. Recent Activities • Making DSL with [] (#phpcon2011 LT) http://blog.yuyat.jp/archives/1355 • PHPUnit でよりよくテストを書くために http://blog.yuyat.jp/archives/1386 • phpenv で複数の PHP 環境を管理する http://blog.yuyat.jp/archives/1446 • Building Development Environment with php-build and phpenv http://blog.yuyat.jp/archives/1461 • 例えば, Singleton を避ける (New! #TddAdventJp) http://blog.yuyat.jp/archives/1500
  • 5. xUnit (Unit Testing Frameworks) • SUnit (Smalltalk) • JUnit (Java) • Test::Unit (Ruby) • PHPUnit (PHP)
  • 6.
  • 7. xSpec? reprise
  • 8. xSpec (Testing Frameworks for BDD) • RSpec (Ruby) • Jasmine (JavaScript) • specs (Scala) • PHPSpec (PHP)
  • 10. BDD (Behaviour Driven Development) • Not test, specify! • It should ... • Expressive • Test as Documentation
  • 11. RSpec example describe Bowling do   describe '#score' do     context 'all gutter game' do       before do         @bowling = Bowling.new         20.times { @bowling.hit(0) }       end       it 'should equal 0' do         @bowling.score.should eq(0)       end     end   end end
  • 12. RSpec example describe Bowling do   describe '#score' do     context 'all gutter game' do       before do         @bowling = Bowling.new         20.times { @bowling.hit(0) }       end       it 'should equal 0' do         @bowling.score.should eq(0)       end     end   end end Not Test, Specify
  • 13. RSpec example describe Bowling do   describe '#score' do     context 'all gutter game' do       before do         @bowling = Bowling.new         20.times { @bowling.hit(0) }       end       it 'should equal 0' do         @bowling.score.should eq(0)       end     end   end end It should ...
  • 14. RSpec example describe Bowling do   describe '#score' do     context 'all gutter game' do       before do         @bowling = Bowling.new         20.times { @bowling.hit(0) }       end       it 'should equal 0' do         @bowling.score.should eq(0)       end     end   end end Expressive
  • 15. RSpec example describe Bowling do   describe '#score' do Test a     context 'all gutter game' do s       before do Docum         @bowling = Bowling.new         20.times { @bowling.hit(0) } entati       end o n       it 'should equal 0' do         @bowling.score.should eq(0)       end     end   end end
  • 17.
  • 18. PHPUnit example class BowlingTest extends PHPUnit_Framwork_TestCase {     private $_bowling;     public function setUp()     {         $this->_bowling = new Bowling;     }     public function testScore0ForAllGutterGame()     {         for ($i = 0; $i <= 20; $i++) {             $this->_bowling->hit(0);         }         $this->assertEquals(0, $this->_bowling->score);     } }
  • 19. PHPSpec example class DescribeBowling extends PHPSpecContext {     private $_bowling;     public function before()     {         $this->_bowling = $this->spec(new Bowling);     }     public function itShouldScore0ForAllGutterGame()     {         for ($i=1; $i<=20; $i++) {             $this->_bowling->hit(0);         }         $this->_bowling->score->should->equal(0);     } }
  • 20. PHPSpec example class DescribeBowling extends PHPSpecContext {     private $_bowling;     public function before()     {         $this->_bowling = $this->spec(new Bowling);     }     public function itShouldScore0ForAllGutterGame()     {         for ($i=1; $i<=20; $i++) {             $this->_bowling->hit(0);         }         $this->_bowling->score->should->equal(0);     } } Not Test, Specify
  • 21. PHPSpec example class DescribeBowling extends PHPSpecContext {     private $_bowling;     public function before()     {         $this->_bowling = $this->spec(new Bowling);     }     public function itShouldScore0ForAllGutterGame()     {         for ($i=1; $i<=20; $i++) {             $this->_bowling->hit(0);         }         $this->_bowling->score->should->equal(0);     } } It should ...
  • 22. PHPSpec example class DescribeBowling extends PHPSpecContext {     private $_bowling;     public function before()     {         $this->_bowling = $this->spec(new Bowling);     }     public function itShouldScore0ForAllGutterGame()     {         for ($i=1; $i<=20; $i++) {             $this->_bowling->hit(0);         }         $this->_bowling->score->should->equal(0);     } } Expressive
  • 23. PHPSpec example class DescribeBowling extends PHPSpecContext { Test a     private $_bowling; Docum s     public function before()     {         $this->_bowling = $this->spec(new Bowling); entati     }     public function itShouldScore0ForAllGutterGame() o n     {         for ($i=1; $i<=20; $i++) {             $this->_bowling->hit(0);         }         $this->_bowling->score->should->equal(0);     } }
  • 27. Issue of PHPUnit/PHPSpec •No nested context •Specification with camelCase or lower_case_with_underscore
  • 28. Issue of PHPUnit/PHPSpec • I want more No nested context • exp ressiv Specification with eness! camelCase or lower_case_with_underscore
  • 30. Speciphy https://github.com/yuya-takeyama/Speciphy •Nested context • Specification with string • PHPSpec matchers
  • 31. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array(     describe('->score', array(         context('all gutter game', array(             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) {                     $bowling->hit(0);                 }                 return $bowling;             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), ));
  • 32. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array(     describe('->score', array(         context('all gutter game', array(             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) {                     $bowling->hit(0);                 }                 return $bowling;             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), Not Test, Specify ));
  • 33. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array(     describe('->score', array(         context('all gutter game', array(             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) {                     $bowling->hit(0);                 }                 return $bowling;             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), It should... ));
  • 34. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array(     describe('->score', array(         context('all gutter game', array(             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) {                     $bowling->hit(0);                 }                 return $bowling;             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), Expressive ));
  • 35. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array( Test a     describe('->score', array(         context('all gutter game', array( Docum s             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) { entati                     $bowling->hit(0);                 }                 return $bowling; on?             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), ));
  • 36. Proposal #1 Use function in namespace, Not method in class
  • 37. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array(     describe('->score', array(         context('all gutter game', array(             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) {                     $bowling->hit(0);                 }                 return $bowling;             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), SpeciphyDSLdescribe ));
  • 38. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array(     describe('->score', array(         context('all gutter game', array(             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) {                     $bowling->hit(0);                 }                 return $bowling;             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), SpeciphyDSLcontext ));
  • 39. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array(     describe('->score', array(         context('all gutter game', array(             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) {                     $bowling->hit(0);                 }                 return $bowling;             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), SpeciphyDSLit ));
  • 40. Proposal #2 Use array to build nested context.
  • 41. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array(     describe('->score', array(         context('all gutter game', array(             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) {                     $bowling->hit(0);                 }                 return $bowling;             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), Nested context ));
  • 42. Array, A Strange Data Structure
  • 43. [ "foo", "bar", "hoge" => "piyo" ]
  • 44. array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" ["hoge"]=> string(4) "piyo" }
  • 46. Model Definition public $id = [ 'int', 'primary' => true, 'serial' => true ]; public $name = [ 'string', 'required' => true, 'unique' => true ]; public $birthday = ['date'];
  • 47. Paml https://github.com/yuya-takeyama/php-HTML_Paml ["div",   ["ul",     ["li", "Foo"]     ["li", "Bar"]     ["li", "Baz"]]]
  • 49. LisPHP https://github.com/yuya-takeyama/LisPHP ['begin', ['define', 'fib', ['lambda', ['x'], ['if', ['<', ':x', 2], ':x', ['+', ['fib', ['-', ':x', 2]], ['fib', ['-', ':x', 1]]]]]], ['print', 'fib(10) = '], ['println', ['fib', 10]]] => fib(10) = 55
  • 50. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array(     describe('->score', array(         context('all gutter game', array(             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) {                     $bowling->hit(0);                 }                 return $bowling;             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), $arr[ subject ] ));
  • 51. Speciphy example namespace SpeciphyDSL; return describe('Bowling', array(     describe('->score', array(         context('all gutter game', array(             'subject' => function () {                 $bowling = new Bowling;                 for ($i = 1; $i <= 20; $i++) {                     $bowling->hit(0);                 }                 return $bowling;             },             it('should equal 0', function ($bowling) {                 $bowling->score->should->equal(0);             }),         )),     )), $arr[0] ));
  • 52. Conclusion •Use function in namespace, Not method in class •Use array to build nested structure •Enjoy BDD with xSpec
  • 53. Questions? or Claims?