PaymentStatusTest.php in Payment 8.2
File
tests/src/Unit/Entity/PaymentStatusTest.php
View source
<?php
namespace Drupal\Tests\payment\Unit\Entity;
use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\payment\Entity\PaymentStatus;
use Drupal\Tests\UnitTestCase;
class PaymentStatusTest extends UnitTestCase {
protected $entityTypeManager;
protected $entityTypeId;
protected $sut;
protected $typedConfigManager;
public function setUp() : void {
$this->entityTypeManager = $this
->createMock(EntityTypeManagerInterface::class);
$this->entityTypeId = $this
->randomMachineName();
$this->typedConfigManager = $this
->createMock(TypedConfigManagerInterface::class);
$this->sut = new PaymentStatus([], $this->entityTypeId);
$this->sut
->setEntityTypeManager($this->entityTypeManager);
$this->sut
->setTypedConfig($this->typedConfigManager);
}
public function testId() {
$id = strtolower($this
->randomMachineName());
$this
->assertSame($this->sut, $this->sut
->setId($id));
$this
->assertSame($id, $this->sut
->id());
}
public function testLabel() {
$entity_type = $this
->createMock(ConfigEntityTypeInterface::class);
$entity_type
->expects($this
->atLeastOnce())
->method('getKey')
->with('label')
->willReturn('label');
$this->entityTypeManager
->expects($this
->atLeastOnce())
->method('getDefinition')
->with($this->entityTypeId)
->willReturn($entity_type);
$label = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setLabel($label));
$this
->assertSame($label, $this->sut
->label());
}
public function testGetParentId() {
$id = strtolower($this
->randomMachineName());
$this
->assertSame($this->sut, $this->sut
->setParentId($id));
$this
->assertSame($id, $this->sut
->getParentId());
}
public function testGetDescription() {
$description = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setDescription($description));
$this
->assertSame($description, $this->sut
->getDescription());
}
public function testEntityTypeManager() {
$method = new \ReflectionMethod($this->sut, 'entityTypeManager');
$method
->setAccessible(TRUE);
$this
->assertSame($this->entityTypeManager, $method
->invoke($this->sut));
}
public function testGetTypedConfig() {
$method = new \ReflectionMethod($this->sut, 'getTypedConfig');
$method
->setAccessible(TRUE);
$this
->assertSame($this->typedConfigManager, $method
->invoke($this->sut));
}
}