Coder Social home page Coder Social logo

phpinlinetest's Introduction

PhpInlineTest English version

PhpInlineTest is script to run inline tests for PHP functions and class methods

WTF is inline tests?

Inline tests are asserts embedded right into PHPDOC-comments.

Benefits

  • Easy and fast to add tests for your functions.
  • Tests can complement/replace documentation for method.
  • Can be written for private/protected class methods.
  • You will never lose them: they are always inside scripts.

Downsides

  • Good only for simple test cases.
  • Can be written only for isolated functions: input - arguments, output - return value.

How to use? It is easy:

Step 1. Write assert line in PHPDOC-comment for class method or function:

<?php
class A {
	/**
	 * Inline test example
	 *     for private class method
	 * @assert (2, 2) == 4
	 */
	private function _add($a, $b) {
		return $a + $b;
	}
}

Step 2. Download latest version of phpinlinetest.

Step 3. Run phpinlinetest to check your asserts:

$ php phpinlinetest.php
.\example.php
Test "_add(2, 2) == 4": OK
Files: 1, tests: 1, succeed: 1, failed: 0

Step 4. Enjoy!


PhpInlineTest Русская версия

PhpInlineTest - это скрипт для запуска inline-тестов для PHP функций и методов класса

Что это еще такое за inline-тесты?

Inline-тесты - это тесты, встроенные непосредственно в PHPDOC-комментарии.

Плюсы

  • Легко и быстро можно добавить тесты для ваших функций.
  • Тесты могут замещать/дополнять документацию для метода.
  • Могут быть написаны для закрытых методов класса.
  • Вы никогда не потеряете их: тесты всегда внутри скрипта.

Минусы

  • Подходят только для простых случаев.
  • Могут быть написаны только для изолированных функций: вход - аргументы, выход - возвращаемое значение.

Как их использовать? Это просто:

Шаг 1. Напишите строку теста функции в PHPDOC-комментарии:

<?php
class A {
	/**
	 * Пример inline-теста
	 *     для закрытого метода класса
	 * @assert (2, 2) == 4
	 */
	private function _add($a, $b) {
		return $a + $b;
	}
}

Шаг 2. Скачайте последнюю версию phpinlinetest.

Шаг 3. Запустите phpinlinetest, чтобы проверить ваши тесты:

$ php phpinlinetest.php
.\example.php
Test "_add(2, 2) == 4": OK
Files: 1, tests: 1, succeed: 1, failed: 0

Шаг 4. Наслаждайтесь!


Keywords: phpinlinetest, php, inline, test, unit, doctest, testing, documentation, phpdoc, comments, methods, private

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.