Bdd

What is Behavior Driven Development? Behavior Driven Development (BDD) is a branch of Test Driven Development (TDD). BDD uses human-readable descriptions of software user requirements as the basis for software tests. Introduction of BDD from Konstantin Kudryashov, the creator of Behat YouTube What is gherkin language? Gherkin is a Business Readable, Domain Specific Language created specifically for behavior descriptions. Gherkin is a whitespace-oriented language that uses indentation to define structure. ...

July 15, 2020 · 2 min · 355 words · Ken Cho

PHP_CodeSniffer

What is PHP_CodeSniffer? PHP_CodeSniffer is a set of two PHP scripts: phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard. phpcbf script to automatically correct coding standard violations. Installation Follow here Usage Checking files and folders vendor/bin/phpcs /path/to/code Printing summary report vendor/bin/phpcs --report=summary /path/to/code Specifying a Coding Standard vendor/bin/phpcs --standard=PEAR /path/to/code/myfile.php List all installed coding standards vendor/bin/phpcs -i eg.The installed coding standards are PEAR, PSR1, PSR12, PSR2, Squiz and Zen ...

July 7, 2020 · 3 min · 577 words · Ken Cho

PHP date times

What is timestamp? A timestamp is the number of seconds from January 1, 1970 at 00:00. <?php //output number of seconds from Jan 1, 1970 at 00:00. echo time(); echo date("d/m/y")."\n"; $now = getdate(); echo $now["hours"]+8; //print_r ($now); // 'z' is indexed from 0, so it is necessary to add 1. $numDays = date("z", mktime(0,0,0,12,31,2020))+1; $numWeeks = date("W", mktime(0,0,0,12,31,2020)); echo "There are $numDays days and $numWeeks weeks in 2020.\n"; How to display the current date/time? <?php // get current date and time // getdate() returns an array of values // notice that the 0th element of the array returned by getdate() contains a UNIX timestamp $now = getdate(); // turn it into strings $currentTime = $now["hours"]+6 . ":" . $now["minutes"] .":" . $now["second"]; $currentDate = $now["mday"] . "." . $now["mon"] . "." . $now["year"]; // result: "It is now 12:37:47 on 30.10.2006" echo "It is now $currentTime on $currentDate"; What are the formats of displaying? Important Full Date and Time Parameters Description r Displays the full date, time and timezone offset. It is equivalent to manually entering date(“D, d M Y H:i:s O”) Time Parameters Description a am or pm depending on the time A AM or PM depending on the time g Hour without leading zeroes. Values are 1 through 12 G Hour in 24-hour format without leading zeroes. Values are 0 through 23 h Hour with leading zeroes. Values 01 through 12 H Hour in 24-hour format with leading zeroes. Values 00 through 23 i Minute with leading zeroes. Values 00 through 59 s Seconds with leading zeroes. Values 00 through 59 Day Parameters Description d Day of the month with leading zeroes. Values are 01 through 31 j Day of the month without leading zeroes. Values 1 through 31 D Day of the week abbreviations. Sun through Sat l Day of the week. Values Sunday through Saturday w Day of the week without leading zeroes. Values 0 through 6 z Day of the year without leading zeroes. Values 0 through 365 Month Parameters Description m Month number with leading zeroes. Values 01 through 12 n Month number without leading zeroes. Values 1 through 12 M Abbreviation for the month. Values Jan through Dec F Normal month representation. Values January through December t The number of days in the month. Values 28 through 31 Year Parameters Description L 1 if it’s a leap year and 0 if it isn’t Y A four digit year format y A two digit year format. Values 00 through 99 Other Formatting Parameters Description U The number of seconds since the Unix Epoch (January 1, 1970) O This represents the Timezone offset, which is the difference from Greenwich Meridian Time (GMT). 100 = 1 hour, -600 = -6 hours How to turn a UNIX timestamp into a human-readable string? <?php // get date // result: "30 Oct 2006" (example) echo date("d M Y"). " <br>"; // get time // result: "12:38:26 PM" (example) echo date("h:i:s A"). " <br>"; // get date and time // result: "Monday, 30 October 2006, 12:38:26 PM" (example) echo date ("l, d F Y, h:i:s A") . " <br>"; // get time with timezone // result: "12:38:26 PM UTC" echo date ("h:i:s A T") . " <br>"; // get date and time in ISO8601 format // result: "2006-10-30T12:38:26+00:00" echo date ("c"); ?> How to convert between mm and hh:mm formats? <?php // define number of minutes $mm = 156; // convert to hh:mm format // result: "02h 36m" echo sprintf("%02dh %02dm", floor($mm/60), $mm%60); ?> <?php // define hours and minutes $hhmm = "02:36"; // convert to minutes // result: "156 minutes" $arr = explode(":", $hhmm); echo $arr[0]*60 + $arr[1] . " minutes"; ?> How to convert local time to Greenwich Mean Time (GMT)? <?php // convert current local time (IST) to GMT // result: "15:06:25 30-Oct-06 GMT" (example) echo gmdate("H:i:s d-M-y T") . "<br>"; // convert specified local time (IST) to GMT // result: "23:00:00 01-Feb-05 GMT" (example) $ts = mktime(4,30,0,2,2,2005); echo gmdate("H:i:s d-M-y T", $ts); ?> How to obtain the local time in another time zone, given its GMT offset? <?php // set default time zone to destination // result: "00:11:26 31-10-06 SST" date_default_timezone_set('Asia/Singapore'); echo date("H:i:s d-m-y") . " SST \n"; // set default time zone to destination // result: "08:11:26 30-10-06 PST" date_default_timezone_set('US/Pacific'); echo date("H:i:s d-m-y") . " PST \n"; ?> Reference PHP dates and times

July 3, 2020 · 4 min · 729 words · Ken Cho

Learn, todo and done 29/6-3/7/20

Learn Codeception in PhpStorm Functional test Unit test Todo Done PR Issue #460, functional test for admin site access. Issue #448 Problem Install codeception to PhpStorm is difficult, a lot of env param is invloved. Reference

June 29, 2020 · 1 min · 36 words · Ken Cho

Codeception

What is Codeception? Codeception is a framework written in PHP for testing application and its multi-featured test framework powered by famous PHPUnit Framework. It can manage Unit, Functional and Acceptance for web application. How to create a Unit Test? Testing pieces of code before coupling them together. It creates a new ExampleTest file located in the tests/unit directory. php vendor/bin/codecept generate:test unit Example Run the newly created test with this command. php vendor/bin/codecept run unit ExampleTest ...

June 23, 2020 · 1 min · 213 words · Ken Cho