faker->word(); $values = collect($this->faker->words()); $validator = Validator::make( [$attribute => $values->implode(',')], [$attribute => new DelimitedRule(['required', 'string'])] ); static::assertTrue($validator->passes()); } /** * The Delimited Rule shall fail if there exist duplicate values. * * @return void */ public function testFailsForDuplicateValues(): void { $attribute = $this->faker->word(); $duplicate = $this->faker->word(); $values = collect([$duplicate, $this->faker->word(), $duplicate]); $validator = Validator::make( [$attribute => $values->implode(',')], [$attribute => new DelimitedRule(['required', 'string'])] ); static::assertFalse($validator->passes()); } /** * The Delimited Rule shall fail if any value fails a rule. * * @return void */ public function testFailsForInvalidValue(): void { $attribute = $this->faker->word(); $values = collect([$this->faker->randomDigitNotNull(), $this->faker->word(), $this->faker->randomDigitNotNull()]); $validator = Validator::make( [$attribute => $values->implode(',')], [$attribute => new DelimitedRule(['required', 'integer'])] ); static::assertFalse($validator->passes()); } /** * The Delimited Rule shall validate empty values. * * @return void */ public function testValidatesEmptyValues(): void { $attribute = $this->faker->word(); $values = collect(array_merge($this->faker->words(), [''])); $validator = Validator::make( [$attribute => $values->implode(',')], [$attribute => new DelimitedRule(['required', 'string'])] ); static::assertFalse($validator->passes()); } }