I'm new to OOP concepts, also PHPUnit Testing is new for me. I want to get the configuration in my testcase.
XYZFormResult.php
namespace Drupal\xyz\XYZFormResult;
use Drupal\Core\Config\ConfigFactory;
use Drupal\webform\Entity\WebformSubmission;
/**
* Class XYZFormResult.
*
* @package Drupal\xyz\formgroup
*/
class XYZFormResult {
/**
* Defines the immutable configuration object.
*
* @var \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig
*/
private $config;
/**
* XYZFormResult constructor.
*
* @param \Drupal\Core\Config\ConfigFactory $config
* Inject ConfigFactory.
*/
public function __construct(ConfigFactory $config) {
$this->config = $config->getEditable('xyz.settings');
}
}
XYZFormTest.php
namespace Drupal\Tests\xyz\Unit\XYZFormTest;
//use Drupal\Core\Config\ConfigFactory;
use Drupal\Tests\UnitTestCase;
use Drupal\xyz\formgroup\FormsGroupResult;
use Drupal\xyz\formgroup\XYZFormResult;
use Drupal\webform\Entity\WebformSubmission;
/**
* @coversDefaultClass \Drupal\xyz\formgroup\FormsGroupResult
* @group xyz
*/
class XYZFormTest extends UnitTestCase {
/**
*
* @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockBuilder
*/
protected $config;
public function testxyz() {
$this->XYZresult = new XYZFormResult($config);
}
}
When I execute this XYZFormTest testcase, I need to pass a parameter for XYZFormResult()
, how to pass config parameter?
If I pass any string in XYZFormResult()
, I'm getting error this error:
__construct() must be an instance of Drupal\Core\Config\ConfigFactory, string given error