دوره PHP Test & TDD (Test Driven Development)

PHP Unit Testing یک چهارچوب انجام تست در زبان برنامه نویسی PHP است که توسط Sebastian Bergmann تولید شده و در GitHub میزبانی می شود. Unit Test امکان تست هر بخش برنامه و کد به صورت جداگانه را فراهم می کند.

 هدف اصلی این قالب، کنترل صحت و کیفیت هر بخش برنامه است تا کوچکترین اجزای قابل آزمایش یک برنامه به صورت جزء به جزء بررسی شود و اطمینان حاصل گردد که این اجزا به درستی کار می کنند. این چهارچوب، نمونه ای از xUnit برای Unit Testing می باشد که با SUnit ایجاد شده است و می تواند تست واحد کدهای PHP را انجام داده و چگونگی عملکرد آن را کنترل نماید.

شاید انجام این فرآیند در ظاهر کاری زمانبر باشد اما اطمینان از صحت عملکرد بخش های مختلف، باگ ها و مشکلات کمتری را در ادامه کار به دنبال خواهد داشت و زمان تولید نرم افزار را کاهش می دهد. مزیت این پروسه این است که برای انجام تستهای بعدی، خودکارسازی صورت می گیرد و از طرفی باعث افزایش مهارت در برنامه نویس می شود و موجب ایجاد داکیومنت و کدهای قوی تری نیز می گردد.

 

محتوا:  آموزش تست واحد و آزمایش ماژول ها و نحوه پروفایل کردن بخش های مختلف نرم افزار php

هدف : کنترل صحت و کیفیت هر بخش برنامه php

مدت دوره : ۵۲ ساعت

پیش نیاز: آشنایی و سابقه کار با زبان PHP

زمان برگزاری: لطفا به تقویم آموزشی مراجعه فرمایید.

 

Installing PHP Unit

  • Requirements
  • PHP Archive (PHAR)
  • Windows
  • Verifying PHP Unit PHAR Releases
  • Composer
  • Optional packages

 

PHP Unit Support in IDEs

  • PhpStorm

 

Tests and What They're All About

  • Understanding unit testing
  • What is a unit test?
  • Assertions
  • The importance of unit testing
  • Testing all possible scenarios
  • What makes a good test?
  • When to write tests
  • Anatomy of a PHP Unit test
  • Defining test methods
  • Testing functions
  • Testing methods
  • The MVC application architecture and tests
  • Testing controllers

 

Writing Tests for PHP Unit

  • Test Dependencies
  • Data Providers
  • Testing Exceptions
  • Testing PHP Errors
  • Testing Output
  • Error output
  • Edge cases

 

The Command-Line Test Runner

  • Command-Line Options
  • Running tests
  • Processing test results
  • Test statuses
  • Command-line switches
  • Logging results
  • Code coverage
  • Including and excluding tests from the execution
  • When to stop the test execution
  • Configuration options
  • Code coverage analysis

 

Fixtures and Test Isolation and Interaction

  • More setUp() than tearDown()
  • Variations
  • Sharing Fixture
  • Global State
  • Test dependencies
  • Before and after each test method
  • Before and after each test suite class

 

Organizing Tests

  • Composing a Test Suite Using the File systems
  • Composing a Test Suite Using XML Configuration

 

Risky Tests

  • Useless Tests
  • Unintentionally Covered Code
  • Output During Test Execution
  • Test Execution Timeout
  • Global State Manipulation

 

Incomplete and Skipped Tests

  • Incomplete Tests
  • Skipping Tests
  • Skipping Tests using @requires

 

Database Testing

  • Supported Vendors for Database Testing
  • Difficulties in Database Testing
  • The four stages of a database test
  1. Clean-Up Database
  2. Set up fixture

       3–5. Run Test, Verify outcome and Teardown

  • Configuration of a PHP Unit Database Test Case

            Implementing getConnection()

            Implementing getDataSet()

            What about the Database Schema (DDL)?

            Tip: Use your own Abstract Database Test Case

  • Understanding DataSets and DataTables

            Available Implementations

            Beware of Foreign Keys

            Implementing your own DataSets/DataTables

  • Using the Database Connection API
  • Database Assertions API

            Asserting the Row-Count of a Table

            Asserting the State of a Table

            Asserting the Result of a Query

            Asserting the State of Multiple Tables

  • Frequently Asked Questions

            Will PHP Unit (re-)create the database schema for each test?

            Am I required to use PDO in my application for the Database Extension to work?

            What can I do, when I get a “Too much Connections” Error?

            How to handle NULL with Flat XML / CSV Datasets?

 

Test Doubles

  • Stubs
  • Mock Objects
  • Prophecy
  • Mocking Traits and Abstract Classes
  • Stubbing and Mocking Web Services
  • Mocking the Filesystem

 

Testing Practices

  • During Development
  • During Debugging

 

Code Coverage Analysis

  • Software Metrics for Code Coverage
  • Whitelisting Files
  • Ignoring Code Blocks
  • Specifying Covered Methods
  • Edge Cases

 

Other Uses for Tests

  • Agile Documentation
  • Cross-Team Tests

 

Testing Legacy Code

  • Testing spaghetti code

            Black box testing

            Using Reflection

 

  • Handling dependencies

            The Patchwork library

            The vfsStream library

            The runkit PHP extension

 

Logging

  • Test Results (XML)
  • Code Coverage (XML)
  • Code Coverage (TEXT)

 

Extending PHP Unit

  • Subclass PHP Unit\Framework\TestCase
  • Write custom assertions
  • Implement PHP Unit\Framework\TestListener
  • Subclass PHP Unit_Extensions_TestDecorator
  • Implement PHP Unit_Framework_Test

 

Assertions

Static vs. Non-Static Usage of Assertion Methods

assertArrayHasKey()

assertClassHasAttribute()

assertArraySubset()

assertClassHasStaticAttribute()

assertContains()

assertContainsOnly()

assertContainsOnlyInstancesOf()

assertCount()

assertDirectoryExists()

assertDirectoryIsReadable()

assertDirectoryIsWritable()

assertEmpty()

assertEqualXMLStructure()

assertEquals()

assertFalse()

assertFileEquals()

assertFileExists()

assertFileIsReadable()

assertFileIsWritable()

assertGreaterThan()

assertGreaterThanOrEqual()

assertInfinite()

assertInstanceOf()

assertInternalType()

assertIsReadable()

assertIsWritable()

assertJsonFileEqualsJsonFile()

assertJsonStringEqualsJsonFile()

assertJsonStringEqualsJsonString()

assertLessThan()

assertLessThanOrEqual()

assertNan()

assertNull()

assertObjectHasAttribute()

assertRegExp()

assertStringMatchesFormat()

assertStringMatchesFormatFile()

assertSame()

assertStringEndsWith()

assertStringEqualsFile()

assertStringStartsWith()

assertThat()

assertTrue()

assertXmlFileEqualsXmlFile()

assertXmlStringEqualsXmlFile()

assertXmlStringEqualsXmlString()

 

Annotations

@ author

@ after

@ afterClass

@ backupGlobals

@ backupStaticAttributes

@ before

@ beforeClass

@ codeCoverageIgnore

@ covers

@ coversDefaultClass

@ coversNothing

@ dataProvider

@ depends

@ doesNotPerformAssertions

@ expectedException

@ expectedExceptionCode

@ expectedExceptionMessage

@ expectedExceptionMessageRegExp

@ group

@ large

@ medium

@ preserveGlobalState

@ requires

@ runTestsInSeparateProcesses

@ runInSeparateProcess

@ small

@ test

@ testdox

@ testWith

@ ticket

@ uses

 

The XML Configuration File

  • PHP Unit
  • Test Suites
  • Groups
  • Whitelisting Files for Code Coverage
  • Logging
  • Test Listeners
  • Setting PHP INI settings, Constants and Global Variables

 

EN / FA

فناوران آنیسا - خانه لینوکس ایران

تهران، میدان آرژانتین، خ وزرا، کوچه هشتم، یحیوی، پلاک ۴

 اطلاعات تماس:

  • 021-88716168
  • 021-88712172
  • 0910-8555111

info @ anisa.co.ir

© فناوران آنیسا - خانه لینوکس ایران | تمامی حقوق این سایت تحت مجوز GFDL برای فناوران آنیسا محفوظ است.
design by www.digitaldesign.ir