SlideShare uma empresa Scribd logo
1 de 77
Baixar para ler offline
['begin',
	 	 ['define',
	 	 	 	 'fib',
	 	 	 	 ['lambda',
	 	 	 	 	 	 ['x'],
	 	 	 	 	 	 ['if',
	 	 	 	 	 	 	 	 ['<',	 ':x',	 2],
	 	 	 	 	 	 	 	 ':x',
	 	 	 	 	 	 	 	 ['+',
	 	 	 	 	 	 	 	 	 	 ['fib',	 ['-',	 ':x',	 2]],
	 	 	 	 	 	 	 	 	 	 ['fib',	 ['-',	 ':x',	 1]]]]]],
	 	 ['print',	 'fib(10)	 =	 '],
	 	 ['println',	 ['fib',	 10]]]
	 	 =>	 fib(10)	 =	 55
class CalculatorTest
  extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $this->calc = new Calculator;
    }

    public function test_add_           ()
    {
        $result = $this->calc->add(1, 2);
        $this->assertSame(3, $result);
    }
}
class CalculatorTest
  extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $this->calc = new Calculator;
    }

    public function test_add_           ()
    {
        $result = $this->calc->add(1, 2);
        $this->assertSame(3, $result);
    }
}
class CalculatorTest
  extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $this->calc = new Calculator;
    }

    public function test_add_           ()
    {
        $result = $this->calc->add(1, 2);
        $this->assertSame(3, $result);
    }
}
class CalculatorTest
  extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $this->calc = new Calculator;
    }

    public function test_add_           ()
    {
        $result = $this->calc->add(1, 2);
        $this->assertSame(3, $result);
    }
}
public function test_isValid_               true()
{
    $user = new User;
    $user->setName('Yuya');
    $user->setUrl('http://yuyat.jp/');
    $user->setAge(24);
    $this->assertTrue($user->isValid());
}

public function test_isValid_               false()
{
    $user = new User;
    $user->setName('Yuya');
    $user->setUrl('http://yuyat.jp/');
    $user->setAge(NULL);
    $this->assertFalse($user->isValid());
}
public function test_isValid_               true()
{
    $user = new User;
    $user->setName('Yuya');
    $user->setUrl('http://yuyat.jp/');
    $user->setAge(24);
    $this->assertTrue($user->isValid());
}

public function test_isValid_               false()
{
    $user = new User;
    $user->setName('Yuya');
    $user->setUrl('http://yuyat.jp/');
    $user->setAge(NULL);
    $this->assertFalse($user->isValid());
}
public function test_isValid_               true()
{
    $user = $this->createValidUser();
    $this->assertTrue($user->isValid());
}

public function test_isValid_               false()
{
    $user = $this->createValidUser();
    $user->setAge(NULL);
    $this->assertFalse($user->isValid());
}
public function test_isValid_               true()
{
    $user = $this->createValidUser();
    $this->assertTrue($user->isValid());
}

public function test_isValid_               false()
{
    $user = $this->createValidUser();
    $user->setAge(NULL);
    $this->assertFalse($user->isValid());
}
public function test_isValid_               true()
{
    $user = $this->createValidUser();
    $this->assertTrue($user->isValid());
}

public function test_isValid_               false()
{
    $user = $this->createValidUser();
    $user->setAge(NULL);
    $this->assertFalse($user->isValid());
}
public function test_isValid_               false()
{
    $user = $this->createValidUser();
    $user->setAge(NULL);
    $this->assertFalse($user->isValid());

    $user = $this->createValidUser();
    $user->setName(NULL);
    $this->assertFalse($user->isValid());
}
public function test_isValid_               false()
{
    $user = $this->createValidUser();
    $user->setAge(NULL);
    $this->assertFalse($user->isValid());

    $user = $this->createValidUser();
    $user->setName(NULL);
    $this->assertFalse($user->isValid());
}
public function test_isValid_               false()
{
    $user = $this->createValidUser();
    $user->setAge(NULL);
    $this->assertFalse($user->isValid());

    $user = $this->createValidUser();
    $user->setName(NULL);
    $this->assertFalse($user->isValid());
}
public function test_isValid_           Null   false()
{
    $user = $this->createValidUser();
    $user->setAge(NULL);
    $this->assertFalse($user->isValid());
}

