Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TDD - Think First, Code Later, PHP Way

TDD - Think First, Code Later, PHP Way

A unit test concept in php

Hiraq Citra M

February 12, 2014
Tweet

More Decks by Hiraq Citra M

Other Decks in Programming

Transcript

  1. 3 Factors 1. Test 2. Code 3. Refactor Result: 1.

    Readable code 2. Managed code
  2. How? User Stories: As a guest, i want to go

    to homepage and want to see “hello World” message
  3. Test Code <?php //cakephp way $msg = $this->testAction(‘/’, array(‘return’ =>

    ‘contents’)); $this->assertEquals(‘hello World’, $msg); ====================================================== == <?php //laravel way $msg = $this->call(‘GET’, ‘/’); $this->assertEquals(‘hello World’, $msg);
  4. Implement Feature ~ CakePHP <?php //file: app/Controller/HomeController.php class HomeController extends

    AppController { public function index() { $this->autoRender = false; echo ‘hello world’; } }
  5. Good Quality Good Quality == Good Business Good Quality ==

    More Happy Customers Good Quality == More Happy Programmers Happy Programmers == Readable Source Code Readable Source Code == Good Quality
  6. Time Management CODE FIRST, TEST LATER == TIME LOSS TEST

    FIRST, CODE LATER == TIME INVESTMENT
  7. Time Loss 1. We don’t know bug 2. We don’t

    know errors 3. We don’t know fail validations! Question: If you don’t know anything, are you sleeping or coding? 4. Test features? just open the browser! It’s 2014 now!!
  8. Time Investment 1. More fast we detect a bug, we

    can fix it faster! 2. More fast we know an error, we can fix it faster! 3. We control the code, not controlled by code! 4. Test all features? One single hit => Enter!
  9. MVC Framework Unit Test 1. Controller 2. Model 3. View

    4. Library / Vendor /Package 5. Helper
  10. Forbidden Framework 1. Developed not by test 2. Not integrated

    with unit test 3. Cannot test their own self!
  11. Unit Test Environment 1. OS: Linux Base (Ubuntu) 2. PHP

    Error Level: error_reporting(-1) *all