Hi community, I’m new here and with yii2
I created the test/console suite and can execute it whith the command
vendor/bin/codecept run console tests/console/ExampleConsoleTest.php
but, as showed below, I’m facing some problems with the ConsoleTest actor…
Can somebody give me a hand, please?
Best regards.
This is my test class
<?php
namespace console;
use ConsoleTester;
class ExampleConsoleTest extends \Codeception\Test\Unit
{
protected ConsoleTester $tester;
protected function _before()
{
}
// tests
public function testExampleConsole_Index()
{
// Run the console command
//whitout use $this->tester the test is runned without error
//$result = $this->tester->runShellCommand('yii example-console/index "testmessageGGG"');
//$this->tester->seeInShellOutput('####### Command!!! public function actionIndex($args) {....');
}
public function testHelloConsole_DefaultMessage()
{
//this test is runned with error
// Run the command without arguments
$this->tester->runShellCommand('yii hello/index');
// Check for the default output
$this->tester->seeInShellOutput('hello world');
}
}
root@1c65d1624d6b:/var/www/html/odin2webYii2# vendor/bin/codecept run console tests/console/ExampleConsoleTest.php
Failed loading /usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so: cannot open shared object file: No such file or directory
[284] Log opened at 2024-09-20 14:38:11.396308
[284] [Config] INFO: Control socket set up succesfully: '@xdebug-ctrl.284'
[284] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[284] [Step Debug] WARN: Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).
[284] [Step Debug] ERR: Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port).
Codeception PHP Testing Framework v5.1.2 https://stand-with-ukraine.pp.ua
Console Tests (2) ----------------------------------------------------------------------------------------------------------------------------------------------------------------
✔ ExampleConsoleTest: Example console_index(0.12s)
E ExampleConsoleTest: Hello console_default message(0.17s)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 00:01.644, Memory: 16.00 MB
There was 1 error:
1) ExampleConsoleTest: Hello console_default message
Test tests/console/ExampleConsoleTest.php:testHelloConsole_DefaultMessage
[RuntimeException] Call to undefined method ConsoleTester::runShellCommand
#1 /var/www/html/odin2webYii2/tests/console/ExampleConsoleTest.php:33
#2 /var/www/html/odin2webYii2/vendor/bin/codecept:119
ERRORS!
Tests: 2, Assertions: 0, Errors: 1.
My codeception.yml
actor: Tester
bootstrap: _bootstrap.php
paths:
tests: tests
output: tests/_output
data: tests/_data
helpers: tests/_support
settings:
memory_limit: 1024M
colors: true
modules:
config:
Yii2:
configFile: 'config/test.php'
my console.suite.yml
actor: ConsoleTester
suite_namespace: \console
modules:
# enable helpers as array
enabled:
- Asserts
- Yii2:
part: [console]
#- \Helper\Console # Module \Helper\Console could not be found and loaded