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

PHP standards

What is PSR? PSR is a standard established by PHP-FIG(PHP Framework Interop Group). PSR consists of several standards such as PSR-1, PSR-2 and PSR-4. PSR-0 and PSR-4 are coding standards for PHP’s autoloaders, PSR-1 and PSR-2 are basic coding standards. PHP code MUST use only UTF-8 without BOM(Byte Order Mark). PSR-1 Basic Coding Standard, defines basic parts of PHP coding Only <?php ?> or <?= ?> are allowed for PHP tags Files must be in UTF-8 without BOM(Byte Order Mark) Namespaces and class names must follow the standards in PSR-0 and PSR-4 Class names must be defined in UpperCamelCase Class variables must be defined in UPPER_SNAKE_CASE Method names must be defined in camelCase // defining normal properties in camelCase // defining static properties in UpperCamelCase // Class constants MUST be declared in all upper case with underscore separators class Something { public $normalPropterty; public static $StaticProperty; const VERSION = '1.0'; const DATE_APPROVED = '2000-12-01'; } PSR-2 Coding style Guide, an extension of PSR-1 You must follow PSR-1 coding standards 4 spaces must be used for indents. Using tabs is not allowed There is no limit to line length, but it should be under 120 characters, and best if under 80 You must put a newline before curly braces for classes and methods Methods and properties must be defined with abstract/final first, followed with public/protected, and finally static. You must not put a newline before curly braces in conditional statements You must not put any spaces before ( and ) in conditional statements PSR-12: Extended Coding Style, is now recommended for PSR-2. .php files must use Unix LF(linefeed) line \n ending only. .php files must end with a non-blank line. closing ?> tag must be omitted from .php files containing only php. Compound namespaces with a depth of more than two MUST NOT be used. namespace SubnamespaceOne\Anothernamespace\ClassA; <?php /** * This file contains an example of coding styles. */ declare(strict_types=1); // MUST be one blank line after the namespace declaration namespace Vendor\Package; // MUST be one blank line after the block of use declarations. use Vendor\Package\{ClassA as A, ClassB, ClassC as C}; use Vendor\Package\SomeNamespace\ClassD as D; use function Vendor\Package\{functionA, functionB, functionC}; use const Vendor\Package\{ConstantA, ConstantB, ConstantC}; use Vendor\Package\FirstTrait; // Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body. class Foo extends Bar implements FooInterface { // use keyword used inside the classes to implement traits MUST be declared on the next line after the opening brace. use FirstTrait; // Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body. public function sampleFunction(int $a, int $b = null): array { if ($a === $b) { bar(); } elseif ($a > $b) { $foo->bar($arg1); } else { BazClass::bar($arg2, $arg3); } } // abstract and final MUST be declared before the visibility; // static MUST be declared after the visibility. final public static function bar() { // method body } } Reference PSR-1 PSR-2 PSR-12 5 PHP coding statands Code Sytle Guide

June 17, 2020 · 3 min · 513 words · Ken Cho

PHPUnit

What is PHPUnit? The goal of unit testing is to isolate each part of the programme and show that the individual parts are correct. What does Assertions mean? Just asserting that something match the expected value or does something you wanted to do. Whats the flow of running phpunit? Install the PHPUnit Configure the phpunit.xml <?xml version="1.0" encoding="utf-8" ?> <phpunit bootstrap="vendor/autoload.php" colors="true" verbose="true" stopOnFailure="false"> <testsuites> <testsuite name="unit"> <directory>tests/unit</directory> </testsuite> </testsuites> </phpunit> Create app, app/Modelsand tests/unit folders Build codes bite by bite, and then run phpunit ./vendor/bin/phpunit File name and the class name must be the same! For example, UserTest.php ...

June 16, 2020 · 2 min · 341 words · Ken Cho

How to add a comment functionality using uterances

What is Utterances? A lightweight comments widget built on GitHub issues. Use GitHub issues for blog comments. Open source. Allow Markdown syntax. Configuration Create an empty Github repo. Install utterances app on that repo In the utterances app, only select the repo just created for comment. Update config.toml as below: [params.utteranc] enable = true repo = "owner/comments_for_hugo" issueTerm = "pathname" theme = "github-light" Create contents/ folders in layouts directory. Create single.html in the layouts/*. Add the following script to /layouts/*/single.html <script src="https://utteranc.es/client.js" repo="owner/comments_for_hugo" issue-term="pathname" label="comments" theme="github-light" crossorigin="anonymous" async> </script> Utterances comments functionality is installed. Reference Utterances How to add Utterances in config.toml

June 15, 2020 · 1 min · 102 words · Ken Cho

Docker 101

What is Docker? In simpler words, Docker is a tool that allows developers, sys-admins etc. to easily deploy their applications in a sandbox (called containers) to run on the host operating system i.e. Linux. The key benefit of Docker is that it allows users to package an application with all of its dependencies into a standardized unit for software development. Unlike virtual machines, containers do not have high overhead and hence enable more efficient usage of the underlying system and resources. ...

June 11, 2020 · 4 min · 704 words · Ken Cho