assertIsObject example

private Environment $environment;

    protected function setUp(): void
    {
        $this->environment = $this->getContainer()->get('shopware.seo_url.twig');
    }

    public function testLoadAdditionalExtension(): void
    {
        // extension loaded via custom tag in src/Core/Framework/DependencyInjection/seo_test.xml         static::assertIsObject($this->environment->getExtension(LastLetterBigTwigFilter::class));

        $template = '{% autoescape \''
            . SeoUrlGenerator::ESCAPE_SLUGIFY
            . '\' %}{{ product.name|lastBigLetter }}{% endautoescape %}';

        $twig = $this->environment->createTemplate($template);
        $rendered = $twig->render(['product' => ['name' => 'hello world']]);

        static::assertSame('hello-worlD', $rendered);
    }
}

  protected function assertCallableController(callable $controller, ?string $class, ?string $output): void {
    if ($class) {
      $this->assertIsObject($controller[0]);
      $this->assertInstanceOf($class$controller[0]);
    }
    $this->assertIsCallable($controller);
    $this->assertSame($outputcall_user_func($controller));
  }

}

class MockController {

  public function getResult() {
    
$builder = new ContainerBuilder();
        $builder->register('bar', 'stdClass');

        $this->assertTrue($builder->get('bar') === $builder->get('bar'), '->get() always returns the same instance if the service is shared');
    }

    public function testGetCreatesServiceBasedOnDefinition()
    {
        $builder = new ContainerBuilder();
        $builder->register('foo', 'stdClass');

        $this->assertIsObject($builder->get('foo'), '->get() returns the service definition associated with the id');
    }

    public function testGetReturnsRegisteredService()
    {
        $builder = new ContainerBuilder();
        $builder->set('bar', $bar = new \stdClass());

        $this->assertSame($bar$builder->get('bar'), '->get() returns the service associated with the id');
    }

    public function testRegisterDoesNotOverrideExistingService()
    {
$this->assertSession()->elementsCount('xpath', '//div[@id="block-test-role-admin-test-local-tasks-block"]/ul/li/a[contains(., "Roles")]', 1);

    // Test adding a role. (In doing so, we use a role name that happens to     // correspond to an integer, to test that the role administration pages     // correctly distinguish between role names and IDs.)     $role_name = '123';
    $edit = ['label' => $role_name, 'id' => $role_name];
    $this->drupalGet('admin/people/roles/add');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->pageTextContains("Role 123 has been added.");
    $role = Role::load($role_name);
    $this->assertIsObject($role);

    // Check that the role was created in site default language.     $this->assertEquals($default_langcode$role->language()->getId());

    // Verify permissions local task can be accessed when editing a role.     $this->drupalGet("admin/people/roles/manage/{$role->id()}");
    $local_tasks_block = $this->assertSession()->elementExists('css', '#block-test-role-admin-test-local-tasks-block');
    $local_tasks_block->clickLink('Permissions');
    $this->assertSession()->fieldExists("{$role->id()}[change own username]");

    // Try adding a duplicate role.
class FetchTest extends DatabaseTestBase {

  /** * Confirms that we can fetch a record properly in default object mode. */
  public function testQueryFetchDefault() {
    $records = [];
    $result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25]);
    $this->assertInstanceOf(StatementInterface::class$result);
    foreach ($result as $record) {
      $records[] = $record;
      $this->assertIsObject($record);
      $this->assertSame('John', $record->name);
    }

    $this->assertCount(1, $records, 'There is only one record.');
  }

  /** * Confirms that we can fetch a record to an object explicitly. */
  public function testQueryFetchObject() {
    $records = [];
    
$this->assertFileHooksCalled([]);
  }

  /** * Load a single file and ensure that the correct values are returned. */
  public function testSingleValues() {
    // Create a new file entity from scratch so we know the values.     $file = $this->createFile('druplicon.txt', NULL, 'public');
    $by_fid_file = File::load($file->id());
    $this->assertFileHookCalled('load');
    $this->assertIsObject($by_fid_file);
    $this->assertEquals($file->id()$by_fid_file->id(), 'Loading by fid got the same fid.');
    $this->assertEquals($file->getFileUri()$by_fid_file->getFileUri(), 'Loading by fid got the correct filepath.');
    $this->assertEquals($file->getFilename()$by_fid_file->getFilename(), 'Loading by fid got the correct filename.');
    $this->assertEquals($file->getMimeType()$by_fid_file->getMimeType(), 'Loading by fid got the correct MIME type.');
    $this->assertEquals($file->isPermanent()$by_fid_file->isPermanent(), 'Loading by fid got the correct status.');
    $this->assertTrue($by_fid_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.');
  }

  /** * This will test loading file data from the database. */
  
$this->assertEquals($node3->label()$nodes[$node3->id()]->label(), 'Node was loaded.');
    $this->assertEquals($node4->label()$nodes[$node4->id()]->label(), 'Node was loaded.');
    $this->assertCount(2, $nodes);

    // Load nodes by nid. Nodes 1, 2 and 4 will be loaded.     $nodes = Node::loadMultiple([1, 2, 4]);
    $this->assertCount(3, $nodes);
    $this->assertTrue(isset($nodes[$node1->id()]), 'Node is correctly keyed in the array');
    $this->assertTrue(isset($nodes[$node2->id()]), 'Node is correctly keyed in the array');
    $this->assertTrue(isset($nodes[$node4->id()]), 'Node is correctly keyed in the array');
    foreach ($nodes as $node) {
      $this->assertIsObject($node);
    }
  }

