public function DeploymentValidationTest::testValidation in Build Hooks 3.x
Same name and namespace in other branches
- 8.2 tests/src/Kernel/DeploymentValidationTest.php \Drupal\Tests\build_hooks\Kernel\DeploymentValidationTest::testValidation()
 
Tests validation constraint.
File
- tests/
src/ Kernel/ DeploymentValidationTest.php, line 28  
Class
- DeploymentValidationTest
 - Defines a class for testing validation constraints for deployment entities.
 
Namespace
Drupal\Tests\build_hooks\KernelCode
public function testValidation() {
  \Drupal::entityTypeManager()
    ->getStorage('build_hooks_deployment')
    ->getOrCreateNextDeploymentForEnvironment($this->environment);
  /** @var \Drupal\build_hooks\Entity\Deployment $another */
  $another = Deployment::create([
    'label' => $this
      ->randomMachineName(),
    'environment' => [
      'target_id' => $this->environment
        ->id(),
    ],
    'status' => 0,
  ]);
  /** @var \Drupal\Core\Entity\EntityConstraintViolationList $errors */
  $errors = $another
    ->validate();
  $this
    ->assertCount(1, $errors);
  $this
    ->assertRegExp('/There is already an active deployment for this environment/', (string) $errors[0]
    ->getMessage());
  $this
    ->assertEquals('status', $errors[0]
    ->getPropertyPath());
}