1. Go to this page and download the library: Download vrok/symfony-addons 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/ */
vrok / symfony-addons example snippets
use Vrok\SymfonyAddons\PHPUnit\ApiPlatformTestCase;
class AuthApiTest extends ApiPlatformTestCase
{
public function testAuthRequiresPassword(): void
{
$this->testOperation([
'uri' => '/authentication_token',
'method' => 'POST',
'requestOptions' => ['json' => ['username' => 'fakeuser']],
'responseCode' => 400,
'contentType' => 'application/json',
'json' => [
'type' => 'https://tools.ietf.org/html/rfc2616#section-10',
'title' => 'An error occurred',
'detail' => 'The key "password" must be provided.',
],
]);
}
}
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
use Vrok\SymfonyAddons\PHPUnit\AuthenticatedClientTrait;
class ApiTest extends ApiTestCase
{
use AuthenticatedClientTrait;
public function testAccess(): void
{
$client = static::createAuthenticatedClient([
'email' => TestFixtures::ADMIN['email']
]);
$iri = $this->findIriBy(User::class, ['id' => 1]);
$client->request('GET', $iri);
self::assertResponseIsSuccessful();
}
}
use Monolog\Level;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Vrok\SymfonyAddons\PHPUnit\MonologAssertsTrait;
class LoggerTest extends KernelTestCase
{
use MonologAssertsTrait;
public function testLog(): void
{
self::prepareLogger();
$logger = static::getContainer()->get(LoggerInterface::class);
$logger->error('Failed to do something');
self::assertLoggerHasMessage('Failed to do something', Level::Error);
}
}
public function __invoke(
Entity $data
WorkflowInterface $entityStateMachine,
): array
{
$result = $data->toArray();
$result['transitions'] = WorkflowHelper::getTransitionList($data, $entityStateMachine);
return $result;
}