local php-100828 2
DESCRIPTION
第11回 LOCAL PHP部勉強会での発表資料ですTRANSCRIPT
![Page 1: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/1.jpg)
PHPで
かんたんテストススメ
@iakio第 11回 LOCAL PHP部勉強会
2010/08/28
![Page 2: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/2.jpg)
テストって?
![Page 3: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/3.jpg)
SimpleTest
PHPUnit
![Page 4: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/4.jpg)
SimpleTest
<?phprequire_once('simpletest/autorun.php');require_once('../fizzbuzz.php');
class TestFizzbuzz extends UnitTestCase { function testFizzBuzzOne() { $this->assertEqual(fizzbuzz(1), 1); }}?>
![Page 5: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/5.jpg)
いうほど
Simple
でもない
![Page 6: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/6.jpg)
Test::Simple
Test::More
![Page 7: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/7.jpg)
ok(fizzbuzz(1) ==1);
is(fizzbuzz(1), 1);
![Page 8: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/8.jpg)
但し Perlのモジュール
![Page 9: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/9.jpg)
いくつか実装があるようです
● http://testanything.org/wiki/index.php/TAP_Producers
● Apache::Test● test-more-php
![Page 10: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/10.jpg)
search.cpan.org
Test.php
![Page 11: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/11.jpg)
#!/usr/bin/php<?phprequire_once('.../tlib/Test.php');require_once('../fizzbuzz.php');plan('no_plan');
is (fizzbuzz(1), 1);is (fizzbuzz(2), 2);is (fizzbuzz(3), "fizz");
![Page 12: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/12.jpg)
Tips
![Page 13: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/13.jpg)
YAML を使う
<?php$data = array( 'id' => 1, 'name' => 'hoge', 'description' => '....');
$data = Y(<<<EODid : 1name : hogedescription : ...EOD);
![Page 14: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/14.jpg)
objectへのキャスト
<?phpis($data['foo'], 'foo');is($data['bar'], 'bar');
$o = (object) $data;is($o->foo, 'foo');is($o->bar, 'bar');
![Page 15: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/15.jpg)
脱線
(本編 ?)
![Page 16: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/16.jpg)
Test.php-0.13 $ cat t/0-compile.t#!/usr/bin/env php<?phprequire 'Test.php';
plan(1);
ok(0 == 0);?>Test.php-0.13 $ make testprove -r tt/0-compile.t ............ okt/1-plan-1.t ............. ok
![Page 17: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/17.jpg)
誰かが PHP を起動している
![Page 18: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/18.jpg)
#/usr/bin/php
<?php phpinfo();?>
![Page 19: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/19.jpg)
$ perl phpinfo.php
phpinfo()
PHP Version => 5.1.6
System => Linux localhost.localdomain
...
![Page 20: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/20.jpg)
Shebang(シバン、シェバン )
chmod +x されたスクリプトを
実行したときに shellが使うもの
![Page 21: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/21.jpg)
でも Perl とRubyは
Shebang をみます
![Page 22: Local php-100828 2](https://reader033.vdocuments.site/reader033/viewer/2022052903/5575e354d8b42af74e8b479a/html5/thumbnails/22.jpg)
phpでも shebang を書いておけば
proveが使えます