alfred-nutile-inc / fixturizer
该包最新版本(1.2)没有可用的许可信息。
1.2
2015-05-03 14:06 UTC
Requires
- php: >=5.4.0
- illuminate/support: *
- symfony/filesystem: *
- symfony/yaml: < 2.7
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-14 16:43:38 UTC
README
Fixturizer
快速编写和读取 fixture 数据的方法。
接受 PHP 数组并将其快速转换为文件系统中的 yaml 文件,反之亦然。
查看测试文件夹中的测试示例
非 Laravel 使用
您可以在 tests/FixturizerTest.php 文件中看到一些使用示例。主要目标是 Writer 或 Reader 允许您轻松传递文件名和路径以获取或放置 yml 格式的文件/fixture 数据。
如果您正在使用 Laravel 5.x
加载提供者和外观
在 config/app.php 中在提供者下加载
'AlfredNutileInc\Fixturizer\FixturizerServiceProvider'
在外观下加载
'FixturizerReader' => 'AlfredNutileInc\Fixturizer\FixturizerReader',
'FixturizerWriter' => 'AlfredNutileInc\Fixturizer\FixturizerWriter',
默认文件夹是 tests/fixtures,但您可以通过以下方式修改它:
php artisan vendor:publish --provider="AlfredNutileInc\Fixturizer\FixturizerServiceProvider"
然后您可以在测试文件中像下面这样使用它
<?php
use AlfredNutileInc\Fixturizer\FixturizerReader;
use AlfredNutileInc\Fixturizer\FixturizerWriter;
class FixtureTest extends \TestCase {
/**
* @test
*/
public function should_write_fixture()
{
$fixture = ['foo' => 'bar'];
FixturizerWriter::createFixture($fixture, 'foo.yml');
$this->assertFileExists(FixturizerWriter::getDestination() . 'foo.yml');
}
/**
* @test
*/
public function should_read_fixture()
{
$name = 'foo.yml';
$path = base_path() . '/tests/fixtures/';
$results = FixturizerReader::getFixture($name, $path);
$this->assertNotNull($results);
}
}