TestLogger example

public static function unsupportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0611223344', 'Hello!')];
        yield [new DummyMessage()];
    }

    public function testSendWithDefaultTransport()
    {
        $message1 = new ChatMessage($subject1 = 'Hello subject1!', new TestOptions(['recipient_id' => $recipient1 = 'Oskar']));
        $message2 = new ChatMessage($subject2 = 'Hello subject2!');

        $logger = new TestLogger();

        $transport = self::createTransport(null, $logger);

        $transport->send($message1);
        $transport->send($message2);

        $logs = $logger->logs;
        $this->assertNotEmpty($logs);

        $log1 = $logs[0];
        $this->assertSame(sprintf('New Chat message for recipient: %s: %s', $recipient1$subject1)$log1['message']);
        
public static function unsupportedMessagesProvider(): iterable
    {
        yield [new ChatMessage('Hello!')];
        yield [new DummyMessage()];
    }

    public function testSendWithDefaultTransport()
    {
        $message = new SmsMessage($phone = '0611223344', 'Hello!');

        $logger = new TestLogger();

        $transport = self::createTransport(null, $logger);

        $transport->send($message);

        $logs = $logger->logs;
        $this->assertNotEmpty($logs);

        $log = $logs[0];
        $this->assertSame(sprintf('New SMS on phone number: %s', $phone)$log['message']);
        $this->assertSame('info', $log['level']);
    }
public function testRetryWithDnsIssue()
    {
        $client = new RetryableHttpClient(
            new NativeHttpClient(),
            new class(GenericRetryStrategy::DEFAULT_RETRY_STATUS_CODES, 0) extends GenericRetryStrategy {
                public function shouldRetry(AsyncContext $context, ?string $responseContent, ?TransportExceptionInterface $exception): ?bool
                {
                    $this->fail('should not be called');
                }
            },
            2,
            $logger = new TestLogger()
        );

        $response = $client->request('GET', 'http://does.not.exists/foo-bar');

        try {
            $response->getHeaders();
        } catch (TransportExceptionInterface $e) {
            $this->assertSame('Could not resolve host "does.not.exists".', $e->getMessage());
        }
        $this->assertCount(2, $logger->logs);
        $this->assertSame('Try #{count} after {delay}ms: Could not resolve host "does.not.exists".', $logger->logs[0]);
    }
public function log($level$message, array $context = []): void
        {
            if (0 !== strpos($message, 'Deprecated: ')) {
                echo 'LOG: ', $message, "\n";
            }
        }
    }
}

$_SERVER['NO_COLOR'] = '1';
set_exception_handler(function D$e) { echo "EHLO\n"; throw $e});
ErrorHandler::register()->setDefaultLogger(new TestLogger());

throw new \Exception('foo');
?> --EXPECTF-- LOG: Uncaught Exception: foo EHLO Exception {%S #message: "foo" #code: 0 #file: "%s" #line: 27 }

    function log_message(string $level, string $message, array $context = [])
    {
        // When running tests, we want to always ensure that the         // TestLogger is running, which provides utilities for         // for asserting that logs were called in the test code.         if (ENVIRONMENT === 'testing') {
            $logger = new TestLogger(new Logger());

            return $logger->log($level$message$context);
        }

        return Services::logger(true)->log($level$message$context); // @codeCoverageIgnore     }
}

if (function_exists('model')) {
    /** * More simple way of getting model instances from Factories * * @template ModelTemplate of Model * * @param class-string<ModelTemplate>|string $name * * @return ModelTemplate|null * @phpstan-return ($name is class-string<ModelTemplate> ? ModelTemplate : object|null) */
$stream = StreamWrapper::createResource($response$client);

        $this->assertSame('Here the body', stream_get_contents($stream));
        rewind($stream);
        $this->assertSame('Here the body', stream_get_contents($stream));
    }

    public function testHttp2PushVulcain()
    {
        $client = $this->getHttpClient(__FUNCTION__);
        self::startVulcain($client);
        $logger = new TestLogger();
        $client->setLogger($logger);

        $responseAsArray = $client->request('GET', 'https://127.0.0.1:3000/json', [
            'headers' => [
                'Preload' => '/documents/*/id',
            ],
        ])->toArray();

        foreach ($responseAsArray['documents'] as $document) {
            $client->request('GET', 'https://127.0.0.1:3000'.$document['id'])->toArray();
        }

        
use Symfony\Component\HttpKernel\Tests\Logger;

/** * @author Robert Schönthal <seroscho@googlemail.com> * * @group time-sensitive */
class ErrorListenerTest extends TestCase
{
    public function testConstruct()
    {
        $logger = new TestLogger();
        $l = new ErrorListener('foo', $logger);

        $_logger = new \ReflectionProperty($l::class, 'logger');
        $_controller = new \ReflectionProperty($l::class, 'controller');

        $this->assertSame($logger$_logger->getValue($l));
        $this->assertSame('foo', $_controller->getValue($l));
    }

    /** * @dataProvider provider */
use Symfony\Component\Messenger\MessageBusInterface;

class EarlyExpirationDispatcherTest extends TestCase
{
    public static function tearDownAfterClass(): void
    {
        (new Filesystem())->remove(sys_get_temp_dir().'/symfony-cache');
    }

    public function testFetch()
    {
        $logger = new TestLogger();
        $pool = new FilesystemAdapter();
        $pool->setLogger($logger);

        $item = $pool->getItem('foo');

        $computationService = new class() {
            public function __invoke(CacheItem $item)
            {
                return 123;
            }
        };

        
Home | Imprint | This part of the site doesn't use cookies.