hgsgtk / mpunit

Mini PHP xUnit Testing Framework
https://speakerdeck.com/hgsgtk/self-made-xunit
MIT License
16 stars 1 forks source link

testing script by phperkaigi2018 #4

Closed hgsgtk closed 5 years ago

hgsgtk commented 5 years ago

learn testing script by phperkaigi 2018 talk https://www.youtube.com/watch?v=o0YY0JnAOwU https://github.com/zonuexe/phperkaigi-test

hgsgtk commented 5 years ago
<?php declare(strict_types=1);

require_once __DIR__ . '/vendor/autoload.php';

(2 === 1 + 1) or die("LINE: " . __LINE__);
(3.0 === 1.5 + 1.5) or die("LINE: " . __LINE__);
$date = date('Y-m-d', 4502304000);
("2112-09-13" === $date) or die("LINE: " . __LINE__);

$a = [1, 2, 3];
(1 == array_shift($a)) or die("LINE: " . __LINE__);

echo "ok" . PHP_EOL;
hgsgtk commented 5 years ago
<?php declare(strict_types=1);

require_once __DIR__ . '/vendor/autoload.php';

assert(2 === 1 + 1);
assert(3 === 1.5 + 1.5);
assert('2112-09-13' === date('Y-m-d', 4503168000));

$a = [1, 2, 3];
assert(1 === array_shift($a));
hgsgtk commented 5 years ago

Software Framework

https://ja.wikipedia.org/wiki/%E3%82%BD%E3%83%95%E3%83%88%E3%82%A6%E3%82%A7%E3%82%A2%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%83%AF%E3%83%BC%E3%82%AF

ライブラリでは呼び出し側がプログラム全体の制御構造を指定できないが、フレームワークでは可能である。この制御の反転がソフトウェアフレームワークの特徴である

hgsgtk commented 5 years ago

https://github.com/hgsgtk/php-snippets/tree/master/simpleTestFramework

アサーションを実現するアイデアを学んだ