I would like to write a UnitTest in CakePHP 3.2 for a Component with parameters, but the CakePHP-Docs says nothing about how to do so (http://book.cakephp.org/3.0/en/development/testing.html#testing-components).
I assume that I have to pass the necessary parameters in the testInitializing()
method:
/**
* Test subject
*
* @var \App\Controller\Component\Bandit\EpsilonGreedyComponent
*/
public $EpsilonGreedy;
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
$registry = new ComponentRegistry();
$this->EpsilonGreedy = new EpsilonGreedyComponent($registry);
}
/**
* Test initial setup
*
* @return void
*/
public function testInitialization()
{
$config['epsilon'] = 0.1;
$config['arrViews'] = array('1', '2', '3');
$config['arrInteractions'] = array('1', '2', '3');
}
The Test fails because the parameters are unknown to the UnitTest.
Does anyone know how to pass the parameters?
In the Component I save the paramters like the following:
`public function initialize(array $config)
{
parent::initialize($config);
$this->setEpsilon($config['epsilon']);
$this->setArrViews($config['arrViews']);
$this->setArrInteractions($config['arrInteractions']);
}`