我已经通过作曲家安装了FactoryMuffin。安装后,我运行作曲家dump-autload只是为了确保我正在使用最新的东西。
现在,当我尝试在代码中使用安装的软件包中的某些内容时,我将无法执行。例如:
use League\FactoryMuffin\Facade;
class APITest extends Sw_Test_PHPUnit_LibraryTestCase
{
public function setUp()
{
$a = new FactoryMuffin();
parent::setUp();
}
}
当我将鼠标悬停在新的FactoryMuffin对象实例上时,它表示找不到其声明。
如果我将鼠标悬停在Facade上:
use League\FactoryMuffin\Facade;
说
未定义的类Facade
以及悬停时:
use League\FactoryMuffin
说
多种实现
我正在遵循FactoryMuffin文档中列出的所有步骤,我缺少什么?
这是我的作曲家文件:
{
"name": "project/project",
"description": "Main Project Library",
"homepage": "http://www.testproject.com/",
"require": {
"php": ">=5.4",
"zendframework/zendframework": "2.3.9",
"guzzle/guzzle": "~3.7",
"justinrainbow/json-schema": "~1.3",
"mikey179/vfsStream": "v1.2.0",
"mtdowling/cron-expression": "1.0.*",
"minfraud/http": ">=1.60,<2.0",
"davegardnerisme/nsqphp": "dev-master",
"myclabs/deep-copy": "1.3.0",
"maennchen/zipstream-php": "0.3.*",
"corneltek/getoptionkit": "~2",
"firebase/php-jwt": "~3.0",
"symfony/property-access": "~3.0",
"punic/punic": "2.1.*",
"guzzlehttp/guzzle": "^6.3",
"easypost/easypost-php": "^3.4",
"textalk/websocket": "^1.2",
"robmorgan/phinx": "^0.10.6",
"fzaninotto/faker": "^1.8",
"league/factory-muffin": "^3.0",
"league/factory-muffin-faker": "^2.1"
},
"require-dev": {
"phpunit/phpunit": "5.6.*",
"mockery/mockery": "dev-master"
},
"repositories": [],
"autoload": {
"psr-0": {
"DeepCopy": "vendor/myclabs/deep-copy/src"
}
}
}
答案 0 :(得分:0)
https://factory-muffin.thephpleague.com/usage/examples/
尝试用作
use League\FactoryMuffin\Facade as FactoryMuffin;
FactoryMuffin::define('Message', array(
'user_id' => 'factory|User',
'subject' => 'sentence',
'message' => 'text',
'phone_number' => 'randomNumber|8',
'created' => 'date|Ymd h:s',
'slug' => 'call|makeSlug|word',
), function ($object, $saved) {
// we're taking advantage of the callback functionality here
$object->message .= '!';
});