It's my first time with kernel tests.
I'm working with this test:
<?php
namespace Drupal\Tests\info_irpf_calculator\Kernel;
use Drupal\info_irpf_calculator\Model\IrpfUserData;
use Drupal\info_irpf_calculator\Model\IrpfUserDataInterface;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the IRPF calculator.
*
* @group info_irpf_calculator
*
* @coversDefaultClass \Drupal\info_irpf_calculator\IrpfCalculator
*/
class IrpfCalculatorTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['info_irpf_calculator'];
/**
* The IRPF calculator service.
*
* @var \Drupal\info_irpf_calculator\IrpfCalculatorInterface
*/
protected $irpfCalculator;
/**
* The IRPF specific values plugin manager.
*
* @var \Drupal\info_irpf_calculator\Plugin\IrpfSpecificValuesManagerInterface
*/
protected $irpfSpecificValuesManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->irpfCalculator = $this->container->get('info_irpf_calculator.calculator');
$this->irpfSpecificValuesManager = $this->container->get('plugin.manager.irpf_specific_values');
}
/**
* Test values.
*
* @covers \Drupal\info_irpf_calculator\IrpfCalculator::getValues
*/
public function testGetValues() {
$user_data = new IrpfUserData([
'age' => 50,
'annual_income' => 12000.00,
'is_pension' => FALSE,
'declaration_type' => IrpfUserDataInterface::DECLARATION_TYPE_INDIVIDUAL,
'single_parent' => FALSE,
'descendant' => 2,
'descendant_under_3' => 1,
]);
$values = $this->irpfCalculator->getValues($user_data);
$regions = count($this->irpfSpecificValuesManager->getDefinitions());
$this->assertCount($regions, $values);
}
}
When I run it: vendor/bin/phpunit --filter IrpfCalculatorTest
It give me back this error:
There was 1 error:
1) Drupal\Tests\info_irpf_calculator\Kernel\IrpfCalculatorTest::testGetValues
Error: Call to a member function get() on null
/var/www/html/web/modules/custom/info_irpf_calculator/src/Plugin/IrpfSpecificValues/AndalusiaIrpfSpecificValues.php:55
/var/www/html/web/modules/custom/info_irpf_calculator/src/Plugin/IrpfSpecificValues/IrpfSpecificValues.php:75
/var/www/html/web/modules/custom/info_irpf_calculator/src/IrpfCalculator.php:46
/var/www/html/web/modules/custom/info_irpf_calculator/tests/src/Kernel/IrpfCalculatorTest.php:63
The line in AndalusiaIrpfSpecificValues.php is:
protected function getMinPersonal(IrpfUserDataInterface $user_data) {
$elements = $this->taxValues->get('get_min_personal_fieldset');
$value = $this->getMinPersonalTrait($elements, $user_data);
return $value;
}
$this->taxValues comes from the construct:
$this->taxValues = $this->entityTypeManager->getStorage('info_irpf_tax_values')->load(self::NAME);
The problem is that when I run the test the class doesn't load the configuration, but I use the website it works fine.
How can I make to load the configuration when I run the test?
Thanks.