GithubHelp home page GithubHelp logo

jellybellydev / phpspec-data-provider-extension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from madisoft/phpspec-data-provider-extension

0.0 2.0 0.0 40 KB

This extension allows you to create data providers for examples in specs.

License: MIT License

PHP 78.32% Gherkin 21.68%

phpspec-data-provider-extension's Introduction

#PhpSpec data provider extension

Build Status

This extension allows you to create data providers for examples in specs.

Installation

composer require coduo/phpspec-data-provider-extension

Usage

Enable extension in phpspec.yml file

extensions:
  Coduo\PhpSpec\DataProvider\DataProviderExtension: ~

Write a spec:

<?php

namespace spec\Coduo\ToString;

use PhpSpec\ObjectBehavior;

class StringLibrarySpec extends ObjectBehavior
{
    /**
     *  @dataProvider positiveConversionExamples
     */
    function it_convert_input_value_into_string($inputValue, $expectedValue)
    {
        $this->beConstructedWith($inputValue);
        $this->__toString()->shouldReturn($expectedValue);
    }

    public function positiveConversionExamples()
    {
        return array(
            array(1, '1'),
            array(1.1, '1.1'),
            array(new \DateTime, '\DateTime'),
            array(array('foo', 'bar'), 'Array(2)')
        );
    }
}

Write class for spec:

<?php

namespace Coduo\ToString;

class StringLibrary
{
    private $value;

    public function __construct($value)
    {
        $this->value = $value;
    }

    public function __toString()
    {
        $type = gettype($this->value);
        switch ($type) {
            case 'array':
                return sprintf('Array(%d)', count($this->value));
            case 'object':
                return sprintf("\\%s", get_class($this->value));
            default:
                return (string) $this->value;
        }
    }
}

Run php spec

$ console bin/phpspec run -f pretty

You should get following output:

Coduo\ToString\String

  12  ✔ convert input value into string
  12  ✔ 1) it convert input value into string
  12  ✔ 2) it convert input value into string
  12  ✔ 3) it convert input value into string
  12  ✔ 4) it convert input value into string


1 specs
5 examples (5 passed)
13ms

phpspec-data-provider-extension's People

Contributors

cordoval avatar dimitri-koenig avatar doncallisto avatar eichie avatar fabrizzio avatar lucaferri avatar m3gg3r avatar norberttech avatar omissis avatar

Watchers

 avatar  avatar

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.