public function test_isValid_           Null   false()
{
    $user = $this->createValidUser();
    $user->setName(NULL);
    $this->assertFalse($user->isValid());
}
public function test_isValid_           Null   false()
{
    $user = $this->createValidUser();
    $user->setAge(NULL);
    $this->assertFalse($user->isValid());
}

public function test_isValid_           Null   false()
{
    $user = $this->createValidUser();
    $user->setName(NULL);
    $this->assertFalse($user->isValid());
}
class Request
{
    public function isSsl()
    {
        return $_SERVER['HTTPS'] === 'on';
    }
}
class Request
{
    public function isSsl()
    {
        return $_SERVER['HTTPS'] === 'on';
    }
}
public function test_isSsl_HTTPS      true()
{
    $_SERVER['HTTPS'] = 'on';
    $this->assertTrue($this->request->isSsl());
}

public function test_isSsl_HTTPS        false()
{
    unset($_SERVER['HTTPS']);
    $this->assertFalse($this->request->isSsl());
}
public function test_isSsl_HTTPS      true()
{
    $_SERVER['HTTPS'] = 'on';
    $this->assertTrue($this->request->isSsl());
}

public function test_isSsl_HTTPS        false()
{
    unset($_SERVER['HTTPS']);
    $this->assertFalse($this->request->isSsl());
}
public function test_isSsl_HTTPS      true()
{
    $_SERVER['HTTPS'] = 'on';
    $this->assertTrue($this->request->isSsl());
}

public function test_isSsl_HTTPS        false()
{
    unset($_SERVER['HTTPS']);
    $this->assertFalse($this->request->isSsl());
}
public function test_isSsl_HTTPS      true()
{
    $_SERVER['HTTPS'] = 'on';
    $this->assertTrue($this->request->isSsl());
}

public function test_isSsl_HTTPS        false()
{
    unset($_SERVER['HTTPS']);
    $this->assertFalse($this->request->isSsl());
}
class Request
{
     public function __construct($server)
     {
         $this->_server = $server;
     }

     public function isSsl()
     {
         return $this->_server === 'on';
     }
}
class Request
{
     public function __construct($server)
     {
         $this->_server = $server;
     }

     public function isSsl()
     {
         return $this->_server === 'on';
     }
}
public function test_isSsl_HTTPS      true()
{
    $request = new Request(array('HTTPS' => 'on'));
    $this->assertTrue($request->isSsl());
}

public function test_isSsl_HTTPS        false()
{
    $request = new Request(array());
    $this->assertFalse($request->isSsl());
}
public function test_isSsl_HTTPS      true()
{
    $request = new Request(array('HTTPS' => 'on'));
    $this->assertTrue($request->isSsl());
}

public function test_isSsl_HTTPS        false()
{
    $request = new Request(array());
    $this->assertFalse($request->isSsl());
}
class User
{
    protected $_name;
    protected $_birthday;

    public function setName($name) { /*~*/ }
    public function getName() { /*~*/ }
    public function getAge() { /*~*/ }

    public static function findByName($name) { /*~*/ }
    public function save() { /*~*/ }
}
$user = User::findByName('Bob');

$user->setName('Alice');

$user->save();
class User
{
    protected $_name;
    protected $_birthday;

    public function setName($name) { /*~*/ }
    public function getName() { /*~*/ }
    public function getAge() { /*~*/ }
}

class UserMapper
{
    public function findByName($name) { /*~*/ }
    public function save(User $user) { /*~*/ }
}
$mapper = new UserMapper;

$user = $mapper->findByName('Bob');

$user->setName('Alice');

$mapper->save($user);
class User
{
    protected $_name;
    protected $_birthday;

