Coder Social home page Coder Social logo

Assert::upper() correct usage about assert HOT 4 OPEN

bpastukh avatar bpastukh commented on August 26, 2024
Assert::upper() correct usage

from assert.

Comments (4)

zerkms avatar zerkms commented on August 26, 2024

how the string can be upper if we assert it is lowercase?

Assertion is for !lowercase-string, exclamation mark ! means negation.

The error is:

How exactly is typed $string? Show /** @psalm-trace $string */;

from assert.

bpastukh avatar bpastukh commented on August 26, 2024

It is not typed, it's $data is a dynamic array

        #[OA\Property(property: 'data', description: 'An array of data dependent on event type', type: 'object')]
        #[Assert\NotBlank]
        #[Assert\Type('array')]
        public array $data = [],

from assert.

bpastukh avatar bpastukh commented on August 26, 2024

I'm able to reproduce it this way:

        $array = ['someKey' => random_bytes(10)];
        $string = $array['someKey'];
        Assert::upper($string);

So $array is not typed (it is defined on the first line of the example) and i'm still getting

ERROR: TypeDoesNotContainType - src/Event/AbstractEvent.php:25:17 - Type non-empty-string for $string is always !lowercase-string (see https://psalm.dev/056)
        Assert::upper($string);

As a workaround for now i've used Assert::true

        Assert::true(
            ctype_upper($string),
            sprintf('Expected a value to contain uppercase characters only. Got: "%s"', $string),
        );

from assert.

zerkms avatar zerkms commented on August 26, 2024

Indeed, I could reproduce it on the psalm.dev:

https://psalm.dev/r/7f0799fc21

from assert.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.