2017 © Pedro Peláez
 

library pu-tester

Simple tester class designed to write PHPUnit tests in BDD-style. Allows to express what test intended to check in human-readable format.

image

dekeysoft/pu-tester

Simple tester class designed to write PHPUnit tests in BDD-style. Allows to express what test intended to check in human-readable format.

  • Tuesday, July 25, 2017
  • by DeathAngel
  • Repository
  • 2 Watchers
  • 6 Stars
  • 792 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

, (*1)

Build Status Code Coverage Code Quality Latest Stable Version Monthly Downloads Total Downloads License , (*2)

NOTICE: Library is under refactoring for release of V5.0.0 and docs reflect the new style of specs

Code Specs isn't just another tests library - it's the way you design your solutions. The Specs Way., (*3)

Code Specs is built as a PHPUnit plugin(with Codeception support as well) for writing BDD style Unit tests in a specification way using human-readable format., (*4)

Goal of Code Specs is to add a bunch of cool tools for unit testing and show a way of representing unit tests as a behavior specifications that describes specific class behavior in variety of use-cases., (*5)

The min hero of Code Specs that does the magic is Tester. Tester represents an actor who ensures you code pass specifications(yes, like in Codeception - this library expired by Codeception). See iy by yourself:, (*6)

namespace Specs\Unit;

use PHPKitchen\CodeSpecs\Base\Specification;
use PHPKitchen\CodeSpecs\Actor\I;

/**
 * Specification of {@link IncomeCalculator}
 *
 * @author Dima Kolodko <prowwid@gmail.com>
 */
class IncomeCalculatorTest extends Specification {
    private const EXPECTED_TAX_FOR_FIRST_LEVEL_TAX_RULE = 4500;
    private const EXPECTED_TAX_FOR_SECOND_LEVEL_TAX_RULE = 7200;
    private const EXPECTED_TAX_FOR_THIRD_LEVEL_TAX_RULE = 30000;
    private const INCOME_AFTER_APPLYING_FIRST_LEVEL_TAX_RULE = 300000;

    /**
     * @test
     */
    public function calculateTaxBehavior() {
        $clientsPayments = []; // dummy variable, just for example
        $hoursSpentWorking = 160; // dummy variable, just for example
        $service = new IncomeCalculator($clientsPayments, $hoursSpentWorking);
        I::describe('income tax calculations');

        I::expect('for income less that 50 000 calculator use 10% tax rule', function () use ($service) {
            I::lookAt('first level income tax')
                ->seeNumber($service->calculateTax())
                ->isNotEmpty()
                ->isEqualTo(self::EXPECTED_TAX_FOR_FIRST_LEVEL_TAX_RULE);
        });

        I::expect('for income between 50 000 and 100 000 calculator use 12% tax rule', function () use ($service) {
            I::lookAt('second level income tax')
                ->seeNumber($service->calculateTax())
                ->isNotEmpty()
                ->isEqualTo(self::EXPECTED_TAX_FOR_SECOND_LEVEL_TAX_RULE);
        });

        I::expect('for income more than 100 000 calculator use 20% tax rule', function () use ($service) {
            I::lookAt('second level income tax')
                ->seeNumber($service->calculateTax())
                ->isNotEmpty()
                ->isEqualTo(self::EXPECTED_TAX_FOR_THIRD_LEVEL_TAX_RULE);
        });
    }

    /**
     * @test
     */
    public function calculateWithTaxBehavior() {
        $clientsPayments = []; // dummy variable, just for example
        $hoursSpentWorking = 160; // dummy variable, just for example
        $service = new IncomeCalculator($clientsPayments, $hoursSpentWorking);

        I::describe('Net income calculation');
        I::expect('calculator calculates income with tax using 10% tax rule for income less that 50 000');

        I::lookAt('income tax')
            ->seeNumber($service->calculateWithTax())
            ->isNotEmpty()
            ->isEqualTo(self::INCOME_AFTER_APPLYING_FIRST_LEVEL_TAX_RULE);


    }
}

CodeSpecs also decorates errors output so, for example, if "IncomeCalculator" service from example above will incorrectly calculate income the error output will include following message(example of output in PHPStorm):, (*7)

picture alt, (*8)

Requirements

PHP >= 7.4 is required., (*9)

PHPUnit >= 9.1 is required., (*10)

Getting Started

Run the following command to add CodeSpecs to your project's composer.json. See Packagist for specific versions., (*11)

composer require --dev php-kitchen/code-specs

Or you can copy this library from: - Packagist - Github, (*12)

Then you can use CodeSpecs in your test simply extending from Specification class. Example:, (*13)

use PHPKitchen\CodeSpecs\Base\Specification;

class YourTest extends Specification {

    /**
     * @test
     */
    public function myMethodBehavior() {
        I::lookAt('my dummy variable')
            ->seeBool(true)
            ->isFalse();
    }
}

Note: If you want to use CodeSpecs with Codeception read Codeception integration guide, (*14)

For additional information and guides go to the project documentation See changes log for information about changes in releases and update guide for information about upgrading to a next major version., (*15)

Contributing

If you want to ask any questions, suggest improvements or just to talk with community and developers, join our server at Discord Read organization contributing rules for additional information., (*16)

Spreading the Word

Acknowledging or citing CodeSpecs is as important as direct contributions., (*17)

If you are using CodeSpecs as part of an OpenSource project, a way to acknowledge it is to use a special badge in your README: Tested By, (*18)

If your code is hosted at GitHub, you can place the following in your README.md file to get the badge:, (*19)

[![CodeSpecs](https://img.shields.io/badge/Tested_By-CodeSpecs-brightgreen.svg?style=flat)](https://github.com/php-kitchen/code-specs)

or use regular HTML:, (*20)

<a href="https://github.com/php-kitchen/code-specs"><img src="https://img.shields.io/badge/Tested_By-CodeSpecs-brightgreen.svg" alt="Tested By"></a>

The Versions

25/07 2017

dev-master

9999999-dev

Simple tester class designed to write PHPUnit tests in BDD-style. Allows to express what test intended to check in human-readable format.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Dmitry Kolodko

bdd phpunit extension tests tester unit tests

25/07 2017

2.0.1

2.0.1.0

Simple tester class designed to write PHPUnit tests in BDD-style. Allows to express what test intended to check in human-readable format.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Dmitry Kolodko

bdd phpunit extension tests tester unit tests

24/07 2017

2.0.0

2.0.0.0

Simple tester class designed to write PHPUnit tests in BDD-style. Allows to express what test intended to check in human-readable format.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Dmitry Kolodko

bdd phpunit extension tests tester unit tests

19/10 2016

1.0.0

1.0.0.0

Simple tester class designed to write PHPUnit tests in BDD-style. Allows to express what test intended to check in human-readable format.

  Sources   Download

MIT

The Requires

  • php ^5.6|^7.0

 

The Development Requires

by Dmitry Kolodko

bdd phpunit extension tests tester unit tests

28/06 2016

0.0.3

0.0.3.0

Simple tester class designed to write BDD-style PHPUnit tests. Allows to express what test intended to check in human-readable format.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Kolodko

27/06 2016

0.0.2

0.0.2.0

Simple tester class designed to write BDD-style PHPUnit tests. Allows to express what test intended to check in human-readable format.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Kolodko

01/06 2016

0.0.1

0.0.1.0

Simple tester class designed to write BDD-style PHPUnit tests. Allows to express what test intended to check in human-readable format.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Kolodko