|
7 | 7 | use Buildotter\Core\BuildableWithArgUnpacking; |
8 | 8 | use Buildotter\Core\BuildableWithArray; |
9 | 9 | use Buildotter\Core\Buildatable; |
| 10 | +use Buildotter\Core\Exception\UnknownPropertyException; |
10 | 11 | use PHPUnit\Framework\TestCase; |
11 | 12 | use function PHPUnit\Framework\assertEquals; |
12 | 13 |
|
@@ -39,6 +40,59 @@ public function test_it_is_buildatable_with_arg_unpacking(): void |
39 | 40 | $fooBuiltWithArgsUnpacking, |
40 | 41 | ); |
41 | 42 | } |
| 43 | + |
| 44 | + public function test_it_is_not_buildatable_with_bad_arg_unpacking(): void |
| 45 | + { |
| 46 | + $this->expectException(UnknownPropertyException::class); |
| 47 | + $this->expectExceptionMessage('The following properties do not exist in "Buildotter\Tests\Core\FooBuilderWithArgUnpacking": "0", "doesNotExist", "doesNotExistEither".'); |
| 48 | + |
| 49 | + FooBuilderWithArgUnpacking::new() |
| 50 | + ->with( |
| 51 | + random()->word(), |
| 52 | + doesNotExist: random()->word(), |
| 53 | + number: random()->randomNumber(), |
| 54 | + doesNotExistEither: random()->word(), |
| 55 | + ) |
| 56 | + ->build(); |
| 57 | + } |
| 58 | + |
| 59 | + public function test_it_is_not_buildatable_with_bad_arg_unpacking_2(): void |
| 60 | + { |
| 61 | + $this->expectException(UnknownPropertyException::class); |
| 62 | + $this->expectExceptionMessage('The following properties do not exist in "Buildotter\Tests\Core\FooBuilderWithArgUnpacking": "doesNotExist".'); |
| 63 | + |
| 64 | + FooBuilderWithArgUnpacking::new() |
| 65 | + ->named(random()->name()) |
| 66 | + ->with(doesNotExist: random()->word()) |
| 67 | + ->with(doesNotExistEither: random()->word()) |
| 68 | + ->build(); |
| 69 | + } |
| 70 | + |
| 71 | + public function test_it_is_not_buildatable_with_bad_arg_array(): void |
| 72 | + { |
| 73 | + $this->expectException(UnknownPropertyException::class); |
| 74 | + $this->expectExceptionMessage('The following properties do not exist in "Buildotter\Tests\Core\FooBuilderWithArray": "doesNotExist", "doesNotExistEither".'); |
| 75 | + |
| 76 | + FooBuilderWithArray::new() |
| 77 | + ->with([ |
| 78 | + 'doesNotExist' => random()->word(), |
| 79 | + 'number' => random()->randomNumber(), |
| 80 | + 'doesNotExistEither' => random()->word(), |
| 81 | + ]) |
| 82 | + ->build(); |
| 83 | + } |
| 84 | + |
| 85 | + public function test_it_is_not_buildatable_with_bad_arg_array_2(): void |
| 86 | + { |
| 87 | + $this->expectException(UnknownPropertyException::class); |
| 88 | + $this->expectExceptionMessage('The following properties do not exist in "Buildotter\Tests\Core\FooBuilderWithArray": "doesNotExist".'); |
| 89 | + |
| 90 | + FooBuilderWithArray::new() |
| 91 | + ->named(random()->name()) |
| 92 | + ->with(['doesNotExist' => random()->word()]) |
| 93 | + ->with(['doesNotExistEither' => random()->word()]) |
| 94 | + ->build(); |
| 95 | + } |
42 | 96 | } |
43 | 97 |
|
44 | 98 | final class Foo |
|
0 commit comments