Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

How load more then one class from file?

未关闭
#183 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
php
领域
testing-qa

调研方向

从 bootstrap.php 的设置以及针对 CComponent.php、CModel.php、CFormModel.php 和 ConfirmForm.php 的 Kernel::loadFile 调用开始。重现缺失的 CFormModel 和 CEvent locator 错误,然后检查包含多个类的文件是如何被发现和加载的。当类似 CComponent.php 这样的文件能够在不出现这些错误的情况下向 locator 提供其中的所有类时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

I just try to test my Yii App with AspectMock and Codeception.
My bootstrap.php:

include __DIR__.'/../vendor/autoload.php'; // composer autoload
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
    'debug' => true,
    'appDir'     => __DIR__ . '/..',
    'includePaths' => [
        __DIR__.'/../src',
    ],
    'cacheDir'   => __DIR__ . '/temp/aspectMock',
    'excludePaths ' => [__DIR__],
]);

I use it:

\AspectMock\Test::double(\TestForm::class, [
    'validate' => false,
]);
$a = new \TestForm();
$a->prop = 123;
$I->assertEquals(false, $a->validate());

\AspectMock\Test::double(\TestForm::class, [
    'validate' => true,
]);
$a = new \TestForm();
$a->prop = 123;
$I->assertEquals(true, $a->validate());

But AspectMock doesn't replace method validate.

I add into bootstap this:

include __DIR__.'/../vendor/autoload.php'; // composer autoload
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
    'debug' => true,
    'appDir'     => __DIR__ . '/..',
    'includePaths' => [
        __DIR__.'/../src',
    ],
    'cacheDir'   => __DIR__ . '/temp/aspectMock',
    'excludePaths ' => [__DIR__],
]);

$kernel->loadFile(__DIR__ . '/../public/protected/models/ConfirmForm.php');

But now I see Error: "Class CFormModel was not found by locator"
CFormModel it's parent of my TestForm.
And I do this:

$kernel->loadFile(__DIR__ . '/../vendor/yiisoft/yii/framework/base/CComponent.php');
$kernel->loadFile(__DIR__ . '/../vendor/yiisoft/yii/framework/base/CModel.php');
$kernel->loadFile(__DIR__ . '/../vendor/yiisoft/yii/framework/web/CFormModel.php');
$kernel->loadFile(__DIR__ . '/../public/protected/models/ConfirmForm.php');

And I see error "Class CEvent was not found by locator". But class CEvent exists in CComponent.php.

In file CComponent have more then one class. And its a problem, I think.

I cant do anything with it?

Can AspectMock load more then one class from file?

主要语言
PHP
星标
784
派生
132
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Codeception/AspectMock 的其他 Issue

查看 Codeception/AspectMock 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。