assertIsBool example

$repo->create($entities, Context::createDefaultContext());

        $update = [
            ['id' => $a, 'custom' => ['bool' => false]],
            ['id' => $b, 'custom' => ['bool' => true]],
        ];
        $events = $repo->update($update, Context::createDefaultContext());
        $event = $events->getEventByEntityName(CustomFieldTestDefinition::ENTITY_NAME);
        $payloads = $event->getPayloads();
        static::assertCount(2, $payloads);

        static::assertIsBool($payloads[0]['custom']['bool']);
        static::assertIsBool($payloads[1]['custom']['bool']);
    }

    public function testNestedJsonStringValue(): void
    {
        $this->addCustomFields(['json' => CustomFieldTypes::JSON]);
        $date = new \DateTimeImmutable();
        $date = (new \DateTimeImmutable('@' . $date->getTimestamp()))->setTimezone($date->getTimezone());

        $id = Uuid::randomHex();
        $entity = [
            
'en' => 'english',
                'de' => 'german',
            ]
        );
        $uuid = $this->ids->get('product-1');
        $documents = $definition->fetch([$uuid], Context::createDefaultContext());

        static::assertArrayHasKey($uuid$documents);
        static::assertArrayHasKey('customFields', $documents[$uuid]);
        static::assertArrayHasKey(Defaults::LANGUAGE_SYSTEM, $documents[$uuid]['customFields']);
        static::assertArrayHasKey('bool', $documents[$uuid]['customFields'][Defaults::LANGUAGE_SYSTEM]);
        static::assertIsBool($documents[$uuid]['customFields'][Defaults::LANGUAGE_SYSTEM]['bool']);
        static::assertArrayHasKey('int', $documents[$uuid]['customFields'][Defaults::LANGUAGE_SYSTEM]);
        static::assertIsFloat($documents[$uuid]['customFields'][Defaults::LANGUAGE_SYSTEM]['int']);
        static::assertArrayNotHasKey('unknown', $documents[$uuid]['customFields'][Defaults::LANGUAGE_SYSTEM]);
    }

    public function getConnection(): Connection
    {
        $connection = $this->createMock(Connection::class);

        $connection
            ->method('fetchAllAssociativeIndexed')
            
'bool' => CustomFieldTypes::BOOL, 'int' => CustomFieldTypes::INT],
            new EventDispatcher(),
            $this->createMock(AbstractProductSearchQueryBuilder::class),
            $this->createMock(EsProductDefinition::class)
        );

        $documents = $definition->fetch([$productId], Context::createDefaultContext());

        static::assertArrayHasKey($productId$documents);
        static::assertArrayHasKey('customFields', $documents[$productId]);
        static::assertArrayHasKey('bool', $documents[$productId]['customFields']);
        static::assertIsBool($documents[$productId]['customFields']['bool']);
        static::assertArrayHasKey('int', $documents[$productId]['customFields']);
        static::assertIsFloat($documents[$productId]['customFields']['int']);
        static::assertArrayNotHasKey('unknown', $documents[$productId]['customFields']);
    }

    public function getConnection(string $uuid): Connection
    {
        $connection = $this->createMock(Connection::class);
        $connection
            ->method('fetchAllAssociative')
            ->willReturnOnConsecutiveCalls(
                [
/** @var array<mixed> $customFields */
        $customFields = $country->getCustomFields();

        static::assertIsInt($customFields['a']);
        static::assertIsInt($customFields['b']);
        static::assertSame(1234, $customFields['a']);
        static::assertSame(1, $customFields['b']);

        static::assertIsFloat($customFields['c']);
        static::assertSame(1.56, $customFields['c']);

        static::assertIsBool($customFields['d']);
        static::assertTrue($customFields['d']);

        static::assertIsArray($customFields['e']);
        static::assertSame(['a']$customFields['e']);

        static::assertIsArray($customFields['f']);
        static::assertEmpty($customFields['f']);
        static::assertSame($customFields['g'], 'test');
    }

    /** * @return array<array<class-string>> */
$controller = new UsageDataController($detector);

        static::assertTrue($this->getJsonResponseResult($controller->needsApprovalRequest()));
    }

    private function getJsonResponseResult(JsonResponse $response): bool
    {
        $json = $response->getContent();
        static::assertIsString($json);

        $result = json_decode($json);
        static::assertIsBool($result);

        return $result;
    }
}
Home | Imprint | This part of the site doesn't use cookies.