|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * Copyright MacFJA |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 9 | + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the |
| 10 | + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | + * permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the |
| 14 | + * Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
| 17 | + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 18 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + */ |
| 21 | + |
| 22 | +namespace MacFJA\RediSearch\tests\Redis\Command\Option; |
| 23 | + |
| 24 | +use BadMethodCallException; |
| 25 | +use InvalidArgumentException; |
| 26 | +use MacFJA\RediSearch\Redis\Command\Option\NamelessOption; |
| 27 | +use MacFJA\RediSearch\tests\fixtures\Redis\Command\Option\FakeWithPublicGroupedSetter; |
| 28 | +use MacFJA\RediSearch\tests\fixtures\Redis\Command\Option\FakeWithPublicGroupedSetterInvalidSelf; |
| 29 | +use PHPUnit\Framework\TestCase; |
| 30 | + |
| 31 | +/** |
| 32 | + * @covers \MacFJA\RediSearch\Redis\Command\Option\WithPublicGroupedSetterTrait |
| 33 | + * |
| 34 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\GroupedOption |
| 35 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption |
| 36 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\NamelessOption |
| 37 | + * |
| 38 | + * @internal |
| 39 | + */ |
| 40 | +class WithPublicGroupedSetterTraitTest extends TestCase |
| 41 | +{ |
| 42 | + public function testInvalidSelf(): void |
| 43 | + { |
| 44 | + $this->expectException(BadMethodCallException::class); |
| 45 | + $this->expectExceptionMessage('This method is not callable in '.FakeWithPublicGroupedSetterInvalidSelf::class); |
| 46 | + $class = new FakeWithPublicGroupedSetterInvalidSelf(); |
| 47 | + $class->setName('John'); |
| 48 | + } |
| 49 | + |
| 50 | + public function testInvalidSetterName(): void |
| 51 | + { |
| 52 | + $this->expectException(BadMethodCallException::class); |
| 53 | + $this->expectExceptionMessage('Call undefined method setAge in '.FakeWithPublicGroupedSetter::class); |
| 54 | + $class = new FakeWithPublicGroupedSetter([], []); |
| 55 | + $class->setAge(50); |
| 56 | + } |
| 57 | + |
| 58 | + public function testInvalidSetterArgCount(): void |
| 59 | + { |
| 60 | + $this->expectException(InvalidArgumentException::class); |
| 61 | + $this->expectExceptionMessage('The method '.FakeWithPublicGroupedSetter::class.'::setName need exactly one argument'); |
| 62 | + $class = new FakeWithPublicGroupedSetter([], []); |
| 63 | + $class->setName('John', 'Doe'); |
| 64 | + } |
| 65 | + |
| 66 | + public function testUndefinedMethod(): void |
| 67 | + { |
| 68 | + $this->expectException(BadMethodCallException::class); |
| 69 | + $this->expectExceptionMessage('Call undefined method foo in '.FakeWithPublicGroupedSetter::class); |
| 70 | + $class = new FakeWithPublicGroupedSetter([], []); |
| 71 | + $class->foo(); |
| 72 | + } |
| 73 | + |
| 74 | + public function testSetter(): void |
| 75 | + { |
| 76 | + $class = new FakeWithPublicGroupedSetter(['name' => new NamelessOption()], []); |
| 77 | + $class->setName('John'); |
| 78 | + static::assertSame('John', $class->getDataOfOption('name')); |
| 79 | + } |
| 80 | +} |
0 commit comments