2017 © Pedro Peláez
 

library codeception-dataprovider-module

Easy data providers in your Codeception tests.

image

jacekk/codeception-dataprovider-module

Easy data providers in your Codeception tests.

  • Monday, January 30, 2017
  • by jacekk
  • Repository
  • 2 Watchers
  • 3 Stars
  • 5,975 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 5 % Grown

The README.md

Codeception DataProvider Module

Build Status Total Downloads Latest Stable Version Latest Unstable Version License, (*1)

This module helps to manage data (that you use inside tests) in an easy way. Especially, when you like Yaml/YML files format., (*2)

Installation

Add the package into your composer.json file:, (*3)

{
    "require-dev": {
        "codeception/codeception": "2.*",
        "jacekk/codeception-dataprovider-module": "1.*"
    }
}

Tell Composer to download the package:, (*4)

$ composer update

Then, enable it in your my-awesome.suite.yml configuration and adjust two required params as in this library suite config:, (*5)

class_name: NoGuy
modules:
    enabled:
        - Asserts
        - DataProvider
    config:
        DataProvider:
            dataPathTpl: '{root}/tests/_data/{file}'
            files:
                - common-provider.yml
                - env-provider.dev.yml

You will need to rebuild your actor class:, (*6)

$ php codecept.phar build

or, (*7)

$ vendor/bin/codecept build

or whatever your tool set allowes :) At last, check out the examples section and use it daily :), (*8)

Parameters

dataPathTpl

Template to build paths to files listed by appropriate setting. Allowes for the following tokens, where the first one is obviously required:, (*9)

  • {file} - one of elements listed in files setting,
  • {root} - current working directory - PHP function: getcwd().

files

One or more files names, which can be found under path defined in dataPathTpl. If --env param is used heavily, then some files reuse is sort of built in., (*10)

Usage examples

getValue($keyName, $default = null)

YML content:, (*11)

headers:
    contentType: 'application/json'
    accept: 'text/html'

PHP code:, (*12)

public function testSomeHeaders(NoGuy $I)
{
    $headerValue = $I->getValue('headers.accept');
    $I->assertEquals('text/html', $headerValue);
    // or with somethin not set in YML files
    $authType = $I->getValue('headers.authorizationType', 'Bearer');
    $I->assertEquals('Bearer', $authType);
}

iterateOver($keyName, callable $callback)

YML content:, (*13)

users:
    admins:
        0:
            id: 123
            email: John(at)example.com
            fullName: John Example
        1:
            id: 321
            email: two(at)gmail.com
            fullName: Tom The Second

or (this will also work, even it is not an ordered list):, (*14)

users:
    admins:
        -
            id: 111
            email: mark(at)gmail.com
            fullName: Mark Whaleberg

PHP code:, (*15)

public function testAdminsDataInUsersResource(NoGuy $I)
{
    $I->iterateOver('users.admins', function ($user, $index) use ($I) {
        $userId = $user['id'];
        $I->sendGET("users/{$userId}");
        $I->seeResponseContainsJson([
            'id'        => $userId,
            'is_admin'  => true,
            'email'     => $user['email'],
            'full_name' => $user['fullName'],
        ]);
    });
}

See more examples in GetValueCest and IterateOverCest which verify this module quality., (*16)

License

Released under the same licence as Codeception: MIT., (*17)

The Versions

30/01 2017

dev-master

9999999-dev

Easy data providers in your Codeception tests.

  Sources   Download

MIT

The Requires

 

by Avatar jacekk

30/01 2017

v1.1.1

1.1.1.0

Easy data providers in your Codeception tests.

  Sources   Download

MIT

The Requires

 

by Avatar jacekk

24/01 2017

v1.1.0

1.1.0.0

Easy data providers in your Codeception tests.

  Sources   Download

MIT

The Requires

 

by Avatar jacekk

06/10 2016

v1.0.4

1.0.4.0

Easy data providers in your Codeception tests.

  Sources   Download

MIT

The Requires

 

by Avatar jacekk

04/10 2016

v1.0.3

1.0.3.0

Easy data providers in your Codeception tests.

  Sources   Download

MIT

The Requires

 

by Avatar jacekk

02/10 2016

v1.0.2

1.0.2.0

Easy data providers in your Codeception tests.

  Sources   Download

MIT

The Requires

 

by Avatar jacekk

02/10 2016

v1.0.1

1.0.1.0

Easy data providers in your Codeception tests.

  Sources   Download

MIT

The Requires

 

by Avatar jacekk

02/10 2016

v1.0.0

1.0.0.0

Easy data providers in your Codeception tests.

  Sources   Download

MIT

The Requires

 

by Avatar jacekk