    public function setName($name) { /*~*/ }
    public function getName() { /*~*/ }
    public function getAge() { /*~*/ }

    public static function findByName($name) { /*~*/ }
    public function save() { /*~*/ }
}
class User
{
    protected $_name;
    protected $_birthday;

    public function setName($name) { /*~*/ }
    public function getName() { /*~*/ }
    public function getAge() { /*~*/ }

    public static function findByName($name) { /*~*/ }
    public function save() { /*~*/ }
}
class User
{
    protected $_name;
    protected $_birthday;

    public function setName($name) { /*~*/ }
    public function getName() { /*~*/ }
    public function getAge() { /*~*/ }

    public static function findByName($name) { /*~*/ }
    public function save() { /*~*/ }
}
class User
{
    protected $_name;
    protected $_birthday;

    public function setName($name) { /*~*/ }
    public function getName() { /*~*/ }
    public function getAge() { /*~*/ }

    public static function findByName($name) { /*~*/ }
    public function save() { /*~*/ }
}
class User
{
    protected $_name;
    protected $_birthday;

    public function setName($name) { /*~*/ }
    public function getName() { /*~*/ }
    public function getAge() { /*~*/ }
}

class UserMapper
{
    public function findByName($name) { /*~*/ }
    public function save(User $user) { /*~*/ }
}
class User
{
    protected $_name;
    protected $_birthday;

    public function setName($name) { /*~*/ }
    public function getName() { /*~*/ }
    public function getAge() { /*~*/ }
}

class UserMapper
{
    public function findByName($name) { /*~*/ }
    public function save(User $user) { /*~*/ }
}
class User
{
    protected $_name;
    protected $_birthday;

    public function setName($name) { /*~*/ }
    public function getName() { /*~*/ }
    public function getAge() { /*~*/ }
}

class UserMapper
{
    public function findByName($name) { /*~*/ }
    public function save(User $user) { /*~*/ }
}
class User
{
    protected $_name;
    protected $_birthday;

    public function setName($name) { /*~*/ }
    public function getName() { /*~*/ }
    public function getAge() { /*~*/ }
}

class UserMapper
{
    public function findByName($name) { /*~*/ }
    public function save(User $user) { /*~*/ }
}
class Config
{
    protected static $_instance;

    private function __construct() {}

    public static function getInstance()
    {
        if (empty(self::$_instance)) {
            self::$_instance = new self;
        }
        return self::$_instance;
    }
}
public function __clone()
{
    throw new BadMethodCallException(
        'Clone is not allowed.'
    );
}
public function test_get_
 ()
{
    $config = Config::getInstance();
    $config->set('message', 'Hello');
    $this->assertSame(
        'Hello',
        $config->get('message')
    );
}
public function test_get_
   Null()
{
    $config = Config::getInstance();
    $this->assertNull(
        $config->get('message')
    );
}
public function test_get_
   Null()
{
    $config = Config::getInstance();
    $this->assertNull(
        $config->get('message')
    );
}
public function test_get_
   Null()
{
    $config = Config::getInstance();
    $config->init();
    $this->assertNull(
        $config->get('message')
    );
}
public function test_get_
   Null()
{
    $config = Config::getInstance();
    $config->init();
    $this->assertNull(
        $config->get('message')
    );
}
public function test_get_
   Null()
{
    $config = Config::getInstance();
    $config->init();
    $this->assertNull(
        $config->get('message')
    );
}
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために

Mais conteúdo relacionado

Mais procurados

jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
Remy Sharp
 
R57shell
R57shellR57shell
R57shell
ady36
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
Fabien Potencier
 

Mais procurados (20)

The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
Agile database access with CakePHP 3
Agile database access with CakePHP 3Agile database access with CakePHP 3
Agile database access with CakePHP 3
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object Calisthenics
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
Pim Elshoff "Final Class Aggregate"
Pim Elshoff "Final Class Aggregate"Pim Elshoff "Final Class Aggregate"
Pim Elshoff "Final Class Aggregate"
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language Trivia
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
R57shell
R57shellR57shell
R57shell
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHP
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 

