<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cornermonkey / phpunit-conditional-assertions example snippets
use CornerMonkey\ConditionalAssertion\ConditionalAssertionTrait;
use PHPUnit\Framework\TestCase;
class MyTestCase extends TestCase
{
use ConditionalAssertionTrait;
public function testConditionIsValid()
{
$this->when(true)->assertThat(true, true);
$this->when(false)->assertThat(true, true); // This assertion will not be called
$this->unless(true)->assertThat(true, true); // This assertion will not be called
$this->unless(false)->assertThat(true, true);
}
}
use CornerMonkey\ConditionalAssertion\ConditionalAssertionTrait;
use PHPUnit\Framework\TestCase;
class MyTestCase extends TestCase
{
use ConditionalAssertionTrait;
public function dataProvider()
{
return [
[true],
[false]
];
}
/**
* @dataProvider dataProvider
*/
public function testIfExceptionShouldBeThrown($shouldThrow)
{
$this->when($shouldThrow, function(TestCase $testCase, $value) {
$testCase->expectException(Exception::class);
});
if ($shouldThrow) {
throw new Exception();
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.