承接 jehoshua02/json-files 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jehoshua02/json-files

最新稳定版本:1.0.0

Composer 安装命令:

composer require jehoshua02/json-files

包简介

Helper classes for loading and iterating json files.

README 文档

README

Helper classes for loading and iterating json files.

Install

Use composer:

composer require jehoshua02/json-files

Usage

Given the following directory structure:

+ SomeClass.php
+ SomeClass.test.php
+ SomeClass.test.data/
|--+ someMethod/
|----+ simple.json
|----+ complex.json

Iterator

In SomeClass.test.php:

  1. Bring in the iterator with use.
  2. Return the iterator from data provider.
<?php

use \Stoutie\JsonFiles; /* [1] */

class SomeClassTest extends PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider someMethodDataProvider
     */
    public function testSomeMethod(/* ... args ... */)
    {
        /* ... test ... */
    }

    public function someMethodDataProvider()
    {
        return new JsonFiles\Iterator(__FILE__); /* [2] */
    }
}

The loader and iterator will replace .php on the end of the path with .data. This allows a very concise syntax of passing in __FILE__ and enables the convention of placing test data in SomeClass.test.data, which matches the name of the test file.

Although the primary use case the iterator was designed for was as a data provider in unit tests, other than the path replacement and data directory convention, it is otherwise generic and can be used to iterate on json files in any context.

Loader

<?php

$jsonLoader = new JsonFiles\Loader(__FILE__);
$data = $jsonLoader->load('someMethod/simple');

Again, by convention, .php at the end of path will be replaced with .data, but any path can be passed in and the loader is rather generic.

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-11