PHP code example of speicher210 / functional-test-bundle
1. Go to this page and download the library: Download speicher210/functional-test-bundle 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/ */
speicher210 / functional-test-bundle example snippets
// tests/bootstrap.php
declare(strict_types=1);
use Symfony\Component\Dotenv\Dotenv;
eicher210/functional-test-bundle/src/Test/bootstrap.php';
// Only needed when using WebTestCase::getRequestUploadLargeFile() (
use PHPUnit\Framework\ExpectationFailedException;
use Speicher210\FunctionalTestBundle\SnapshotUpdater;
use Speicher210\FunctionalTestBundle\SnapshotUpdater\DriverConfigurator;
protected function assertCsvExportMatchesExpected(string $actualCsv): void
{
// Next expected file of the test: Expected/<test>-<n>.csv
$expectedFile = $this->getExpectedContentFile('csv');
try {
self::assertStringEqualsFile($expectedFile, $actualCsv);
} catch (ExpectationFailedException $e) {
$comparisonFailure = $e->getComparisonFailure();
if ($comparisonFailure !== null && DriverConfigurator::isOutputUpdaterEnabled()) {
SnapshotUpdater::updateText($comparisonFailure, $expectedFile);
}
throw $e;
}
}
declare(strict_types=1);
namespace App\Tests\Controller;
use App\Tests\Fixtures\Loader\LoadOneUser;
use Speicher210\FunctionalTestBundle\Attribute\WithFixture;
use Speicher210\FunctionalTestBundle\Test\RestControllerWebTestCase;
use Symfony\Component\HttpFoundation\Request;
#[WithFixture(LoadOneUser::class)]
final class UserControllerTest extends RestControllerWebTestCase
{
public function testReturns404IfUserIsNotFound(): void
{
$this->assertRestRequestReturns404('/api/users/999', Request::METHOD_GET);
}
public function testReturnsUser(): void
{
$this->assertRestGetPath('/api/users/1');
}
public function testUpdatesUser(): void
{
self::loginAsAdmin();
$this->assertRestPatchPath('/api/users/1', ['firstName' => 'Jane']);
$this->assertRestGetPath('/api/users/1');
}
}
declare(strict_types=1);
namespace App\Tests\Fixtures\Loader;
use App\Entity\User;
use Generator;
use Override;
use Speicher210\FunctionalTestBundle\Test\Loader\AbstractLoader;
final class LoadOneUser extends AbstractLoader
{
#[Override]
protected function doLoad(): Generator
{
yield new User(1, 'John', 'Doe');
}
}
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
#[AllowMockObjectsWithoutExpectations]
final class MyFormTypeTest extends FormTypeTestCase
{
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.