简体   繁体   中英

How to Phpunit test a method in an abstract class that uses other methods

I have an abstract class as follows:

abstract class Entity
{

  public function __construct($configFile, $logger, $database)
  {
    $this->configFile = $configFile;
    $this->logger = $logger;
    $this->database = $database;
  }


  public function SettingData(array $info)
  {
        $this->logger->debug('setting the information'.serialize($info));
        $info = $info.'debug';
        $this->formatData();
        return true;
    }
}

Here is the unittest:

  $data = array('informations','data');
  $result = Entity::SettingData($data);
  $this->assertTrue($result);

I want to test the method SettingData but I get the error:

Undefined property: Entity::$logger

How Am I supposed to test this method?

Any help is really apreaciated.

You cannot test an abstract class. You have to create a derived class. Then you create an object of that class and call the constructor with testable parameters. After that you can test SettingData.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM