PHP code example of digitalrevolution / phpunit-extensions
1. Go to this page and download the library: Download digitalrevolution/phpunit-extensions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digitalrevolution / phpunit-extensions example snippets
use DR\PHPUnitExtensions\Symfony\AbstractControllerTestCase;
class MyControllerTest extends AbstractControllerTestCase
{
public function myTest(): void
{
$this->expectDenyAccessUnlessGranted('attribute', null, true);
$this->expectGetUser(new User());
$this->expectCreateForm(TextType::class);
($this->controller)();
}
public function getController() {
return new MyController();
}
}
use DR\PHPUnitExtensions\Symfony\AbstractConstraintValidatorTestCase;
class MyConstraintValidatorTest extends AbstractConstraintValidatorTestCase
{
public function testValidate(): void
{
$this->expectBuildViolation($constraint->message, ['parameter' => 123])
->expectSetCode(789)
->expectAtPath('path')
->expectAddViolation();
$this->validator->validate(123, $this->constraint);
}
protected function getValidator(): ConstraintValidator
{
return new MyConstraintValidator();
}
protected function getConstraint(): Constraint
{
return new MyConstraint();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.