Destaque

とある事業の脱レガシー
とある事業の脱レガシーとある事業の脱レガシー
とある事業の脱レガシー
Hisateru Tanaka
 
UnitTestのためのクラス設計
UnitTestのためのクラス設計UnitTestのためのクラス設計
UnitTestのためのクラス設計
Takeshi Ishida
 
PHPUnit でテスト駆動開発を始めよう
PHPUnit でテスト駆動開発を始めようPHPUnit でテスト駆動開発を始めよう
PHPUnit でテスト駆動開発を始めよう
Yuya Takeyama
 
Awsで実現するseleniumテスト高速術
Awsで実現するseleniumテスト高速術Awsで実現するseleniumテスト高速術
Awsで実現するseleniumテスト高速術
finoue
 
Jmeter Performance Testing
Jmeter Performance TestingJmeter Performance Testing
Jmeter Performance Testing
Atul Pant
 
AspectMock 最強のモッキングフレームワーク
AspectMock 最強のモッキングフレームワークAspectMock 最強のモッキングフレームワーク
AspectMock 最強のモッキングフレームワーク
kenjis
 

Destaque (20)

とある事業の脱レガシー
とある事業の脱レガシーとある事業の脱レガシー
とある事業の脱レガシー
 
5分でわかる? 関数型 PHP の潮流
5分でわかる? 関数型 PHP の潮流5分でわかる? 関数型 PHP の潮流
5分でわかる? 関数型 PHP の潮流
 
Ioc & in direction
Ioc & in directionIoc & in direction
Ioc & in direction
 
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
 
UnitTestのためのクラス設計
UnitTestのためのクラス設計UnitTestのためのクラス設計
UnitTestのためのクラス設計
 
2007 5 30 肖镜辉 统计语言模型简介
2007 5 30 肖镜辉 统计语言模型简介2007 5 30 肖镜辉 统计语言模型简介
2007 5 30 肖镜辉 统计语言模型简介
 
IoC with PHP
IoC with PHPIoC with PHP
IoC with PHP
 
PHP Unit-Testing With Doubles
PHP Unit-Testing With DoublesPHP Unit-Testing With Doubles
PHP Unit-Testing With Doubles
 
Stub you!
Stub you!Stub you!
Stub you!
 
デブサミ関西2012 B-3
デブサミ関西2012 B-3デブサミ関西2012 B-3
デブサミ関西2012 B-3
 
PHPUnit でテスト駆動開発を始めよう
PHPUnit でテスト駆動開発を始めようPHPUnit でテスト駆動開発を始めよう
PHPUnit でテスト駆動開発を始めよう
 
Awsで実現するseleniumテスト高速術
Awsで実現するseleniumテスト高速術Awsで実現するseleniumテスト高速術
Awsで実現するseleniumテスト高速術
 
PHPUnit 入門介紹
PHPUnit 入門介紹PHPUnit 入門介紹
PHPUnit 入門介紹
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
テスト駆動開発へようこそ
テスト駆動開発へようこそテスト駆動開発へようこそ
テスト駆動開発へようこそ
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
Jmeter Performance Testing
Jmeter Performance TestingJmeter Performance Testing
Jmeter Performance Testing
 
AspectMock 最強のモッキングフレームワーク
AspectMock 最強のモッキングフレームワークAspectMock 最強のモッキングフレームワーク
AspectMock 最強のモッキングフレームワーク
 
Di – ioc (ninject)
Di – ioc (ninject)Di – ioc (ninject)
Di – ioc (ninject)
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
 

Semelhante a PHPUnit でよりよくテストを書くために

Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOP
Wildan Maulana
 

Semelhante a PHPUnit でよりよくテストを書くために (20)

Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Oops in php
Oops in phpOops in php
Oops in php
 
Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Laravel
LaravelLaravel
Laravel
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
 
BEAR DI
BEAR DIBEAR DI
BEAR DI
 
