endtoend-test-psl/tests/Psl/InvariantTest.php

28 lines
618 B
PHP
Raw Normal View History

2020-07-07 15:17:36 +02:00
<?php
declare(strict_types=1);
namespace Psl\Tests;
use PHPUnit\Framework\TestCase;
use Psl;
use Psl\Exception\InvariantViolationException;
final class InvariantTest extends TestCase
2020-07-07 15:17:36 +02:00
{
public function testInvariant(): void
{
$this->expectException(InvariantViolationException::class);
$this->expectExceptionMessage('Something went wrong!');
Psl\invariant(false, 'Something %s %s!', 'went', 'wrong');
}
public function testInvariantDoesNotThrowWhenTheFactIsTrue(): void
{
Psl\invariant(2 === (1 + 1), 'Unless?');
$this->addToAssertionCount(1);
}
}