Skip to content

Commit 0a96d34

Browse files
Josh Salwayclaude
andcommitted
test: add test for File::types() chain preservation
Verifies that calling types() on an existing File instance preserves prior configuration (e.g. max()) instead of creating a new instance. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 27139dd commit 0a96d34

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tests/Validation/ValidationFileRuleTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ public function testMixOfMimetypesAndMimes()
135135
);
136136
}
137137

138+
public function testTypesPreservesChainConfiguration()
139+
{
140+
// When types() is called on an existing instance, it should preserve
141+
// prior configuration like max() instead of creating a new instance.
142+
$this->fails(
143+
File::image()->max(1)->types(['jpg', 'jpeg']),
144+
UploadedFile::fake()->image('photo.jpg', 800, 600),
145+
['validation.max.file'],
146+
);
147+
148+
// When types() is called statically, it should still work as a factory.
149+
$this->fails(
150+
File::types('text/plain'),
151+
UploadedFile::fake()->createWithContent('foo.png', file_get_contents(__DIR__.'/fixtures/image.png')),
152+
['validation.mimetypes'],
153+
);
154+
155+
// When types() is called before max(), the max constraint should also work.
156+
$this->fails(
157+
File::default()->types(['jpg', 'jpeg'])->max(1),
158+
UploadedFile::fake()->image('photo.jpg', 800, 600),
159+
['validation.max.file'],
160+
);
161+
}
162+
138163
public function testSingleExtension()
139164
{
140165
$this->fails(

0 commit comments

Comments
 (0)