Bacbkone js
Bacbkone jsBacbkone js
Bacbkone js
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
 
Presentation1
Presentation1Presentation1
Presentation1
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...
“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...
“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Workshop unittesting
Workshop unittestingWorkshop unittesting
Workshop unittesting
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOP
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 

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
 
MySQL 入門的なはなし
MySQL 入門的なはなしMySQL 入門的なはなし
MySQL 入門的なはなし
Yuya Takeyama
 
HashTable と HashDos
HashTable と HashDosHashTable と HashDos
HashTable と HashDos
Yuya Takeyama
 
Proposal for xSpep BDD Framework for PHP
Proposal for xSpep BDD Framework for PHPProposal for xSpep BDD Framework for PHP
Proposal for xSpep BDD Framework for PHP
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 (13)

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 する
 
MySQL 入門的なはなし
MySQL 入門的なはなしMySQL 入門的なはなし
MySQL 入門的なはなし
 
HashTable と HashDos
HashTable と HashDosHashTable と HashDos
HashTable と HashDos
 
Proposal for xSpep BDD Framework for PHP
Proposal for xSpep BDD Framework for PHPProposal for xSpep BDD Framework for PHP
Proposal for xSpep BDD Framework for PHP
 
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
 
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

Último (20)

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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

PHPUnit でよりよくテストを書くために

  • 1.
  • 2.
  • 3.
  • 4. ['begin', ['define', 'fib', ['lambda', ['x'], ['if', ['<', ':x', 2], ':x', ['+', ['fib', ['-', ':x', 2]], ['fib', ['-', ':x', 1]]]]]], ['print', 'fib(10) = '], ['println', ['fib', 10]]] => fib(10) = 55
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. class CalculatorTest extends PHPUnit_Framework_TestCase {     public function setUp()     {         $this->calc = new Calculator;     }     public function test_add_ ()     {         $result = $this->calc->add(1, 2);         $this->assertSame(3, $result);     } }
  • 11. class CalculatorTest extends PHPUnit_Framework_TestCase {     public function setUp()     {         $this->calc = new Calculator;     }     public function test_add_ ()     {         $result = $this->calc->add(1, 2);         $this->assertSame(3, $result);     } }
  • 12. class CalculatorTest extends PHPUnit_Framework_TestCase {     public function setUp()     {         $this->calc = new Calculator;     }     public function test_add_ ()     {         $result = $this->calc->add(1, 2);         $this->assertSame(3, $result);     } }
  • 13. class CalculatorTest extends PHPUnit_Framework_TestCase {     public function setUp()     {         $this->calc = new Calculator;     }     public function test_add_ ()     {         $result = $this->calc->add(1, 2);         $this->assertSame(3, $result);     } }
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. public function test_isValid_ true() {     $user = new User;     $user->setName('Yuya');     $user->setUrl('http://yuyat.jp/');     $user->setAge(24);     $this->assertTrue($user->isValid()); } public function test_isValid_ false() {     $user = new User;     $user->setName('Yuya');     $user->setUrl('http://yuyat.jp/');     $user->setAge(NULL);     $this->assertFalse($user->isValid()); }
  • 26. public function test_isValid_ true() {     $user = new User;     $user->setName('Yuya');     $user->setUrl('http://yuyat.jp/');     $user->setAge(24);     $this->assertTrue($user->isValid()); } public function test_isValid_ false() {     $user = new User;     $user->setName('Yuya');     $user->setUrl('http://yuyat.jp/');     $user->setAge(NULL);     $this->assertFalse($user->isValid()); }
  • 27. public function test_isValid_ true() {     $user = $this->createValidUser();     $this->assertTrue($user->isValid()); } public function test_isValid_ false() {     $user = $this->createValidUser();     $user->setAge(NULL);     $this->assertFalse($user->isValid()); }
  • 28. public function test_isValid_ true() {     $user = $this->createValidUser();     $this->assertTrue($user->isValid()); } public function test_isValid_ false() {     $user = $this->createValidUser();     $user->setAge(NULL);     $this->assertFalse($user->isValid()); }
  • 29. public function test_isValid_ true() {     $user = $this->createValidUser();     $this->assertTrue($user->isValid()); } public function test_isValid_ false() {     $user = $this->createValidUser();     $user->setAge(NULL);     $this->assertFalse($user->isValid()); }
  • 30.
  • 31. public function test_isValid_ false() {     $user = $this->createValidUser();     $user->setAge(NULL);     $this->assertFalse($user->isValid());     $user = $this->createValidUser();     $user->setName(NULL);     $this->assertFalse($user->isValid()); }
  • 32. public function test_isValid_ false() {     $user = $this->createValidUser();     $user->setAge(NULL);     $this->assertFalse($user->isValid());     $user = $this->createValidUser();     $user->setName(NULL);     $this->assertFalse($user->isValid()); }
  • 33. public function test_isValid_ false() {     $user = $this->createValidUser();     $user->setAge(NULL);     $this->assertFalse($user->isValid());     $user = $this->createValidUser();     $user->setName(NULL);     $this->assertFalse($user->isValid()); }
  • 34. public function test_isValid_ Null false() {     $user = $this->createValidUser();     $user->setAge(NULL);     $this->assertFalse($user->isValid()); } public function test_isValid_ Null false() {     $user = $this->createValidUser();     $user->setName(NULL);     $this->assertFalse($user->isValid()); }
  • 35. public function test_isValid_ Null false() {     $user = $this->createValidUser();     $user->setAge(NULL);     $this->assertFalse($user->isValid()); } public function test_isValid_ Null false() {     $user = $this->createValidUser();     $user->setName(NULL);     $this->assertFalse($user->isValid()); }
  • 36.
  • 37.
  • 38.
  • 39. class Request {     public function isSsl()     {         return $_SERVER['HTTPS'] === 'on';     } }
  • 40. class Request {     public function isSsl()     {         return $_SERVER['HTTPS'] === 'on';     } }
  • 41. public function test_isSsl_HTTPS true() {     $_SERVER['HTTPS'] = 'on';     $this->assertTrue($this->request->isSsl()); } public function test_isSsl_HTTPS false() {     unset($_SERVER['HTTPS']);     $this->assertFalse($this->request->isSsl()); }
  • 42. public function test_isSsl_HTTPS true() {     $_SERVER['HTTPS'] = 'on';     $this->assertTrue($this->request->isSsl()); } public function test_isSsl_HTTPS false() {     unset($_SERVER['HTTPS']);     $this->assertFalse($this->request->isSsl()); }
  • 43. public function test_isSsl_HTTPS true() {     $_SERVER['HTTPS'] = 'on';     $this->assertTrue($this->request->isSsl()); } public function test_isSsl_HTTPS false() {     unset($_SERVER['HTTPS']);     $this->assertFalse($this->request->isSsl()); }
  • 44. public function test_isSsl_HTTPS true() {     $_SERVER['HTTPS'] = 'on';     $this->assertTrue($this->request->isSsl()); } public function test_isSsl_HTTPS false() {     unset($_SERVER['HTTPS']);     $this->assertFalse($this->request->isSsl()); }
  • 45. class Request { public function __construct($server) {      $this->_server = $server; } public function isSsl() {      return $this->_server === 'on'; } }
  • 46. class Request { public function __construct($server) {      $this->_server = $server; } public function isSsl() {      return $this->_server === 'on'; } }
  • 47. public function test_isSsl_HTTPS true() {     $request = new Request(array('HTTPS' => 'on'));     $this->assertTrue($request->isSsl()); } public function test_isSsl_HTTPS false() {     $request = new Request(array());     $this->assertFalse($request->isSsl()); }
  • 48. public function test_isSsl_HTTPS true() {     $request = new Request(array('HTTPS' => 'on'));     $this->assertTrue($request->isSsl()); } public function test_isSsl_HTTPS false() {     $request = new Request(array());     $this->assertFalse($request->isSsl()); }
  • 49.
  • 50.
  • 51. class User {     protected $_name;     protected $_birthday;     public function setName($name) { /*~*/ }     public function getName() { /*~*/ }     public function getAge() { /*~*/ }     public static function findByName($name) { /*~*/ }     public function save() { /*~*/ } }
  • 53. class User {     protected $_name;     protected $_birthday;     public function setName($name) { /*~*/ }     public function getName() { /*~*/ }     public function getAge() { /*~*/ } } class UserMapper {     public function findByName($name) { /*~*/ }     public function save(User $user) { /*~*/ } }
  • 54. $mapper = new UserMapper; $user = $mapper->findByName('Bob'); $user->setName('Alice'); $mapper->save($user);
  • 55. class User {     protected $_name;     protected $_birthday;     public function setName($name) { /*~*/ }     public function getName() { /*~*/ }     public function getAge() { /*~*/ }     public static function findByName($name) { /*~*/ }     public function save() { /*~*/ } }
  • 56. class User {     protected $_name;     protected $_birthday;     public function setName($name) { /*~*/ }     public function getName() { /*~*/ }     public function getAge() { /*~*/ }     public static function findByName($name) { /*~*/ }     public function save() { /*~*/ } }
  • 57. class User {     protected $_name;     protected $_birthday;     public function setName($name) { /*~*/ }     public function getName() { /*~*/ }     public function getAge() { /*~*/ }     public static function findByName($name) { /*~*/ }     public function save() { /*~*/ } }
  • 58. class User {     protected $_name;     protected $_birthday;     public function setName($name) { /*~*/ }     public function getName() { /*~*/ }     public function getAge() { /*~*/ }     public static function findByName($name) { /*~*/ }     public function save() { /*~*/ } }
  • 59. class User {     protected $_name;     protected $_birthday;     public function setName($name) { /*~*/ }     public function getName() { /*~*/ }     public function getAge() { /*~*/ } } class UserMapper {     public function findByName($name) { /*~*/ }     public function save(User $user) { /*~*/ } }
  • 60. class User {     protected $_name;     protected $_birthday;     public function setName($name) { /*~*/ }     public function getName() { /*~*/ }     public function getAge() { /*~*/ } } class UserMapper {     public function findByName($name) { /*~*/ }     public function save(User $user) { /*~*/ } }
  • 61. class User {     protected $_name;     protected $_birthday;     public function setName($name) { /*~*/ }     public function getName() { /*~*/ }     public function getAge() { /*~*/ } } class UserMapper {     public function findByName($name) { /*~*/ }     public function save(User $user) { /*~*/ } }
  • 62. class User {     protected $_name;     protected $_birthday;     public function setName($name) { /*~*/ }     public function getName() { /*~*/ }     public function getAge() { /*~*/ } } class UserMapper {     public function findByName($name) { /*~*/ }     public function save(User $user) { /*~*/ } }
  • 63. class Config {     protected static $_instance;     private function __construct() {}     public static function getInstance()     {         if (empty(self::$_instance)) {             self::$_instance = new self;         }         return self::$_instance;     } }
  • 64. public function __clone() {     throw new BadMethodCallException( 'Clone is not allowed.' ); }
  • 65. public function test_get_ () {     $config = Config::getInstance();     $config->set('message', 'Hello');     $this->assertSame( 'Hello', $config->get('message') ); }
  • 66. public function test_get_ Null() {     $config = Config::getInstance();     $this->assertNull( $config->get('message') ); }
  • 67. public function test_get_ Null() {     $config = Config::getInstance();     $this->assertNull( $config->get('message') ); }
  • 68. public function test_get_ Null() {     $config = Config::getInstance();     $config->init();     $this->assertNull( $config->get('message') ); }
  • 69. public function test_get_ Null() {     $config = Config::getInstance();     $config->init();     $this->assertNull( $config->get('message') ); }
  • 70. public function test_get_ Null() {     $config = Config::getInstance();     $config->init();     $this->assertNull( $config->get('message') ); }