AspectMock не мокает объект
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
Research direction
Start with the bootstrap.php setup and the AspectMock::Test::double call for app\modules\api\models\base\Methods. Reproduce the call to Methods::tableName() under the PHP 8.1 and Codeception configuration shown, then compare the returned value with the configured mock expectation. Done means identifying why the mock is not applied and documenting or testing the corrected behavior.
Written by the indexing model from the issue text.
Description
Не мокается обхект тест запускается хорошо но не работает
bootstrap.php
<?php
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_DEBUG') or define('YII_DEBUG', true);
require __DIR__ .'/../vendor/autoload.php';
$kernel = AspectMock\Kernel::getInstance();
$kernel->init([
'debug' => true,
'appDir' => 'app',
'cacheDir' => __DIR__ . '/../runtime/myapp',
'includePaths' => [
__DIR__.'/..'
],
'excludePaths' => [__DIR__]
]);
$kernel->loadFile(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
Yii::setAlias('@tests', dirname(__DIR__));
Yii::setAlias('@app', dirname(dirname(__DIR__)));
сам код
класс который мокаю
<?php
namespace app\modules\api\models\base;
use app\base\db\ActiveRecord;
class Methods extends ActiveRecord
{
static protected $structure = [
'name' => [
'title' => 'Имя',
'type' => 'string',
'identify' => true,
'maxLength' => 255,
],
'description' => [
'title' => 'Описание',
'type' => 'text',
],
];
public static $permanentlyDelete = true;
protected static $hiddable = false;
protected static $modelTitle = 'Методы API';
protected static $recordTitle = 'метод API';
protected static $accusativeRecordTitle = 'метод API';
protected static $readonly = true;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'api_methods';
}
/**
* @inheritdoc
*/
public function rules()
{
return [];
}
}
$methods = \AspectMock\Test::double('app\modules\api\models\base\Methods', [
'tableName' => 34
]);
$n2 = Methods::tableName();
//$methods->verifyInvoked('tableName');
print_r($n2); печатает api_methods вместо 34
exit;
Details
- Codeception version:
- PHP Version: 8.1
- Operating System: windiws
codeception.yml
namespace: Tests
support_namespace: Support
paths:
tests: tests
output: tests/_output
data: tests/Support/Data
support: tests/Support
envs: tests/_envs
settings:
bootstrap: ../_bootstrap.php
error_level: E_ALL & ~E_STRICT & ~E_DEPRECATED
memory_limit: 1024M
colors: true
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Yii2:
configFile: 'config/test-local.php'
cleanup: false
# Codeception Test Suite Configuration
#
# Suite for unit or integration tests.
Unit.suite.yml
actor: UnitTester
modules:
enabled:
- Asserts
- Yii2:
part: [orm]
- Db:
dsn: 'mysql:host=db;dbname=lkp'
user: 'root'
password: 'lkp_dev_passwd'
step_decorators: ~
- Dominant language
- PHP
- Stars
- 784
- Forks
- 130
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Codeception/AspectMock
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
Codeception/AspectMock#208 · 2 comments · 5 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Codeception/AspectMock#203 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
Codeception/AspectMock#202 · 5 comments · 2 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
Codeception/AspectMock#201 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Codeception/AspectMock#196 · 1 comment ·
All issues in Codeception/AspectMock
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
taskforcesh/bullmq#5238 ·
Maintainers usually reply within 1 day
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects itPossibly taken @bfs2021 claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Automattic/jetpack#55517 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
area/import type/enhancement when/later
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day