duanfangbunao36970 2019-05-14 23:12
浏览 393

php - 如何使用通过composer安装的包

I've installed FactoryMuffin via composer. After installation, I ran composer dump-autload just to make sure I was using the latest stuff.

Now, when I try to use in my code something from the package I installed I can't. For instance:

use League\FactoryMuffin\Facade;

class APITest extends Sw_Test_PHPUnit_LibraryTestCase
{

    public function setUp()
    {
        $a = new FactoryMuffin();

        parent::setUp();
    }
}

When I hover over the new FactoryMuffin object instantiation, it says it cannot find its declaration.

If I hover over Facade in:

use League\FactoryMuffin\Facade;

it says

Undefined class Facade

and when hovering over:

use League\FactoryMuffin

it says

multiple implementations

I'm following all the steps listed in the documentation for FactoryMuffin, what am I missing?

Here's my composer file:

{
    "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"
        }
    }
}

  • 写回答

1条回答 默认 最新

  • douzheren3349 2019-05-14 23:24
    关注

    https://factory-muffin.thephpleague.com/usage/examples/

    Try using as

    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 .= '!';
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。