withClockMock example

            if ($this->willBeIsolated($test)) {
                $this->runsInSeparateProcess = tempnam(sys_get_temp_dir(), 'deprec');
                putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$this->runsInSeparateProcess);
                putenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE='.tempnam(sys_get_temp_dir(), 'expectdeprec'));
            }

            $groups = Test::getGroups(\get_class($test)$test->getName(false));

            if (!$this->runsInSeparateProcess) {
                if (\in_array('time-sensitive', $groups, true)) {
                    ClockMock::register(\get_class($test));
                    ClockMock::withClockMock(true);
                }
                if (\in_array('dns-sensitive', $groups, true)) {
                    DnsMock::register(\get_class($test));
                }
            }

            if (!$test->getTestResultObject()) {
                return;
            }

            $annotations = Test::parseTestMethodAnnotations(\get_class($test)$test->getName(false));

            
private Connection $conn;
    private ?Stopwatch $stopwatch;

    protected function setUp(): void
    {
        parent::setUp();

        if (!interface_exists(MiddlewareInterface::class)) {
            $this->markTestSkipped(sprintf('%s needed to run this test', MiddlewareInterface::class));
        }

        ClockMock::withClockMock(false);
    }

    private function init(bool $withStopwatch = true): void
    {
        $this->stopwatch = $withStopwatch ? new Stopwatch() : null;

        $config = ORMSetup::createConfiguration(true);
        if (class_exists(DefaultSchemaManagerFactory::class)) {
            $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
        }
        $config->setLazyGhostObjectEnabled(true);
        

        $window = new SlidingWindow('foo', 10);

        usleep(9.5 * 1e6);
        // should be 500ms left (10 - 9.5)         $this->assertEqualsWithDelta(0.5, $window->getRetryAfter()->format('U.u') - microtime(true), 0.2);
    }

    public function testCreateAtExactTime()
    {
        ClockMock::register(SlidingWindow::class);
        ClockMock::withClockMock(1234567890.000000);
        $window = new SlidingWindow('foo', 10);
        $window->getRetryAfter();
        $this->assertEquals('1234567900.000000', $window->getRetryAfter()->format('U.u'));
    }
}
/** * @internal * * @covers \Shopware\Core\Profiling\Doctrine\ConnectionProfiler * * @group time-sensitive */
class ConnectionProfilerTest extends TestCase
{
    protected function setUp(): void
    {
        ClockMock::withClockMock(1500000000);
    }

    public function testCollectConnections(): void
    {
        $c = $this->createCollector([]);
        $c->lateCollect();
        $c = unserialize(serialize($c));
        static::assertEquals(['default']$c->getConnections());
    }

    public function testCollectQueryCount(): void
    {
EOF;

    /** * @dataProvider getSignData */
    public function testSign(int $time, string $bodyCanon, string $headerCanon, string $header)
    {
        ClockMock::withClockMock($time);

        $message = (new Email())
            ->from(new Address('fabien@testdkim.symfony.net', 'Fabién'))
            ->to('fabien.potencier@gmail.com')
            ->subject('Tést')
            ->text("Some body \n \n This \r\n\r\n is really interesting and at the same time very long line to see if everything works as expected, does it?\r\n\r\n\r\n\r\n")
            ->date(new \DateTimeImmutable('2005-10-15', new \DateTimeZone('Europe/Paris')));

        $signer = new DkimSigner(self::$pk, 'testdkim.symfony.net', 'sf');
        $signedMessage = $signer->sign($message[
            'header_canon' => $headerCanon,
            
// Doctrine DBAL 2 compatibility class_exists(\Doctrine\DBAL\Platforms\MySqlPlatform::class);

class DoctrineDataCollectorTest extends TestCase
{
    use DoctrineDataCollectorTestTrait;

    protected function setUp(): void
    {
        ClockMock::register(self::class);
        ClockMock::withClockMock(1500000000);
    }

    public function testReset()
    {
        $queries = [
            ['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 1],
        ];
        $c = $this->createCollector($queries);
        $c->collect(new Request()new Response());

        $c->reset();
        

class ClockMockTest extends TestCase
{
    public static function setUpBeforeClass(): void
    {
        ClockMock::register(__CLASS__);
    }

    protected function setUp(): void
    {
        ClockMock::withClockMock(1234567890.125);
    }

    public function testTime()
    {
        $this->assertSame(1234567890, time());
    }

    public function testSleep()
    {
        sleep(2);
        $this->assertSame(1234567892, time());
    }
Home | Imprint | This part of the site doesn't use cookies.