daikon-cqrs /
interop
| 1 | <?php declare(strict_types=1); |
||||
| 2 | /** |
||||
| 3 | * This file is part of the daikon-cqrs/interop project. |
||||
| 4 | * |
||||
| 5 | * For the full copyright and license information, please view the LICENSE |
||||
| 6 | * file that was distributed with this source code. |
||||
| 7 | */ |
||||
| 8 | |||||
| 9 | namespace Daikon\Tests\Interop; |
||||
| 10 | |||||
| 11 | use Daikon\Interop\InvalidArgumentException; |
||||
| 12 | use Daikon\Tests\Interop\Fixture\AnnotatedValue; |
||||
| 13 | use Daikon\Tests\Interop\Fixture\MockValue; |
||||
| 14 | use PHPUnit\Framework\TestCase; |
||||
| 15 | use TypeError; |
||||
| 16 | |||||
| 17 | class FromToNativeTest extends TestCase |
||||
| 18 | { |
||||
| 19 | 1 | public function testMakeEmpty(): void |
|||
| 20 | { |
||||
| 21 | 1 | $mock = MockValue::makeEmpty(); |
|||
| 22 | 1 | $this->assertNull($mock->getValue()); |
|||
| 23 | |||||
| 24 | 1 | $mock = new AnnotatedValue; |
|||
| 25 | 1 | $this->assertInstanceOf(MockValue::class, $mock->getMockValue()); |
|||
| 26 | 1 | $this->assertNull($mock->getMockValue()->getValue()); |
|||
| 27 | 1 | } |
|||
| 28 | |||||
| 29 | 1 | public function testFromNativeWithNull(): void |
|||
| 30 | { |
||||
| 31 | 1 | $this->expectException(InvalidArgumentException::class); |
|||
| 32 | 1 | $this->expectExceptionMessage('This trait only works with array state.'); |
|||
| 33 | 1 | MockValue::fromNative(null); |
|||
| 34 | } |
||||
| 35 | |||||
| 36 | 1 | public function testInferredFromNativeWithNull(): void |
|||
| 37 | { |
||||
| 38 | 1 | $this->expectException(InvalidArgumentException::class); |
|||
| 39 | 1 | $this->expectExceptionMessage('This trait only works with array state.'); |
|||
| 40 | 1 | AnnotatedValue::fromNative(null); |
|||
| 41 | } |
||||
| 42 | |||||
| 43 | 1 | public function testFromNativeWithScalar(): void |
|||
| 44 | { |
||||
| 45 | 1 | $this->expectException(InvalidArgumentException::class); |
|||
| 46 | 1 | $this->expectExceptionMessage('This trait only works with array state.'); |
|||
| 47 | 1 | MockValue::fromNative('test'); |
|||
| 48 | } |
||||
| 49 | |||||
| 50 | 1 | public function testInferredFromNativeWithScalar(): void |
|||
| 51 | { |
||||
| 52 | 1 | $this->expectException(InvalidArgumentException::class); |
|||
| 53 | 1 | $this->expectExceptionMessage('This trait only works with array state.'); |
|||
| 54 | 1 | AnnotatedValue::fromNative('test'); |
|||
| 55 | } |
||||
| 56 | |||||
| 57 | 1 | public function testFromNativeWithUnknownKey(): void |
|||
| 58 | { |
||||
| 59 | 1 | $mock = MockValue::fromNative(['what' => 'no']); |
|||
| 60 | 1 | $this->assertNull($mock->getValue()); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 61 | 1 | } |
|||
| 62 | |||||
| 63 | 1 | public function testInferredFromNativeWithUnknownKey(): void |
|||
| 64 | { |
||||
| 65 | 1 | $mock = AnnotatedValue::fromNative(['what' => 'no']); |
|||
| 66 | 1 | $this->assertInstanceOf(MockValue::class, $mock->getMockValue()); |
|||
|
0 ignored issues
–
show
It seems like
getMockValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 67 | 1 | $this->assertNull($mock->getMockValue()->getValue()); |
|||
| 68 | 1 | } |
|||
| 69 | |||||
| 70 | 1 | public function testFromNativeWithInvalidType(): void |
|||
| 71 | { |
||||
| 72 | 1 | $this->expectException(TypeError::class); |
|||
| 73 | 1 | MockValue::fromNative(['value' => 123]); |
|||
| 74 | } |
||||
| 75 | |||||
| 76 | 1 | public function testInferredFromNativeWithInvalidType(): void |
|||
| 77 | { |
||||
| 78 | 1 | $this->expectException(InvalidArgumentException::class); |
|||
| 79 | 1 | $this->expectExceptionMessage('This trait only works with array state.'); |
|||
| 80 | 1 | AnnotatedValue::fromNative(['mockValue' => 123]); |
|||
| 81 | } |
||||
| 82 | |||||
| 83 | 1 | public function testInferredFromNativeWithNullValueState(): void |
|||
| 84 | { |
||||
| 85 | 1 | $this->expectException(InvalidArgumentException::class); |
|||
| 86 | 1 | $this->expectExceptionMessage('This trait only works with array state.'); |
|||
| 87 | 1 | AnnotatedValue::fromNative(['mockValue' => null]); |
|||
| 88 | } |
||||
| 89 | |||||
| 90 | 1 | public function testFromNative(): void |
|||
| 91 | { |
||||
| 92 | 1 | $mock = MockValue::fromNative([]); |
|||
| 93 | 1 | $this->assertNull($mock->getValue()); |
|||
| 94 | |||||
| 95 | 1 | $mock = MockValue::fromNative(['value' => null]); |
|||
| 96 | 1 | $this->assertNull($mock->getValue()); |
|||
| 97 | |||||
| 98 | 1 | $mock = MockValue::fromNative(['value' => 'yo']); |
|||
| 99 | 1 | $this->assertEquals('yo', $mock->getValue()); |
|||
| 100 | 1 | } |
|||
| 101 | |||||
| 102 | 1 | public function testInferredFromNative(): void |
|||
| 103 | { |
||||
| 104 | 1 | $mock = AnnotatedValue::fromNative(['mockValue' => []]); |
|||
| 105 | 1 | $this->assertInstanceOf(MockValue::class, $mock->getMockValue()); |
|||
| 106 | 1 | $this->assertNull($mock->getMockValue()->getValue()); |
|||
| 107 | |||||
| 108 | 1 | $mock = AnnotatedValue::fromNative(['mockValue' => ['valuex' => '']]); |
|||
| 109 | 1 | $this->assertNull($mock->getMockValue()->getValue()); |
|||
| 110 | |||||
| 111 | 1 | $mock = AnnotatedValue::fromNative(['mockValue' => ['value' => '']]); |
|||
| 112 | 1 | $this->assertEmpty($mock->getMockValue()->getValue()); |
|||
| 113 | |||||
| 114 | 1 | $mock = AnnotatedValue::fromNative(['mockValue' => ['value' => '123']]); |
|||
| 115 | 1 | $this->assertEquals('123', $mock->getMockValue()->getValue()); |
|||
| 116 | |||||
| 117 | 1 | $mock = AnnotatedValue::fromNative([ |
|||
| 118 | 1 | 'otherMockValue' => ['custom' => 'ABC'], |
|||
| 119 | 'defaultFactoryMockValue' => ['value' => 'XYZ'] |
||||
| 120 | ]); |
||||
| 121 | 1 | $this->assertEquals('ABC', $mock->getOtherMockValue()->getValue()); |
|||
|
0 ignored issues
–
show
It seems like
getOtherMockValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 122 | 1 | $this->assertEquals('XYZ', $mock->getDefaultFactoryMockValue()->getValue()); |
|||
|
0 ignored issues
–
show
It seems like
getDefaultFactoryMockValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 123 | |||||
| 124 | 1 | $this->expectException(TypeError::class); |
|||
| 125 | 1 | AnnotatedValue::fromNative(['otherMockValue' => 'ABC']); |
|||
| 126 | } |
||||
| 127 | } |
||||
| 128 |