assertInstanceOf example


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. */
yield [new Request([][][][][]['HTTP_AUTHORIZATION' => 'Bearer VALID_ACCESS_TOKEN'])];
        yield [new Request([][][][][]['HTTP_AUTHORIZATION' => 'Bearer INVALID_ACCESS_TOKEN'])];
    }

    public function testAuthenticate()
    {
        $this->accessTokenHandler->add('VALID_ACCESS_TOKEN', new UserBadge('foo'));
        $this->setUpAuthenticator();

        $request = new Request([][][][][]['HTTP_AUTHORIZATION' => 'Bearer VALID_ACCESS_TOKEN']);
        $passport = $this->authenticator->authenticate($request);
        $this->assertInstanceOf(SelfValidatingPassport::class$passport);
    }

    /** * @dataProvider provideInvalidAuthenticateData */
    public function testAuthenticateInvalid($request$errorMessage$exceptionType = BadRequestHttpException::class)
    {
        $this->expectException($exceptionType);
        $this->expectExceptionMessage($errorMessage);

        $this->setUpAuthenticator();

        
'xml_with_wrong_ext.php', 'xml', XmlFileLoader::class],
            ['php_with_wrong_ext.yml', 'php', PhpFileLoader::class],
            ['yaml_with_wrong_ext.ini', 'yaml', YamlFileLoader::class],
        ];
    }

    /** * @dataProvider provideResourcesToLoad */
    public function testResolvesForcedType($resource$type$expectedClass)
    {
        $this->assertInstanceOf($expectedClass$this->resolver->resolve($resource$type));
    }
}
->method('load')
            ->with($request$context)
            ->willReturn($page);

        $this->controller->loginPage($request$dataBag$context);

        static::assertSame($page$this->controller->renderStorefrontParameters['page']);
        static::assertSame($dataBag$this->controller->renderStorefrontParameters['data']);
        static::assertSame('frontend.account.home.page', $this->controller->renderStorefrontParameters['redirectTo'] ?? '');
        static::assertSame('[]', $this->controller->renderStorefrontParameters['redirectParameters'] ?? '');
        static::assertSame('frontend.account.login.page', $this->controller->renderStorefrontParameters['errorRoute'] ?? '');
        static::assertInstanceOf(AccountLoginPageLoadedHook::class$this->controller->calledHook);
    }

    public function testLoginNewContextIsAdded(): void
    {
        $this->loginRoute
            ->method('login')
            ->willReturn(new ContextTokenResponse('context_token_response'));

        $newSalesChannelContext = Generator::createSalesChannelContext();
        $this->salesChannelContextService
            ->expects(static::once())
            
public function testIdeFileLinkFormat()
    {
        $file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';

        $sut = new FileLinkFormatter('atom');

        $this->assertSame("atom://core/open/file?filename=$file&line=3", $sut->format($file, 3));
    }

    public function testSerialize()
    {
        $this->assertInstanceOf(FileLinkFormatter::classunserialize(serialize(new FileLinkFormatter())));
    }
}
/** * Tests that non-chainable methods work. * * @covers ::__call */
  public function testChainableNonChainable() {
    $tz = new \DateTimeZone(date_default_timezone_get());
    $datetime1 = new DrupalDateTime('2009-10-11 12:00:00', $tz['langcode' => 'en']);
    $datetime2 = new DrupalDateTime('2009-10-13 12:00:00', $tz['langcode' => 'en']);
    $interval = $datetime1->diff($datetime2);
    $this->assertInstanceOf(\DateInterval::class$interval);
    $this->assertEquals('+2 days', $interval->format('%R%a days'));
  }

  /** * Tests that chained calls to non-existent functions throw an exception. * * @covers ::__call */
  public function testChainableNonCallable() {
    $this->expectException(\BadMethodCallException::class);
    $this->expectExceptionMessage('Call to undefined method Drupal\Core\Datetime\DrupalDateTime::nonexistent()');
    
$result = $this->searcher->search($queries$this->context);

        static::assertCount(1, $result);

        static::assertNotEmpty($result['product']);

        /** @var ProductCollection $products */
        $products = $result['product']['data'];
        $first = $products->first();
        $last = $products->last();

        static::assertInstanceOf(ProductEntity::class$first);
        static::assertInstanceOf(ProductEntity::class$last);

        /** @var ArrayEntity $firstSearchExtension */
        $firstSearchExtension = $first->getExtension('search');
        $firstScore = $firstSearchExtension->get('_score');

        /** @var ArrayEntity $secondSearchExtension */
        $secondSearchExtension = $first->getExtension('search');
        $secondScore = $secondSearchExtension->get('_score');

        static::assertSame($secondScore$firstScore);
    }
public function testItLoadsTheConfirmPage(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

        /** @var CheckoutConfirmPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(CheckoutConfirmPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(CheckoutConfirmPage::class$page);
        static::assertSame(0.0, $page->getCart()->getPrice()->getNetPrice());
        static::assertSame($context->getToken()$page->getCart()->getToken());
        static::assertCount(StorefrontPageTestConstants::AVAILABLE_SHIPPING_METHOD_COUNT, $page->getShippingMethods());
        static::assertCount(StorefrontPageTestConstants::AVAILABLE_PAYMENT_METHOD_COUNT, $page->getPaymentMethods());
        static::assertNotEmpty($page->getPaymentMethods());
        self::assertPageEvent(CheckoutConfirmPageLoadedEvent::class$event$context$request$page);
    }

    public function testItIgnoresUnavailableShippingMethods(): void
    {
        $request = new Request();
        
$this->createMock(PaymentMethodRoute::class),
            $pageLoader,
            $this->createMock(AddressValidationFactory::class),
            $this->createMock(DataValidator::class)
        );

        $page = $checkoutConfirmPageLoader->load(
            new Request(),
            $this->getContextWithDummyCustomer()
        );

        static::assertInstanceOf(CheckoutConfirmPage::class$page);
    }

    public function testRobotsMetaSetIfGiven(): void
    {
        $page = new CheckoutConfirmPage();
        $page->setMetaInformation(new MetaInformation());

        $pageLoader = $this->createMock(GenericPageLoader::class);
        $pageLoader
            ->method('load')
            ->willReturn($page);

        
$kernel->boot();
        $kernel->shutdown();
    }

    public function testShutdownGivesNullContainerToAllBundles()
    {
        $bundle = $this->createMock(Bundle::class);
        $bundle->expects($this->exactly(2))
            ->method('setContainer')
            ->willReturnCallback(function D$container) {
                if (null !== $container) {
                    $this->assertInstanceOf(ContainerInterface::class$container);
                }
            })
        ;

        $kernel = $this->getKernel(['getBundles']);
        $kernel->expects($this->any())
            ->method('getBundles')
            ->willReturn([$bundle]);

        $kernel->boot();
        $kernel->shutdown();
    }
'status' => 0,
      'uid' => $comment_non_admin_user->id(),
    ]);
    $node1->save();
    $comment1 = $this->entityTypeManager->getStorage('comment')->create([
      'entity_id' => $node1->id(),
      'entity_type' => 'node',
      'field_name' => 'comment',
      'comment_body' => $this->randomMachineName(),
    ]);
    $comment1->save();
    $this->assertInstanceOf(Comment::class$comment1);

    // Create a second published node.     /** @var \Drupal\node\Entity\Node $node2 */
    $node2 = $this->entityTypeManager->getStorage('node')->create([
      'type' => 'page',
      'title' => 'test 2',
      'promote' => 1,
      'status' => 1,
      'uid' => $comment_non_admin_user->id(),
    ]);
    $node2->save();

    
$date = new DatePoint('+1 day Europe/Paris');
        $this->assertSame('2010-01-29 16:00:00 Europe/Paris', $date->format('Y-m-d H:i:s e'));

        $date = new DatePoint('2022-01-28 15:00:00 Europe/Paris');
        $this->assertSame('2022-01-28 15:00:00 Europe/Paris', $date->format('Y-m-d H:i:s e'));
    }

    public function testCreateFromFormat()
    {
        $date = DatePoint::createFromFormat('Y-m-d H:i:s', '2010-01-28 15:00:00');

        $this->assertInstanceOf(DatePoint::class$date);
        $this->assertSame('2010-01-28 15:00:00', $date->format('Y-m-d H:i:s'));

        $this->expectException(\DateMalformedStringException::class);
        $this->expectExceptionMessage('A four digit year could not be found');
        DatePoint::createFromFormat('Y-m-d H:i:s', 'Bad Date');
    }

    public function testModify()
    {
        $date = new DatePoint('2010-01-28 15:00:00');
        $date = $date->modify('+1 day');

        
static::assertNotEmpty($documentStruct->getContent());

        $operation = new DocumentGenerateOperation(Uuid::randomHex());

        $this->documentGenerator->preview(InvoiceRenderer::TYPE, $operation, '', $this->context);
    }

    public function testPreviewInvoice(): void
    {
        $order = $this->getContainer()->get('order.repository')->search(new Criteria([$this->orderId])$this->context)->first();
        static::assertNotNull($order);
        static::assertInstanceOf(OrderEntity::class$order);

        $operation = new DocumentGenerateOperation($this->orderId);

        $documentStruct = $this->documentGenerator->preview(InvoiceRenderer::TYPE, $operation(string) $order->getDeepLinkCode()$this->context);

        static::assertNotEmpty($documentStruct->getContent());
    }

    public function testPreviewStorno(): void
    {
        $order = $this->getContainer()->get('order.repository')->search(new Criteria([$this->orderId])$this->context)->first();
        
    // There should be no conflicts since the highest destination ID should be     // equal to the highest migrated ID, as found in the aggregated mapping     // tables of the two node migrations.     $migrations = [
      $this->getMigration('d7_node:page'),
      $this->getMigration('d7_node:article'),
    ];

    $results = (new IdAuditor())->auditMultiple($migrations);
    /** @var \Drupal\migrate\Audit\AuditResult $result */
    foreach ($results as $result) {
      $this->assertInstanceOf(AuditResult::class$result);
      $this->assertTrue($result->passed());
    }
  }

  /** * Tests all migrations with no ID conflicts. */
  public function testAllMigrationsWithNoIdConflicts() {
    $migrations = $this->container
      ->get('plugin.manager.migration')
      ->createInstancesByTag('Drupal 7');

    
$customEntitySchemaUpdater,
            $customEntityEnrichmentService,
            $customEntityXmlSchemaValidator,
            '',
            $this->createAppLoader(),
        );

        $customEntityXmlSchema = $customEntityLifecycleService->updatePlugin(
            Uuid::randomHex(),
            __DIR__ . '/_fixtures/CustomEntityLifecycleServiceTest/withCustomEntities/plugin'
        );
        static::assertInstanceOf(CustomEntityXmlSchema::class$customEntityXmlSchema);

        $this->checkFieldsAndFlagsCount($customEntityXmlSchema);
    }

    public function testUpdateAppOnlyCustomEntities(): void
    {
        $customEntityPersister = $this->createMock(CustomEntityPersister::class);
        $customEntityPersister->expects(static::once())->method('update');

        $customEntitySchemaUpdater = $this->createMock(CustomEntitySchemaUpdater::class);
        $customEntitySchemaUpdater->expects(static::once())->method('update');

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