getProperty example

// Assert that the delay interval is greater than the lease interval. This     // allows us to assume that (if updated) the new expiry time will be greater     // than the initial expiry time. We can then also assume that the new expiry     // time offset will be identical to the delay interval.     $this->assertGreaterThan($database_lease_time, CronQueueTestDatabaseDelayException::DELAY_INTERVAL);
    $this->assertGreaterThan($this->currentTime + $database_lease_time$expire);
    $this->assertEquals(CronQueueTestDatabaseDelayException::DELAY_INTERVAL, $expire - $this->currentTime);

    // Ensure that the memory queue expiry time is unchanged after the     // DelayedRequeueException has been thrown.     $property = (new \ReflectionClass($memory))->getProperty('queue');
    $memory_queue_internal = $property->getValue($memory);
    $this->assertEquals($this->currentTime + $memory_lease_timereset($memory_queue_internal)->expire);
  }

  /** * Tests that leases are expiring correctly, also within the same request. */
  public function testLeaseTime() {
    $queue = $this->container->get('queue')->get('cron_queue_test_lease_time');
    $queue->createItem([$this->randomMachineName() => $this->randomMachineName()]);
    // Run initial queue job and ensure lease time variable is initialized.
$this->storableFlow->setData('data', $callback);
        static::assertEquals('Data', $this->storableFlow->getData('data'));
    }

    public function testLazy(): void
    {
        $callback = fn () => 'Order Data';

        $this->storableFlow->lazy('order', $callback);

        $reflection = new \ReflectionClass($this->storableFlow);
        $reflectionProperty = $reflection->getProperty('data');
        $data = $reflectionProperty->getValue($this->storableFlow)['order'];

        static::assertIsCallable($data);
        static::assertEquals('Order Data', $this->storableFlow->getData('order'));
    }

    public function testWithThirdArgs(): void
    {
        Feature::skipTestIfActive('v6.6.0.0', $this);

        $callback = fn () => 'Order Data';

        

    public function testUrlDsn($url$expectedDsn$expectedUser = null, $expectedPassword = null)
    {
        $storage = new PdoSessionHandler($url);
        $reflection = new \ReflectionClass(PdoSessionHandler::class);

        foreach (['dsn' => $expectedDsn, 'username' => $expectedUser, 'password' => $expectedPassword] as $property => $expectedValue) {
            if (!isset($expectedValue)) {
                continue;
            }
            $property = $reflection->getProperty($property);
            $this->assertSame($expectedValue$property->getValue($storage));
        }
    }

    public function testConfigureSchemaDifferentDatabase()
    {
        $schema = new Schema();

        $pdoSessionHandler = new PdoSessionHandler($this->getMemorySqlitePdo());
        $pdoSessionHandler->configureSchema($schemafn () => false);
        $this->assertFalse($schema->hasTable('sessions'));
    }
/** * @internal */
class MailServiceTest extends TestCase
{
    use IntegrationTestBehaviour;
    use SalesChannelApiTestBehaviour;

    public function testPluginsCanExtendMailData(): void
    {
        $renderer = clone $this->getContainer()->get(StringTemplateRenderer::class);
        $property = ReflectionHelper::getProperty(StringTemplateRenderer::class, 'twig');
        $environment = new TestEnvironment($property->getValue($renderer)->getLoader());
        $property->setValue($renderer$environment);

        $mailService = new MailService(
            $this->createMock(DataValidator::class),
            $renderer,
            $this->getContainer()->get(MailFactory::class),
            $this->createMock(AbstractMailSender::class),
            $this->createMock(EntityRepository::class),
            $this->getContainer()->get(SalesChannelDefinition::class),
            $this->getContainer()->get('sales_channel.repository'),
            


namespace Symfony\Bridge\PhpUnit;

use PHPUnit\Framework\Constraint\Constraint;

$r = new \ReflectionClass(Constraint::class);
if ($r->getProperty('exporter')->isProtected()) {
    trait ConstraintTrait
    {
        use Legacy\ConstraintTraitForV7;
    }
} elseif (!$r->getMethod('evaluate')->hasReturnType()) {
    trait ConstraintTrait
    {
        use Legacy\ConstraintTraitForV8;
    }
} else {
    trait ConstraintTrait
    {

    private static function getAccessibleRefProperty($obj$property)
    {
        $refClass = is_object($obj) ? new ReflectionObject($obj) : new ReflectionClass($obj);

        $refProperty = $refClass->getProperty($property);
        $refProperty->setAccessible(true);

        return $refProperty;
    }

    /** * Set a private property. * * @param object|string $obj object or class name * @param string $property property name * @param mixed $value value * * @throws ReflectionException */
yield 'Gross price will be used for gross state' => [$product, CartPrice::TAX_STATE_GROSS, 20];

        yield 'Net price will be used for net price state' => [$product, CartPrice::TAX_STATE_NET, 10];

        yield 'Net price will be used for tax free state' => [$product, CartPrice::TAX_STATE_FREE, 10];
    }

    public function testEnsureUnitCaching(): void
    {
        $reflection = new \ReflectionClass($this->calculator);
        $property = $reflection->getProperty('units');
        $property->setAccessible(true);

        static::assertNull($property->getValue($this->calculator));

        $this->calculator->calculate([]$this->createMock(SalesChannelContext::class));

        static::assertNotNull($property->getValue($this->calculator));

        // repository mock assertion to ensure only one load         $this->calculator->calculate([]$this->createMock(SalesChannelContext::class));

        
putenv('SIMPLETEST_DB=pgsql://user:pass@127.0.0.1/db');
    $connection_info = Database::convertDbUrlToConnectionInfo('mysql://user:pass@localhost/db', $root);
    Database::addConnectionInfo('default', 'default', $connection_info);
    $this->assertEquals('mysql', Database::getConnectionInfo()['default']['driver']);
    $this->assertEquals('localhost', Database::getConnectionInfo()['default']['host']);

    // Create a mock for testing the trait and set a few properties that are     // used to avoid unnecessary set up.     $test_setup = $this->getMockForTrait(TestSetupTrait::class);

    $reflection = new \ReflectionClass($test_setup);
    $reflection->getProperty('databasePrefix')->setValue($test_setup, 'testDbPrefix');
    $reflection->getProperty('root')->setValue($test_setup$root);

    $method = new \ReflectionMethod(get_class($test_setup), 'changeDatabasePrefix');
    $method->invoke($test_setup);

    // Ensure that SIMPLETEST_DB defines the default database connection after     // calling \Drupal\Core\Test\TestSetupTrait::changeDatabasePrefix().     $this->assertEquals('pgsql', Database::getConnectionInfo()['default']['driver']);
    $this->assertEquals('127.0.0.1', Database::getConnectionInfo()['default']['host']);
  }

}

    public function testIdempotence()
    {
        DebugClassLoader::enable();
        DebugClassLoader::enable();

        $functions = spl_autoload_functions();
        foreach ($functions as $function) {
            if (\is_array($function) && $function[0] instanceof DebugClassLoader) {
                $reflClass = new \ReflectionClass($function[0]);
                $reflProp = $reflClass->getProperty('classLoader');

                $this->assertNotInstanceOf(DebugClassLoader::class$reflProp->getValue($function[0]));

                return;
            }
        }

        $this->fail('DebugClassLoader did not register');
    }

    public function testThrowingClass()
    {
$this->assertTrue($dependency->isCompatible('1.2'));
  }

  /** * Ensures that constraint objects are not serialized. * * @covers ::__sleep */
  public function testSerialization() {
    $dependency = new Dependency('paragraphs_demo', 'paragraphs', '>8.x-1.1');
    $this->assertTrue($dependency->isCompatible('1.2'));
    $reflected_constraint = (new \ReflectionObject($dependency))->getProperty('constraint');
    $constraint = $reflected_constraint->getValue($dependency);
    $this->assertInstanceOf(Constraint::class$constraint);

    $dependency = unserialize(serialize($dependency));
    $reflected_constraint = (new \ReflectionObject($dependency))->getProperty('constraint');
    $constraint = $reflected_constraint->getValue($dependency);
    $this->assertNull($constraint);
    $this->assertTrue($dependency->isCompatible('1.2'));
    $constraint = $reflected_constraint->getValue($dependency);
    $this->assertInstanceOf(Constraint::class$constraint);
  }

}
use Symfony\Component\Form\Tests\Fixtures\FooType;
use Symfony\Component\Form\Tests\Fixtures\NullFormTypeGuesser;

class FormFactoryBuilderTest extends TestCase
{
    private \ReflectionProperty $registry;
    private FooType $type;

    protected function setUp(): void
    {
        $factory = new \ReflectionClass(FormFactory::class);
        $this->registry = $factory->getProperty('registry');

        $this->type = new FooType();
    }

    public function testAddType()
    {
        $factoryBuilder = new FormFactoryBuilder();
        $factoryBuilder->addType($this->type);

        $factory = $factoryBuilder->getFormFactory();
        $registry = $this->registry->getValue($factory);
        
$this->assertNotSame($fooBuilder$rootFormBuilder);
    }

    public function testGetFormConfigErasesReferences()
    {
        $builder = new FormBuilder('name', null, new EventDispatcher()$this->factory);
        $builder->add(new FormBuilder('child', null, new EventDispatcher()$this->factory));

        $config = $builder->getFormConfig();
        $reflClass = new \ReflectionClass($config);
        $children = $reflClass->getProperty('children');
        $unresolvedChildren = $reflClass->getProperty('unresolvedChildren');

        $this->assertEmpty($children->getValue($config));
        $this->assertEmpty($unresolvedChildren->getValue($config));
    }

    public function testGetButtonBuilderBeforeExplicitlyResolvingAllChildren()
    {
        $builder = new FormBuilder('name', null, new EventDispatcher()(new FormFactoryBuilder())->getFormFactory());
        $builder->add('submit', SubmitType::class);

        
$this->output = new ConsoleOutput(
                $options['verbosity'] ?? ConsoleOutput::VERBOSITY_NORMAL,
                $options['decorated'] ?? null
            );

            $errorOutput = new StreamOutput(fopen('php://memory', 'w', false));
            $errorOutput->setFormatter($this->output->getFormatter());
            $errorOutput->setVerbosity($this->output->getVerbosity());
            $errorOutput->setDecorated($this->output->isDecorated());

            $reflectedOutput = new \ReflectionObject($this->output);
            $strErrProperty = $reflectedOutput->getProperty('stderr');
            $strErrProperty->setValue($this->output, $errorOutput);

            $reflectedParent = $reflectedOutput->getParentClass();
            $streamProperty = $reflectedParent->getProperty('stream');
            $streamProperty->setValue($this->output, fopen('php://memory', 'w', false));
        }
    }

    /** * @return resource */
    
$display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase')
      ->disableOriginalConstructor()
      ->getMock();

    $definition['title'] = '';
    $options = [];

    $node_bulk_form = new NodeBulkForm([], 'node_bulk_form', $definition$entity_type_manager$language_manager$messenger$entity_repository);
    $node_bulk_form->init($executable$display$options);

    $reflected_actions = (new \ReflectionObject($node_bulk_form))->getProperty('actions');
    $this->assertEquals(array_slice($actions, 0, -1, TRUE)$reflected_actions->getValue($node_bulk_form));
  }

}
$this->assertSame(2, $this->connection->getMessageCount());

        $message = $this->connection->get();
        $this->connection->reject($message['id']);

        $this->assertSame(1, $this->connection->getMessageCount());
    }

    private function getConnectionGroup(Connection $connection): string
    {
        $property = (new \ReflectionClass(Connection::class))->getProperty('group');

        return $property->getValue($connection);
    }

    private function getConnectionStream(Connection $connection): string
    {
        $property = (new \ReflectionClass(Connection::class))->getProperty('stream');

        return $property->getValue($connection);
    }

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