Error: Fatal Error (1): Class 'AppShell' not found in when testing the cake2.x shell with PHPUnit

Asked 1 years ago, Updated 1 years ago, 105 views

I created the shell program app/Console/Command/TestShell.php in cakephp2.x.

The shell itself works, but when I launch the PHPUnit test code from my browser, it turns white and error.log shows the following error:

Error: Fatal Error (1): Class 'AppShell' not found in
Error: [FatalErrorException] Class 'AppShell' not found

The PHPUnit setUp() is written on the Internet without knowing it well, so please let me know if you know anything.

■ Shell Program app/Console/Command/TestShell.php

App::uses('ComponentCollection', 'Controller');
App::uses('TestCommonComponent', 'Controller/Component');
class TestShell extensions AppShell {
    public$uses=array(
        'TestModel 1',
        'TestModel 2'
   );
   public function startup() {
       parent::startup();
   }

    public function main() {

■ PHPUnit
app/Test/Case/Console/Command/TestShellTest.php

<?php
App::uses('ConsoleOutput','Console');
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('Folder', 'Utility');
App::uses('TestShell', 'Console/Command');

class TestShellTest extensions CakeTestCase {
    public$target;
    public function setUp(){
        parent::setUp();

        $output=$this->getMock('ConsoleOutput', array(), array(), '', false);
        $error=$this->getMock('ConsoleOutput', array(), array(), '', false);
        $in = $this->getMock('ConsoleInput', array(), array(), '', false);
        $this->target=new TestShell($output,$error,$in);
        $this->target->initialize();
    }

    public function tearDown(){
        parent::tearDown();
    }

    public function testCommon() {
// Write a test here
        $this->assertEquals(0,0);
    }
}

php cakephp phpunit

2022-09-30 21:32

1 Answers

The PHPUnit is now working by adding App::uses('AppShell', 'Console/Command'); on the shell side.


2022-09-30 21:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.