foothing / laravel-fixture
此包的最新版本(v0.1.0)没有可用的许可信息。
适用于Laravel 4的轻量级固定数据
v0.1.0
2015-02-16 19:21 UTC
Requires
- php: >=5.4.0
- illuminate/database: >=4.0.0
This package is auto-updated.
Last update: 2024-09-22 23:40:39 UTC
README
为Laravel 4提供基本轻量级固定数据管理。
如何使用
在测试用例中设置tearDown()
public function tearDown() { // Your code // ... Fixture::tearDown(); }
使用Fixture::need()
class FooTest { public function testBar() { // Create your fixture by passing the namespaced class name // you want to fixture and an array of attributes. // If an User instance matching the given attributes is found, // then it will be returned. Otherwise a new User instance will be // saved to the testing database. // Note that User must be an Eloquent implementation. $user = Fixture::need('User', array('email' => 'email1')); // Example, $user now exists with the given attributes. $this->assertEquals($user->email, 'email1'); // ... // more tests. } }
当您的测试需要给定实例时,您将想要使用 need 方法。
使用Fixture::needNot()
class FooTest { public function testBar() { // Ensure that no instances of Some\Object matching the given // attributes are stored in the testing database. Fixture::needNot('Some\Object', array('attribute' => 'value')); } }
当您的测试需要在运行之前清空数据库时,您将使用此方法。
这可能会节省您一些时间,因为您可以拥有一个精细的数据设置,而不是运行会减慢测试执行时间的迁移。
注意,Fixture 不是 一个门面,因此您不需要配置任何服务提供者。