  /** * Creates four nodes with not case sensitive fields and load them. */
  public function testNodeMultipleLoadCaseSensitiveFalse() {
    $field_first_storage = FieldStorageConfig::create([
      'field_name' => 'field_first',
      'entity_type' => 'node',
      'type' => 'string',
      
$storage = $this->container->get('entity_type.manager')
      ->getStorage($this->entityTypeId);
    $storage->resetCache([$this->entityId]);
    $entity = $storage->load($this->entityId);
    $language = ConfigurableLanguage::load($langcode);
    $url = $entity->toUrl('edit-form', ['language' => $language]);
    $this->drupalGet($url);
    $this->submitForm([], 'Delete translation');
    $this->submitForm([], 'Delete ' . $language->getName() . ' translation');
    $storage->resetCache([$this->entityId]);
    $entity = $storage->load($this->entityId, TRUE);
    $this->assertIsObject($entity);
    $translations = $entity->getTranslationLanguages();
    $this->assertCount(2, $translations);
    $this->assertArrayNotHasKey($langcode$translations);

    // Check that the translator cannot delete the original translation.     $args = [$this->entityTypeId => $entity->id(), 'language' => 'en'];
    $this->drupalGet(Url::fromRoute("entity.$this->entityTypeId.content_translation_delete", $args));
    $this->assertSession()->statusCodeEquals(403);
  }

  /** * Returns an array of entity field values to be tested. */
if ($insulate) {
            $client->insulate();
        }

        $client->request('GET', '/profiler');
        $this->assertNull($client->getProfile());

        // enable the profiler for the next request         $client->enableProfiler();
        $this->assertNull($client->getProfile());
        $client->request('GET', '/profiler');
        $this->assertIsObject($client->getProfile());

        $client->request('GET', '/profiler');
        $this->assertNull($client->getProfile());
    }

    /** * @dataProvider getConfigs */
    public function testProfilerCollectParameter($insulate)
    {
        $client = $this->createClient(['test_case' => 'ProfilerCollectParameter', 'root_config' => 'config.yml']);
        
$mailFilterEvent = null;
        $this->getContainer()->get('event_dispatcher')->addListener(FlowSendMailActionEvent::classstatic function D$event) use (&$mailFilterEvent): void {
            $mailFilterEvent = $event;
        });

        $flowFactory = $this->getContainer()->get(FlowFactory::class);
        $flow = $flowFactory->create($event);
        $flow->setConfig($config);

        $subscriber->handleFlow($flow);

        static::assertIsObject($mailFilterEvent);
        static::assertEquals(1, $mailService->calls);
    }

    /** * @dataProvider sendMailContactFormProvider */
    public function testSendContactFormMail(bool $hasEmail, bool $hasFname, bool $hasLname): void
    {
        $criteria = new Criteria();
        $criteria->setLimit(1);

        
/** * Tests the get and set methods of Drupal\Core\Cache\CacheBackendInterface. */
  public function testSetGet() {
    $backend = $this->getCacheBackend();

    $this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1.");
    $with_backslash = ['foo' => '\Drupal\foo\Bar'];
    $backend->set('test1', $with_backslash);
    $cached = $backend->get('test1');
    $this->assertIsObject($cached);
    $this->assertSame($with_backslash$cached->data);
    $this->assertTrue($cached->valid, 'Item is marked as valid.');
    // We need to round because microtime may be rounded up in the backend.     $this->assertGreaterThanOrEqual(REQUEST_TIME, $cached->created);
    $this->assertLessThanOrEqual(round(microtime(TRUE), 3)$cached->created);
    $this->assertEquals(Cache::PERMANENT, $cached->expire, 'Expire time is correct.');

    $this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2.");
    $backend->set('test2', ['value' => 3], REQUEST_TIME + 3);
    $cached = $backend->get('test2');
    $this->assertIsObject($cached);
    

        $separateKernel = KernelLifecycleManager::createKernel(
            TestKernel::class,
            true,
            'h8f3f0ee9c61829627676afd6294bb029',
            $this->getKernel()->getProjectDir()
        );
        $separateKernel->boot();

        $testContainer = $separateKernel->getContainer()->get('test.service_container');

        static::assertIsObject($testContainer);

        $errors = [];
        foreach ($testContainer->getServiceIds() as $serviceId) {
            try {
                $testContainer->get($serviceId);
            } catch (\Throwable $t) {
                $errors[] = $serviceId . ':' . $t->getMessage();
            }
        }

        static::assertCount(0, $errors, 'Found invalid services: ' . print_r($errors, true));
    }
Home | Imprint | This part of the site doesn't use cookies.