Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[11.x] Add tests for handling non-baked enum and empty string requests #51289

Merged
merged 2 commits into from
May 5, 2024

Conversation

hrant1020
Copy link
Contributor

@hrant1020 hrant1020 commented May 4, 2024

        /** Added some tests */
        $request = Request::create('/', 'GET', [
            'empty_value_request' => '',
        ]);

        // Empty string case         
        $this->assertNull($request->enum('empty_value_request', TestEnumBacked::class)); //this should be null
        
        // Non baked enum case         
        $this->assertNull($request->enum('valid_enum_value', TestEnum::class)); //this should be null (no error thrown)       

So now PR test look like this

    public function testEnumMethod()
    {
        $request = Request::create('/', 'GET', [
            'valid_enum_value' => 'test',
            'invalid_enum_value' => 'invalid',
            'empty_value_request' => '',
        ]);

        $this->assertNull($request->enum('doesnt_exists', TestEnumBacked::class));

        $this->assertEquals(TestEnumBacked::test, $request->enum('valid_enum_value', TestEnumBacked::class));

        $this->assertNull($request->enum('invalid_enum_value', TestEnumBacked::class));
        $this->assertNull($request->enum('empty_value_request', TestEnumBacked::class));
        $this->assertNull($request->enum('valid_enum_value', TestEnum::class));
    }

@hrant1020 hrant1020 changed the title Add tests for handling non-baked enum and empty string requests [11.x] Add tests for handling non-baked enum and empty string requests May 4, 2024
@taylorotwell taylorotwell merged commit 7269425 into laravel:11.x May 5, 2024
28 checks passed
func0der pushed a commit to func0der/framework that referenced this pull request May 6, 2024
laravel#51289)

* Add tests for handling non-baked enum and empty string requests

* use existing request key

---------

Co-authored-by: Hrant Aghanian <haghanian@ronasit.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants